Lazy loading of attributes
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / directory / ldap / DefaultLdapEntry.java
index 4212c5f5576fa1cfec836695ac7f03bf9dcd5140..8db662393e5ee1fb702664465a2692616ef17e68 100644 (file)
@@ -35,8 +35,8 @@ public class DefaultLdapEntry implements LdapEntry {
        private Attributes publishedAttributes;
 
        // Temporarily expose the fields
-       protected final AttributeDictionary properties;
-       protected final AttributeDictionary credentials;
+       protected AttributeDictionary properties;
+       protected AttributeDictionary credentials;
 
        protected DefaultLdapEntry(AbstractLdapDirectory directory, LdapName dn, Attributes attributes) {
                Objects.requireNonNull(directory);
@@ -44,8 +44,8 @@ public class DefaultLdapEntry implements LdapEntry {
                this.directory = directory;
                this.dn = dn;
                this.publishedAttributes = attributes;
-               properties = new AttributeDictionary(false);
-               credentials = new AttributeDictionary(true);
+//             properties = new AttributeDictionary(false);
+//             credentials = new AttributeDictionary(true);
        }
 
        @Override
@@ -54,6 +54,9 @@ public class DefaultLdapEntry implements LdapEntry {
        }
 
        public synchronized Attributes getAttributes() {
+               // lazy loading
+               if (publishedAttributes == null)
+                       publishedAttributes = getDirectory().getDirectoryDao().doGetAttributes(dn);
                return isEditing() ? getModifiedAttributes() : publishedAttributes;
        }
 
@@ -103,15 +106,23 @@ public class DefaultLdapEntry implements LdapEntry {
        public synchronized void publishAttributes(Attributes modifiedAttributes) {
                publishedAttributes = modifiedAttributes;
        }
-       
+
        /*
         * PROPERTIES
         */
        @Override
        public Dictionary<String, Object> getProperties() {
+               if (properties == null)
+                       properties = new AttributeDictionary(false);
                return properties;
        }
 
+       public Dictionary<String, Object> getCredentials() {
+               if (credentials == null)
+                       credentials = new AttributeDictionary(false);
+               return credentials;
+       }
+
        /*
         * CREDENTIALS
         */