directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1221802 - in /directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry: DefaultEntry.java Entry.java ImmutableEntry.java
Date Wed, 21 Dec 2011 16:57:46 GMT
Author: elecharny
Date: Wed Dec 21 16:57:45 2011
New Revision: 1221802

URL: http://svn.apache.org/viewvc?rev=1221802&view=rev
Log:
Added the apply( SchemaManager ) to the Entry interface, and impelmented the method in the
inherited classes

Modified:
    directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
    directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
    directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java

Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java?rev=1221802&r1=1221801&r2=1221802&view=diff
==============================================================================
--- directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
(original)
+++ directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
Wed Dec 21 16:57:45 2011
@@ -37,7 +37,9 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.ldif.LdapLdifException;
 import org.apache.directory.shared.ldap.model.ldif.LdifAttributesReader;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.model.name.Ava;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Base64;
@@ -586,6 +588,65 @@ public final class DefaultEntry implemen
 
         return schemaManager.lookupAttributeTypeRegistry( upId );
     }
+    
+    
+    /**
+     * Adds missing Rdn's attributes and values to the entry.
+     *
+     * @param dn the Dn
+     * @param entry the entry
+     */
+    private void addRdnAttributesToEntry( SchemaManager schemaManager ) throws LdapException
+    {
+        if ( Dn.isNullOrEmpty( dn ) )
+        {
+            return;
+        }
+
+        Rdn rdn = dn.getRdn();
+
+        // Loop on all the AVAs
+        for ( Ava ava : rdn )
+        {
+            Value<?> value = ava.getNormValue();
+            Value<?> upValue = ava.getUpValue();
+            String upId = ava.getUpType();
+
+            // Check that the entry contains this Ava
+            if ( !contains( upId, value ) )
+            {
+                String message = "The Rdn '" + upId + "=" + upValue + "' is not present in
the entry";
+                LOG.warn( message );
+
+                // We don't have this attribute : add it.
+                // Two cases :
+                // 1) The attribute does not exist
+                if ( !containsAttribute( upId ) )
+                {
+                    AttributeType attributeType = schemaManager.getAttributeType( upId );
+
+                    add( upId, attributeType, value );
+                }
+                // 2) The attribute exists
+                else
+                {
+                    AttributeType at = schemaManager.lookupAttributeTypeRegistry( upId );
+
+                    // 2.1 if the attribute is single valued, replace the value
+                    if ( at.isSingleValued() )
+                    {
+                        removeAttributes( upId );
+                        add( upId, value );
+                    }
+                    // 2.2 the attribute is multi-valued : add the missing value
+                    else
+                    {
+                        add( upId, value );
+                    }
+                }
+            }
+        }
+    }
 
 
     //-------------------------------------------------------------------------
@@ -975,6 +1036,30 @@ public final class DefaultEntry implemen
 
 
     /**
+     * {@inheritDoc}
+     */
+    public void apply( SchemaManager schemaManager ) throws LdapException
+    {
+        if ( dn.getSchemaManager() == null )
+        {
+            dn.apply( schemaManager );
+        }
+
+        for ( Attribute attribute : attributes.values() )
+        {
+            if ( attribute.getAttributeType() == null )
+            {
+                AttributeType attributeType = schemaManager.getAttributeType( attribute.getId()
);
+                attribute.apply( attributeType );
+            }
+        }
+
+        addRdnAttributesToEntry( schemaManager );
+        this.schemaManager = schemaManager;
+    }
+
+
+    /**
      * Clone an entry. All the element are duplicated, so a modification on
      * the original object won't affect the cloned object, as a modification
      * on the cloned object has no impact on the original object

Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java?rev=1221802&r1=1221801&r2=1221802&view=diff
==============================================================================
--- directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
(original)
+++ directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
Wed Dec 21 16:57:45 2011
@@ -29,6 +29,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 
 
 /**
@@ -48,6 +49,13 @@ import org.apache.directory.shared.ldap.
 public interface Entry extends Cloneable, Iterable<Attribute>, Externalizable
 {
     /**
+     * Apply the SchemaManager to this entry
+     * @param schemaManager The SchemaManager
+     * @throws LdapException if there is some problem in the DN or in the Attributes
+     */
+    void apply( SchemaManager schemaManager ) throws LdapException;
+
+    /**
      * Remove all the attributes for this entry. The Dn is not reset
      */
     void clear();

Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java?rev=1221802&r1=1221801&r2=1221802&view=diff
==============================================================================
--- directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
(original)
+++ directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
Wed Dec 21 16:57:45 2011
@@ -31,6 +31,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.exception.NotImplementedException;
 
 
@@ -168,6 +169,16 @@ public class ImmutableEntry implements E
 
 
     /**
+     * {@inheritDoc}
+     */
+    public void apply( SchemaManager schemaManager )
+    {
+        new Exception().printStackTrace();
+        throw new NotImplementedException( "Cannot apply the schemaManager : the entry "
+ entry.getDn() + " is immutable." );
+    }
+
+
+    /**
      * Clone an entry. All the element are duplicated, so a modification on
      * the original object won't affect the cloned object, as a modification
      * on the cloned object has no impact on the original object



Mime
View raw message