directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r638228 [3/20] - in /directory/sandbox/akarasulu/bigbang/apacheds: ./ apacheds-xbean-spring/src/site/ benchmarks/src/site/ bootstrap-extract/src/site/ bootstrap-partition/src/site/ bootstrap-plugin/src/main/java/org/apache/directory/server/...
Date Tue, 18 Mar 2008 06:13:18 GMT
Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java Mon Mar 17 23:12:41 2008
@@ -43,6 +43,7 @@
 import org.slf4j.LoggerFactory;
 
 import javax.naming.NamingException;
+import javax.naming.directory.InvalidAttributeValueException;
 
 
 /**
@@ -65,9 +66,6 @@
     /** A map containing all the attributes for this entry */
     private Map<AttributeType, ServerAttribute> serverAttributeMap = new HashMap<AttributeType, ServerAttribute>();
     
-    /** The objectClass container */
-    private ObjectClassAttribute objectClassAttribute;
-    
     /** The global registries */
     private final transient Registries registries;
     
@@ -103,8 +101,6 @@
                     OBJECT_CLASS_AT = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT );
                 }
             }
-            
-            setObjectClassAttribute( new ObjectClassAttribute( registries, SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC ) );
         }
         catch ( NamingException ne )
         {
@@ -114,16 +110,15 @@
 
     
     /**
-     * Creates a new instance of DefaultServerEntry.
+     * Creates a new instance of DefaultServerEntry. This is a private constructor
+     * which will only be used by the desrialization method 
      * <p>
      * This entry <b>must</b> be initialized before being used !
      */
-    /*public DefaultServerEntry()
+    public DefaultServerEntry()
     {
         registries = null;
-        
-        initObjectClassAT( registries );
-    }*/
+    }
 
 
     /**
@@ -167,12 +162,6 @@
 
         for ( AttributeType attributeType:attributeTypes )
         {
-            if ( attributeType.equals(  OBJECT_CLASS_AT ) )
-            {
-                // The ObjectClass AttributeType has already been added
-                continue;
-            }
-            
             // Add a new AttributeType without value
             set( attributeType );
         }
@@ -202,24 +191,14 @@
 
         initObjectClassAT( registries );
 
-        if ( attributeType.equals(  OBJECT_CLASS_AT ) )
+        try
         {
-            // If the AttributeType is the ObjectClass AttributeType, then
-            // we don't add it to the entry, as it has already been added
-            // before. But we have to store the upId.
-            objectClassAttribute.setUpId( upId, OBJECT_CLASS_AT );
+            put( upId, attributeType, (String)null );
         }
-        else
+        catch ( NamingException ne )
         {
-            try
-            {
-                put( upId, attributeType, (String)null );
-            }
-            catch ( NamingException ne )
-            {
-                // What do we do ???
-                LOG.error( "We have had an error while adding the '{}' AttributeType : {}", upId, ne.getMessage() );
-            }
+            // What do we do ???
+            LOG.error( "We have had an error while adding the '{}' AttributeType : {}", upId, ne.getMessage() );
         }
     }
 
@@ -290,13 +269,6 @@
 
         for ( ServerAttribute attribute:attributes )
         {
-            if ( attribute.getType().equals(  OBJECT_CLASS_AT ) )
-            {
-                // Treat the ObjectClass in a specific way
-                setObjectClassAttribute( attribute );
-                continue;
-            }
-            
             // Store a new ServerAttribute
             try
             {
@@ -385,128 +357,13 @@
     }
 
     
-    /**
-     * Stores the ObjectClassAttribute into its container.
-     *
-     * @param objectClassAttribute The instance of ObjectClassAttribute
-     * @return The previously stored ObjectClassAttribute, if any
-     */
-    private ServerAttribute setObjectClassAttribute( ObjectClassAttribute objectClassAttribute )
-    {
-        assert objectClassAttribute != null : "The ObjectClass Attribute should not be null";
-        
-        this.objectClassAttribute = objectClassAttribute;
-        ServerAttribute previous = serverAttributeMap.put( OBJECT_CLASS_AT, objectClassAttribute );
-        
-        return previous;
-    }
-
-
-    /**
-     * Stores the ObjectClassAttribute into its container.
-     *
-     * @param objectClassAttribute The instance of ObjectClassAttribute
-     * @return The previously stored ObjectClassAttribute, if any
-     */
-    private ServerAttribute setObjectClassAttribute( ServerAttribute serverAttribute )
-    {
-        assert serverAttribute != null : "The ObjectClass Attribute should not be null";
-        
-        this.objectClassAttribute = new ObjectClassAttribute( registries );
-        ServerAttribute previous = serverAttributeMap.put( OBJECT_CLASS_AT, objectClassAttribute );
-        
-        return previous;
-    }
-
-
-    private ServerAttribute removeObjectClassAttribute( ServerAttribute objectClassAttribute ) throws NamingException
-    {
-        this.objectClassAttribute = (ObjectClassAttribute)objectClassAttribute;
-
-        return serverAttributeMap.remove( OBJECT_CLASS_AT );
-    }
-
-
-    public boolean addObjectClass( ObjectClass objectClass, String alias ) throws NamingException
-    {
-        return objectClassAttribute.addObjectClass( objectClass, alias );
-    }
-
-
-    public boolean addObjectClass( ObjectClass objectClass ) throws NamingException
-    {
-        return objectClassAttribute.addObjectClass( objectClass );
-    }
-
-
-    public void addObjectClass( ObjectClassAttribute objectClassAttribute ) throws NamingException
-    {
-        this.objectClassAttribute = objectClassAttribute;
-    }
-
-
-    public boolean hasObjectClass( ObjectClass objectClass )
-    {
-        return objectClassAttribute.hasObjectClass( objectClass );
-    }
-
-
     public boolean hasObjectClass( String objectClass )
     {
-        try
-        {
-            ObjectClass oc = registries.getObjectClassRegistry().lookup( objectClass );
-            return objectClassAttribute.hasObjectClass( oc );
-        }
-        catch ( NamingException ne )
-        {
-            return false;
-        }
-    }
-
-
-    public Set<ObjectClass> getAbstractObjectClasses()
-    {
-        return objectClassAttribute.getAbstractObjectClasses();
-    }
-
-
-    public ObjectClass getStructuralObjectClass()
-    {
-        return objectClassAttribute.getStructuralObjectClass();
-    }
-
-
-    public Set<ObjectClass> getStructuralObjectClasses()
-    {
-        return objectClassAttribute.getStructuralObjectClasses();
-    }
-
-
-    public Set<ObjectClass> getAuxiliaryObjectClasses()
-    {
-        return objectClassAttribute.getAuxiliaryObjectClasses();
-    }
-
-
-    public Set<ObjectClass> getAllObjectClasses()
-    {
-        return objectClassAttribute.getAllObjectClasses();
-    }
-
-
-    public Set<AttributeType> getMustList()
-    {
-        return objectClassAttribute.getMustList();
-    }
-
-
-    public Set<AttributeType> getMayList()
-    {
-        return objectClassAttribute.getMayList();
+        ServerAttribute oc = serverAttributeMap.get( OBJECT_CLASS_AT );
+        
+        return oc.contains( objectClass );
     }
 
-
     public boolean isValid()
     {
         throw new NotImplementedException();
@@ -571,7 +428,7 @@
      */
     public ServerAttribute put( String upId, byte[]... values ) throws NamingException
     {
-        return put( getAttributeType( upId ), values );
+        return put( upId, getAttributeType( upId ), values );
     }
 
 
@@ -605,28 +462,19 @@
                 throw new IllegalArgumentException( message );
             }
             
-            // The ObjectClass AT is special
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
+            if ( returnedServerAttributes == null )
             {
-                // Just do nothing but clear the ObjectClass values
-                objectClassAttribute.clear();
+                returnedServerAttributes = new ArrayList<ServerAttribute>();
             }
-            else
-            {
-                if ( returnedServerAttributes == null )
-                {
-                    returnedServerAttributes = new ArrayList<ServerAttribute>();
-                }
-
-                if ( serverAttributeMap.containsKey( attributeType ) )
-                {
-                    // Add the removed serverAttribute to the list
-                    returnedServerAttributes.add( serverAttributeMap.remove( attributeType ) );
-                }
 
-                ServerAttribute newAttribute = new DefaultServerAttribute( attributeType );
-                serverAttributeMap.put( attributeType, newAttribute );
+            if ( serverAttributeMap.containsKey( attributeType ) )
+            {
+                // Add the removed serverAttribute to the list
+                returnedServerAttributes.add( serverAttributeMap.remove( attributeType ) );
             }
+
+            ServerAttribute newAttribute = new DefaultServerAttribute( attributeType );
+            serverAttributeMap.put( attributeType, newAttribute );
         }
         
         return returnedServerAttributes;
@@ -658,34 +506,11 @@
                 throw new IllegalArgumentException( message );
             }
             
-            if ( serverAttribute.getType().equals( OBJECT_CLASS_AT ) )
-            {
-                // The objectClass attributeType is special 
-                if ( serverAttribute instanceof ObjectClassAttribute )
-                {
-                    ServerAttribute removed = setObjectClassAttribute( ( ObjectClassAttribute ) serverAttribute );
-
-                    previous.add( removed );
-                }
-                else
-                {
-                    // Here, the attributeType is ObjectClass, but the Attribute itself is 
-                    // not a instance of the ObjectClassAttribute. We will store all of
-                    // its values into a new instance of ObjectClassAttribute. 
-                    ObjectClassAttribute objectClassAttribute = new ObjectClassAttribute( registries, serverAttribute );
-                    ServerAttribute removed = setObjectClassAttribute( objectClassAttribute );
-
-                    previous.add( removed );
-                }
-            }
-            else
+            ServerAttribute removed = serverAttributeMap.put( serverAttribute.getAttributeType(), serverAttribute );
+            
+            if ( removed != null )
             {
-                ServerAttribute removed = serverAttributeMap.put( serverAttribute.getType(), serverAttribute );
-                
-                if ( removed != null )
-                {
-                    previous.add( removed );
-                }
+                previous.add( removed );
             }
         }
         
@@ -737,14 +562,9 @@
         
         for ( ServerAttribute serverAttribute:serverAttributes )
         {
-            if ( serverAttribute.getType().equals( OBJECT_CLASS_AT ) )
-            {
-                removeObjectClassAttribute( new ObjectClassAttribute( registries ) );
-            }
-
-            if ( serverAttributeMap.containsKey( serverAttribute.getType() ) )
+            if ( serverAttributeMap.containsKey( serverAttribute.getAttributeType() ) )
             {
-                serverAttributeMap.remove( serverAttribute.getType() );
+                serverAttributeMap.remove( serverAttribute.getAttributeType() );
                 removedAttributes.add( serverAttribute );
             }
         }
@@ -764,34 +584,9 @@
      * @throws NamingException If some values conflict with the attributeType
      * 
      */
-    public ServerAttribute put( AttributeType attributeType, ServerValue<?>... values ) throws NamingException
+    public ServerAttribute put( AttributeType attributeType, Value<?>... values ) throws NamingException
     {
-        if ( attributeType == null )
-        {
-            String message = "The attributeType should not be null";
-            LOG.error( message );
-            throw new IllegalArgumentException( message );
-        }
-        
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
-
-        if ( existing != null )
-        {
-            // We have an existing attribute : clone it and return it
-            ServerAttribute previous = (ServerAttribute)existing.clone();
-            
-            // Stores the new values into the attribute
-            existing.put( values );
-
-            return previous;
-        }
-        else
-        {
-            ServerAttribute serverAttribute = new DefaultServerAttribute( attributeType, values );
-            put( serverAttribute );
-            
-            return null;
-        }
+        return put( null, attributeType, values );
     }
 
 
@@ -805,29 +600,14 @@
      * @return The existing attribute if any
      * @throws NamingException 
      */
-    public ServerAttribute put( String upId, AttributeType attributeType, ServerValue<?>... values ) throws NamingException
+    public ServerAttribute put( String upId, AttributeType attributeType, Value<?>... values ) throws NamingException
     {
         upId = getUpId( upId, attributeType );
         attributeType = getAttributeType( upId, attributeType );
 
-        ServerAttribute serverAttribute = new DefaultServerAttribute( upId, attributeType );
-
-        if ( attributeType.equals( OBJECT_CLASS_AT ) )
-        {
-            // If the AttributeType is the ObjectClass AttributeType, then
-            // we don't add it to the entry, as it has already been added
-            // before. But we have to store the upId.
-            ServerAttribute previous = objectClassAttribute.clone();
-            objectClassAttribute.setUpId( upId, OBJECT_CLASS_AT );
-            objectClassAttribute.put( values );
-            return previous;
-        }
-        else
-        {
-            // We simply have to set the current attribute values
-            serverAttribute.put( values );
-            return serverAttributeMap.put( attributeType, serverAttribute );
-        }
+        // We simply have to set the current attribute values
+        ServerAttribute serverAttribute = new DefaultServerAttribute( upId, attributeType, values );
+        return serverAttributeMap.put( attributeType, serverAttribute );
     }
 
 
@@ -836,14 +616,14 @@
      * If the attribute already exists, the previous attribute will be 
      * replaced and returned.
      * <p>
-     * The values are stored as ServerValue<?> objects.
+     * The values are stored as Value<?> objects.
      *
      * @param upId The attribute ID
-     * @param values The list of ServerValue<?> objects to inject. It can be empty.
+     * @param values The list of Value<?> objects to inject. It can be empty.
      * @return The replaced attribute
      * @throws NamingException If the attribute does not exist
      */
-    public ServerAttribute put( String upId, ServerValue<?>... values ) throws NamingException
+    public ServerAttribute put( String upId, Value<?>... values ) throws NamingException
     {
         return put( upId, getAttributeType( upId ), values );
     }
@@ -856,38 +636,13 @@
      * we will try to convert values from String to byte[]
      * 
      * @param attributeType The attributeType
-     * @param vals The String values to add to the attribute
+     * @param values The String values to add to the attribute
      * @return The existing ServerAttribute which has been replaced, if any
      * @throws NamingException If some values conflict with the attributeType
      */
-    public ServerAttribute put( AttributeType attributeType, String... vals ) throws NamingException
+    public ServerAttribute put( AttributeType attributeType, String... values ) throws NamingException
     {
-        if ( attributeType == null )
-        {
-            String message = "The attributeType should not be null";
-            LOG.error( message );
-            throw new IllegalArgumentException( message );
-        }
-        
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
-
-        if ( existing != null )
-        {
-            ServerAttribute previous = (ServerAttribute)existing.clone();
-            existing.put( vals );
-            return previous;
-        }
-        else
-        {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                return setObjectClassAttribute( new ObjectClassAttribute( registries, OBJECT_CLASS_AT.getName(), vals ) );
-            }
-            else
-            {
-                return put( null, attributeType, vals );
-            }
-        }
+        return put( null, attributeType, values );
     }
 
     
@@ -908,22 +663,9 @@
 
         ServerAttribute serverAttribute = new DefaultServerAttribute( upId, attributeType );
 
-        if ( attributeType.equals( OBJECT_CLASS_AT ) )
-        {
-            // If the AttributeType is the ObjectClass AttributeType, then
-            // we don't add it to the entry, as it has already been added
-            // before. But we have to store the upId.
-            ServerAttribute previous = objectClassAttribute.clone();
-            objectClassAttribute.setUpId( upId, OBJECT_CLASS_AT );
-            objectClassAttribute.put( values );
-            return previous;
-        }
-        else
-        {
-            // We simply have to set the current attribute values
-            serverAttribute.put( values );
-            return serverAttributeMap.put( attributeType, serverAttribute );
-        }
+        // We simply have to set the current attribute values
+        serverAttribute.put( values );
+        return serverAttributeMap.put( attributeType, serverAttribute );
     }
 
 
@@ -933,36 +675,13 @@
      * The values are byte[], so the attributeType must be non-humanReadable.
      * 
      * @param attributeType The attributeType
-     * @param vals The byte[] values to add to the attribute
+     * @param values The byte[] values to add to the attribute
      * @return The existing ServerAttribute which has been replaced, if any
      * @throws NamingException If some values conflict with the attributeType
      */
-    public ServerAttribute put( AttributeType attributeType, byte[]... vals ) throws NamingException
+    public ServerAttribute put( AttributeType attributeType, byte[]... values ) throws NamingException
     {
-        if ( attributeType == null )
-        {
-            String message = "The attributeType should not be null";
-            LOG.error( message );
-            throw new IllegalArgumentException( message );
-        }
-
-        if ( attributeType.equals( OBJECT_CLASS_AT ) )
-        {
-            throw new UnsupportedOperationException( "Only String values supported for objectClass attribute" );
-        }
-
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
-
-        if ( existing != null )
-        {
-            ServerAttribute previous = (ServerAttribute)existing.clone();
-            existing.put( vals );
-            return previous;
-        }
-        else
-        {
-            return put( null, attributeType, vals );
-        }
+        return put( null, attributeType, values );
     }
 
 
@@ -978,6 +697,13 @@
      */
     public ServerAttribute put( String upId, AttributeType attributeType, byte[]... values ) throws NamingException
     {
+        if ( attributeType == null )
+        {
+            String message = "The attributeType should not be null";
+            LOG.error( message );
+            throw new IllegalArgumentException( message );
+        }
+        
         upId = getUpId( upId, attributeType );
         attributeType = getAttributeType( upId, attributeType );
 
@@ -1005,16 +731,9 @@
         
         for ( AttributeType attributeType:attributeTypes )
         {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
+            if ( serverAttributeMap.containsKey( attributeType ) )
             {
-                attributes.add( setObjectClassAttribute( new ObjectClassAttribute( registries ) ) );
-            }
-            else
-            {
-                if ( serverAttributeMap.containsKey( attributeType ) )
-                {
-                    attributes.add( serverAttributeMap.remove( attributeType ) );
-                }
+                attributes.add( serverAttributeMap.remove( attributeType ) );
             }
         }
         
@@ -1037,14 +756,7 @@
         {
             AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( upId );
     
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                attributes.add( setObjectClassAttribute( new ObjectClassAttribute( registries ) ) );
-            }
-            else
-            {
-                attributes.add( serverAttributeMap.remove( attributeType ) );
-            }
+            attributes.add( serverAttributeMap.remove( attributeType ) );
         }
         
         return attributes;
@@ -1055,7 +767,7 @@
     {
         serverAttributeMap.clear();
 
-        setObjectClassAttribute( new ObjectClassAttribute( registries ) );
+        //setObjectClassAttribute( new ObjectClassAttribute( registries ) );
     }
 
 
@@ -1083,14 +795,36 @@
     }
     
     
+    /**
+     * 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
+     */
     public ServerEntry clone()
     {
         try
         {
+            // First, clone the structure
             DefaultServerEntry clone = (DefaultServerEntry)super.clone();
             
+            // A serverEntry has a DN, an ObjectClass attribute
+            // and many attributes
+            // Clone the DN
             clone.dn = (LdapDN)dn.clone();
-            //clone.objectClassAttribute = objectClassAttribute.clone();
+            
+            // clone the ServerAttribute Map
+            clone.serverAttributeMap = (Map<AttributeType, ServerAttribute>)(((HashMap<AttributeType, ServerAttribute>)serverAttributeMap).clone());
+            
+            // now clone all the servrAttributes
+            clone.serverAttributeMap.clear();
+            
+            for ( AttributeType key:serverAttributeMap.keySet() )
+            {
+                ServerAttribute value = (ServerAttribute)serverAttributeMap.get( key ).clone();
+                clone.serverAttributeMap.put( key, value );
+            }
+            
+            // We are done !
             return clone;
         }
         catch ( CloneNotSupportedException cnse )
@@ -1108,16 +842,16 @@
      * @return <code>true</code> if the value is found within the attribute
      * @throws NamingException If there is a problem
      */
-    public boolean contains( ServerAttribute attribute, Value<?> value ) throws NamingException
+    public boolean contains( AttributeType attributeType, Value<?> value ) throws NamingException
     {
-        if ( attribute == null )
+        if ( attributeType == null )
         {
             return false;
         }
         
-        if ( serverAttributeMap.containsKey( attribute.getType() ) )
+        if ( serverAttributeMap.containsKey( attributeType ) )
         {
-            return serverAttributeMap.get( attribute.getType() ).contains( (ServerValue<?>)value );
+            return serverAttributeMap.get( attributeType ).contains( (Value<?>)value );
         }
         else
         {
@@ -1149,7 +883,7 @@
         }
         else if ( serverAttributeMap.containsKey( attributeType ) )
         {
-            return serverAttributeMap.get( attributeType ).contains( (ServerValue<?>)value );
+            return serverAttributeMap.get( attributeType ).contains( (Value<?>)value );
         }
         else
         {
@@ -1284,6 +1018,72 @@
     
     
     /**
+     * Add a new ServerAttribute, with its upId. If the upId is null,
+     * default to the AttributeType name.
+     * 
+     * Updates the serverAttributeMap.
+     */
+    private void createAttribute( String upId, AttributeType attributeType, Value<?>... values ) throws NamingException, InvalidAttributeValueException
+    {
+        ServerAttribute attribute = new DefaultServerAttribute( attributeType, values );
+        attribute.setUpId( upId, attributeType );
+        serverAttributeMap.put( attributeType, attribute );
+    }
+    
+    
+    /**
+     * Add a new ServerAttribute, with its upId. If the upId is null,
+     * default to the AttributeType name.
+     * 
+     * Updates the serverAttributeMap.
+     */
+    private void createAttribute( String upId, AttributeType attributeType, String... values ) throws NamingException, InvalidAttributeValueException
+    {
+        ServerAttribute attribute = new DefaultServerAttribute( attributeType, values );
+        attribute.setUpId( upId, attributeType );
+        serverAttributeMap.put( attributeType, attribute );
+    }
+    
+    
+    /**
+     * Add a new ServerAttribute, with its upId. If the upId is null,
+     * default to the AttributeType name.
+     * 
+     * Updates the serverAttributeMap.
+     */
+    private void createAttribute( String upId, AttributeType attributeType, byte[]... values ) throws NamingException, InvalidAttributeValueException
+    {
+        ServerAttribute attribute = new DefaultServerAttribute( attributeType, values );
+        attribute.setUpId( upId, attributeType );
+        serverAttributeMap.put( attributeType, attribute );
+    }
+    
+    
+    /*-------------------------------------------------------------------------
+     *
+     * Add an attribute into this entry. We have many different cases.
+     * 1) We are adding a value to an ObjectClass or an ObjectClass to the
+     * entry
+     * 2) We are adding an attribute or a value to an attribute which is not 
+     * an ObjectClass
+     * 
+     * For (1), we will have to check :
+     *  - that the value is not binary
+     *  - we won't add an existing objectClass
+     *  - and the ObjectClass must be valid
+     *  
+     * If everything is fine, we will proceed accordingly to the existence
+     * of the ObjectClass attribute :
+     *  - if the ObjectClass attribute has already been created, we will 
+     *  create the ObjectClass, set its value and add an Attribute into 
+     *  the values Map
+     *  - otherwise, we will just add the value to the Values Map 
+     *  
+     * For (2), we just have to update the values Map :
+     *  - if the attribute already exists, we add the value (no duplicate)
+     *  - or we just add a new attribute to the Map
+     *-----------------------------------------------------------------------*/
+    /**
      * Add an attribute (represented by its ID and some String values) into an 
      * entry.
      * <p> 
@@ -1302,22 +1102,19 @@
             throw new IllegalArgumentException( message );
         }
         
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
-
-        if ( existing != null )
+        ServerAttribute attribute = serverAttributeMap.get( attributeType );
+        
+        if ( attribute != null )
         {
-            existing.add( values );
+            // This Attribute already exist, we add the values 
+            // into it
+            attribute.add( values );
         }
         else
         {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                setObjectClassAttribute( new ObjectClassAttribute( registries, OBJECT_CLASS_AT.getName(), values ) );
-            }
-            else
-            {
-                put( null, attributeType, values );
-            }
+            // We have to create a new Attribute and set the values
+            // and the upId
+            createAttribute( null, attributeType, values );
         }
     }
 
@@ -1341,38 +1138,41 @@
             throw new IllegalArgumentException( message );
         }
         
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        // ObjectClass with binary values are not allowed
+        if ( attributeType.equals( OBJECT_CLASS_AT ) )
+        {
+            String message = "Only String values supported for objectClass attribute";
+            LOG.error(  message  );
+            throw new UnsupportedOperationException( message );
+        }
 
-        if ( existing != null )
+        ServerAttribute attribute = serverAttributeMap.get( attributeType );
+        
+        if ( attribute != null )
         {
-            existing.add( values );
+            // This Attribute already exist, we add the values 
+            // into it
+            attribute.add( values );
         }
         else
         {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                String message = "Only String values supported for objectClass attribute";
-                LOG.error(  message  );
-                throw new UnsupportedOperationException( message );
-            }
-            else
-            {
-                put( null, attributeType, values );
-            }
+            // We have to create a new Attribute and set the values
+            // and the upId
+            createAttribute( null, attributeType, values );
         }
     }
 
 
     /**
-     * Add a new attribute with some ServerValue values into the entry.
+     * Add a new attribute with some Value values into the entry.
      * <p>
      * 
      * @param attributeType The attributeType to add
-     * @param values The associated ServerValue values
+     * @param values The associated Value values
      * @throws NamingException If some values conflict with the attributeType
      * 
      */
-    public void add( AttributeType attributeType, ServerValue<?>... values ) throws NamingException
+    public void add( AttributeType attributeType, Value<?>... values ) throws NamingException
     {
         if ( attributeType == null )
         {
@@ -1381,17 +1181,17 @@
             throw new IllegalArgumentException( message );
         }
         
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
-
-        if ( existing != null )
+        ServerAttribute attribute = serverAttributeMap.get( attributeType );
+    
+        if ( attribute != null )
         {
-            // Adds the new values into the attribute
-            existing.add( values );
+            // This Attribute already exist, we add the values 
+            // into it
+            attribute.add( values );
         }
         else
         {
-            ServerAttribute serverAttribute = new DefaultServerAttribute( attributeType, values );
-            put( serverAttribute );
+            createAttribute( null, attributeType, values );
         }
     }
 
@@ -1423,13 +1223,13 @@
 
 
     /**
-     * Add an attribute (represented by its ID and ServerValue values) into an entry. 
+     * Add an attribute (represented by its ID and Value values) into an entry. 
      *
      * @param upId The attribute ID
-     * @param values The list of ServerValue values to inject. It can be empty
+     * @param values The list of Value values to inject. It can be empty
      * @throws NamingException If the attribute does not exist
      */
-    public void add( String upId, ServerValue<?>... values ) throws NamingException
+    public void add( String upId, Value<?>... values ) throws NamingException
     {
         add( upId, getAttributeType( upId ), values );
     }
@@ -1446,32 +1246,29 @@
      */
     public void add( String upId, AttributeType attributeType, String... values ) throws NamingException
     {
-        upId = getUpId( upId, attributeType );
-        attributeType = getAttributeType( upId, attributeType );
+        if ( attributeType == null )
+        {
+            String message = "The attributeType should not be null";
+            LOG.error( message );
+            throw new IllegalArgumentException( message );
+        }
         
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        upId = getUpId( upId, attributeType );
+
+        ServerAttribute attribute = serverAttributeMap.get( attributeType );
         
-        if ( existing == null )
+        if ( attribute != null )
         {
-            put( upId, attributeType, values );
+            // This Attribute already exist, we add the values 
+            // into it
+            attribute.add( values );
+            attribute.setUpId( upId, attributeType );
         }
         else
         {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                // If the AttributeType is the ObjectClass AttributeType, then
-                // we don't add it to the entry, as it has already been added
-                // before. But we have to store the upId.
-                objectClassAttribute.setUpId( upId, OBJECT_CLASS_AT );
-                objectClassAttribute.add( values );
-            }
-            else
-            {
-                // We simply have to set the current attribute values
-                // and to change its upId
-                existing.add( values );
-                existing.setUpId( upId, attributeType );
-            }
+            // We have to create a new Attribute and set the values
+            // and the upId
+            createAttribute( upId, attributeType, values );
         }
     }
 
@@ -1487,71 +1284,66 @@
      */
     public void add( String upId, AttributeType attributeType, byte[]... values ) throws NamingException
     {
-        upId = getUpId( upId, attributeType );
-        attributeType = getAttributeType( upId, attributeType );
+        // ObjectClass with binary values are not allowed
+        if ( attributeType.equals( OBJECT_CLASS_AT ) )
+        {
+            String message = "Only String values supported for objectClass attribute";
+            LOG.error(  message  );
+            throw new UnsupportedOperationException( message );
+        }
+
+        ServerAttribute attribute = serverAttributeMap.get( attributeType );
         
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        upId = getUpId( upId, attributeType );
         
-        if ( existing == null )
+        if ( attribute != null )
         {
-            put( upId, attributeType, values );
+            // This Attribute already exist, we add the values 
+            // into it
+            attribute.add( values );
+            attribute.setUpId( upId, attributeType );
         }
         else
         {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                String message = "Only String values supported for objectClass attribute";
-                LOG.error(  message  );
-                throw new UnsupportedOperationException( message );
-            }
-            else
-            {
-                // We simply have to set the current attribute values
-                // and to change its upId
-                existing.add( values );
-                existing.setUpId( upId, attributeType );
-            }
+            // We have to create a new Attribute and set the values
+            // and the upId
+            createAttribute( upId, attributeType, values );
         }
     }
 
 
     /**
-     * Adds a new attribute with some ServerValue values into an entry, setting
+     * Adds a new attribute with some Value values into an entry, setting
      * the User Provided ID in the same time.
      *
      * @param upId The User provided ID
      * @param attributeType The associated AttributeType
-     * @param values The ServerValue values to store into the new Attribute
+     * @param values The Value values to store into the new Attribute
      * @throws NamingException 
      */
-    public void add( String upId, AttributeType attributeType, ServerValue<?>... values ) throws NamingException
+    public void add( String upId, AttributeType attributeType, Value<?>... values ) throws NamingException
     {
-        upId = getUpId( upId, attributeType );
-        attributeType = getAttributeType( upId, attributeType );
+        if ( attributeType == null )
+        {
+            String message = "The attributeType should not be null";
+            LOG.error( message );
+            throw new IllegalArgumentException( message );
+        }
         
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        upId = getUpId( upId, attributeType );
         
-        if ( existing == null )
+        ServerAttribute attribute = serverAttributeMap.get( attributeType );
+    
+        if ( attribute != null )
         {
-            put( upId, attributeType, values );
+            // This Attribute already exist, we add the values 
+            // into it
+            attribute.add( values );
+            attribute.setUpId( upId, attributeType );
         }
         else
         {
-            if ( attributeType.equals( OBJECT_CLASS_AT ) )
-            {
-                // If the AttributeType is the ObjectClass AttributeType, then
-                // we don't add it to the entry, as it has already been added
-                // before. But we have to store the upId.
-                objectClassAttribute.setUpId( upId, OBJECT_CLASS_AT );
-                objectClassAttribute.add( values );
-            }
-            else
-            {
-                // We simply have to set the current attribute values
-                // and to change its upId
-                existing.add( values );
-                existing.setUpId( upId, attributeType );
-            }
+            createAttribute( upId, attributeType, values );
         }
     }
 
@@ -1577,19 +1369,62 @@
      */
     public void writeExternal( ObjectOutput out ) throws IOException
     {
+        // First, the DN
         if ( dn == null )
         {
-            // We don't have a DN, so write a -1 instead of a real length
+            // Write an empty DN
+            LdapDN.EMPTY_LDAPDN.writeExternal( out );
+        }
+        else
+        {
+            // Write the DN
+            out.writeObject( dn );
+        }
+        
+        // Then the attributes. 
+        if ( serverAttributeMap == null )
+        {
             out.writeInt( -1 );
         }
         else
         {
-            // Here, we should ask ourselves if it would not be better
-            // to serialize the current LdapDN instead of a String.
-            String dnString = dn.getUpName();
-            out.writeInt( dnString.length() );
-            out.writeUTF( dnString );
+            out.writeInt( serverAttributeMap.size() );
             
+            // Iterate through the keys. We store the Attribute
+            // here, to be able to restore it in the readExternal :
+            // we need access to the registries, which are not available
+            // in the ServerAttribute class.
+            for ( AttributeType attributeType:serverAttributeMap.keySet() )
+            {
+                // We store the OID, as the AttributeType might have no name
+                out.writeUTF( attributeType.getOid() );
+                
+                // And store the attribute.
+                ServerAttribute attribute = serverAttributeMap.get( attributeType );
+
+                // Store the UP id
+                out.writeUTF( attribute.getUpId() );
+                
+                // The number of values
+                int nbValues = attribute.size();
+                
+                if ( nbValues == 0 ) 
+                {
+                    out.writeInt( 0 );
+                }
+                else 
+                {
+                    out.writeInt( nbValues );
+
+                    for ( Value<?> value:attribute )
+                    {
+                        out.writeObject( value );
+                    }
+                }
+            }
+
+            // Note : we don't store the ObjectClassAttribute. I has already
+            // been stored as an attribute.
         }
         
         out.flush();
@@ -1601,69 +1436,109 @@
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
-        if ( in.available() == 0 )
-        {
-            String message = "Cannot read an null Attribute";
-            LOG.error( message );
-            throw new IOException( message );
-        }
-        else
-        {
-            // Read the HR flag
-            boolean hr = in.readBoolean();
-        }
-        /*
-            // Read the UPid
-            upId = in.readUTF();
+        // Read the DN
+        LdapDN dn = (LdapDN)in.readObject();
+        
+        // Read the number of attributes
+        int nbAttributes = in.readInt();
+        
+        serverAttributeMap = new HashMap<AttributeType, ServerAttribute>();
 
-            // Read the number of values
-            int nbValues = in.readInt();
+        // Read the attributes
+        for ( int i = 0; i < nbAttributes; i++ )
+        {
+            String oid = in.readUTF();
             
-            switch ( nbValues )
+            try
             {
-                case -1 :
-                    values = null;
-                    break;
-                    
-                case 0 :
-                    values = new ArrayList<ServerValue<?>>();
-                    break;
-                    
-                default :
-                    values = new ArrayList<ServerValue<?>>();
+                AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( oid );
                 
-                    for ( int i = 0; i < nbValues; i++ )
-                    {
-                        if ( hr )
-                        {
-                            ServerStringValue value = new ServerStringValue( attributeType ); 
-                    }
-                    
-                    break;
-            }
-            if ( nbValues != 0 )
-            {
+                ServerAttribute attribute = new DefaultServerAttribute( attributeType );
                 
+                // Read the attribute upID
+                String upId = in.readUTF();
+                attribute.setUpId( upId, attributeType );
+                
+                // Read the number of values
+                int nbValues = in.readInt();
+                
+                for ( int j = 0; j < nbValues; j++ )
+                {
+                    Value<?> value = (Value<?>)in.readObject();
+                    attribute.add( value );
+                }
+                
+                serverAttributeMap.put(  attributeType, attribute );
             }
-            else
+            catch ( NamingException ne )
             {
                 
             }
-            //
-            String wrapped = in.readUTF();
-            
-            set( wrapped );
+        }
+    }
+    
+    
+    /**
+    * Gets the hashcode of this ServerEntry.
+    *
+    * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int result = 37;
+        
+        result = result*17 + dn.hashCode();
+        
+        for ( ServerAttribute attribute:serverAttributeMap.values() )
+        {
+            result = result*17 + attribute.hashCode();
+        }
+
+        return result;
+    }
+
+    
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        
+        if ( ! ( o instanceof DefaultServerEntry ) )
+        {
+            return false;
+        }
+        
+        DefaultServerEntry other = (DefaultServerEntry)o;
+        
+        if ( !dn.equals( other.getDn() ) )
+        {
+            return false;
+        }
+        
+        if ( size() != other.size() )
+        {
+            return false;
+        }
+        
+        for ( ServerAttribute attribute:other )
+        {
+            ServerAttribute attr = this.get( attribute.getAttributeType() );
             
-            normalizedValue = in.readUTF();
+            if ( attr == null )
+            {
+                return false;
+            }
             
-            if ( ( normalizedValue.length() == 0 ) &&  ( wrapped.length() != 0 ) )
+            if ( !attribute.equals( attr ) )
             {
-                // In this case, the normalized value is equal to the UP value
-                normalizedValue = wrapped;
+                return false;
             }
-        }*/
+        }
+        
+        return true;
     }
-
         
     /**
      * @see Object#toString()
@@ -1675,16 +1550,11 @@
         sb.append( "DefaultEntryServer\n" );
         sb.append( "    dn: " ).append( dn ).append( '\n' );
         
-        if ( objectClassAttribute != null )
-        {
-            sb.append( objectClassAttribute );
-        }
-
         if ( serverAttributeMap.size() != 0 )
         {
             for ( ServerAttribute attribute:serverAttributeMap.values() )
             {
-                if ( !attribute.getType().equals( OBJECT_CLASS_AT ) )
+                if ( !attribute.getAttributeType().equals( OBJECT_CLASS_AT ) )
                 {
                     sb.append( attribute );
                 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java Mon Mar 17 23:12:41 2008
@@ -20,7 +20,7 @@
 
 
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.ClientAttribute;
 
 import javax.naming.NamingException;
 import javax.naming.directory.InvalidAttributeValueException;
@@ -33,70 +33,82 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ServerAttribute extends EntryAttribute<ServerValue<?>>
+public interface ServerAttribute extends ClientAttribute
 {
     /**
-     * Gets the attribute type associated with this ServerAttribute.
+     * Get the attribute type associated with this ServerAttribute.
      *
      * @return the attributeType associated with this entry attribute
      */
-    AttributeType getType();
+    AttributeType getAttributeType();
 
+    
     /**
-     * Get's the user provided identifier for this entry.  This is the value
-     * that will be used as the identifier for the attribute within the
-     * entry.  If this is a commonName attribute for example and the user
-     * provides "COMMONname" instead when adding the entry then this is
-     * the format the user will have that entry returned by the directory
-     * server.  To do so we store this value as it was given and track it
-     * in the attribute using this property.
+     * <p>
+     * Set the attribute type associated with this ServerAttribute.
+     * </p>
+     * <p>
+     * The current attributeType will be replaced. It is the responsibility of
+     * the caller to insure that the existing values are compatible with the new
+     * AttributeType
+     * </p>
      *
-     * @return the user provided identifier for this attribute
+     * @param the attributeType associated with this entry attribute
      */
-    String getUpId();
-    
+    void setAttributeType( AttributeType attributeType );
+
     
     /**
+     * <p>
+     * Check if the current attribute type is of the expected attributeType
+     * </p>
+     * <p>
+     * This method won't tell if the current attribute is a descendant of 
+     * the attributeType. For instance, the "CN" serverAttribute will return
+     * false if we ask if it's an instance of "Name". 
+     * </p> 
+     *
+     * @param attributeId The AttributeType ID to check
+     * @return True if the current attribute is of the expected attributeType
+     * @throws InvalidAttributeValueException If there is no AttributeType
+     */
+    boolean instanceOf( String attributeId ) throws InvalidAttributeValueException;
+
+
+    /**
+     * <p>
      * Set the user provided ID. If we have none, the upId is assigned
      * the attributetype's name. If it does not have any name, we will
      * use the OID.
+     * </p>
      * <p>
      * If we have an upId and an AttributeType, they must be compatible. :
      *  - if the upId is an OID, it must be the AttributeType's OID
      *  - otherwise, its normalized form must be equals to ones of
      *  the attributeType's names.
-     *
+     * </p>
+     * <p>
+     * In any case, the ATtributeType will be changed. The caller is responsible for
+     * the present values to be compatoble with the new AttributeType.
+     * </p>
+     * 
      * @param upId The attribute ID
      * @param attributeType The associated attributeType
      */
     public void setUpId( String upId, AttributeType attributeType );
-
+    
     
     /**
+     * <p>
      * Checks to see if this attribute is valid along with the values it contains.
-     *
+     * </p>
+     * <p>
+     * An attribute is valid if :
+     * <li>All of its values are valid with respect to the attributeType's syntax checker</li>
+     * <li>If the attributeType is SINGLE-VALUE, then no more than a value should be present</li>
+     *</p>
      * @return true if the attribute and it's values are valid, false otherwise
      * @throws NamingException if there is a failure to check syntaxes of values
      */
     boolean isValid() throws NamingException;
-    
-    
-    /**
-     * Get the String value, if and only if the value is known to be a String,
-     * otherwise a InvalidAttributeValueException will be thrown
-     *
-     * @return The value as a String
-     * @throws InvalidAttributeValueException If the value is a byte[]
-     */
-    String getString() throws InvalidAttributeValueException;
-
-
-    /**
-     * Get the byte[] value, if and only if the value is known to be Binary,
-     * otherwise a InvalidAttributeValueException will be thrown
-     *
-     * @return The value as a String
-     * @throws InvalidAttributeValueException If the value is a String
-     */
-    byte[] getBytes() throws InvalidAttributeValueException;
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Mon Mar 17 23:12:41 2008
@@ -20,8 +20,10 @@
 
 
 import org.apache.directory.shared.ldap.NotImplementedException;
-import org.apache.directory.shared.ldap.entry.AbstractBinaryValue;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
 import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.ByteArrayComparator;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -47,7 +49,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ServerBinaryValue extends AbstractBinaryValue implements ServerValue<byte[]>, Externalizable
+public class ServerBinaryValue extends ClientBinaryValue
 {
     /** Used for serialization */
     public static final long serialVersionUID = 2L;
@@ -62,16 +64,53 @@
     /** reference to the attributeType which is not serialized */
     private transient AttributeType attributeType;
 
-    /** the canonical representation of the wrapped binary value */
-    private transient byte[] normalizedValue;
-    
     /** A flag set if the normalized data is different from the wrapped data */
     private transient boolean same;
 
-    /** cached results of the isValid() method call */
-    private transient Boolean valid;
 
+    // -----------------------------------------------------------------------
+    // utility methods
+    // -----------------------------------------------------------------------
+    /**
+     * Utility method to get some logs if an assert fails
+     */
+    protected String logAssert( String message )
+    {
+        LOG.error(  message );
+        return message;
+    }
+
+    
+    /**
+     *  Check the attributeType member. It should not be null, 
+     *  and it should contains a syntax.
+     */
+    protected String checkAttributeType( AttributeType attributeType )
+    {
+        try
+        {
+            if ( attributeType == null )
+            {
+                return "The AttributeType parameter should not be null";
+            }
+            
+            if ( attributeType.getSyntax() == null )
+            {
+                return "There is no Syntax associated with this attributeType";
+            }
+
+            return null;
+        }
+        catch ( NamingException ne )
+        {
+            return "This AttributeType is incorrect";
+        }
+    }
 
+    
+    // -----------------------------------------------------------------------
+    // Constructors
+    // -----------------------------------------------------------------------
     /**
      * Creates a ServerBinaryValue without an initial wrapped value.
      *
@@ -79,6 +118,7 @@
      */
     public ServerBinaryValue( AttributeType attributeType )
     {
+        super();
         assert checkAttributeType( attributeType) == null : logAssert( checkAttributeType( attributeType ) );
 
         try
@@ -107,40 +147,27 @@
     public ServerBinaryValue( AttributeType attributeType, byte[] wrapped )
     {
         this( attributeType );
-        super.set( wrapped );
+        this.wrapped = wrapped;
     }
 
 
-    // -----------------------------------------------------------------------
-    // Value<String> Methods
-    // -----------------------------------------------------------------------
-
-
     /**
-     * Sets the wrapped binary value.  Has the side effect of setting the
-     * normalizedValue and the valid flags to null if the wrapped value is
-     * different than what is already set.  These cached values must be
-     * recomputed to be correct with different values.
-     *
-     * @see ServerValue#set(Object)
-     */
-    public final void set( byte[] wrapped )
-    {
-        // Why should we invalidate the normalized value if it's we're setting the
-        // wrapper to it's current value?
-        byte[] value = getReference();
-        
-        if ( value != null )
-        {
-            if ( Arrays.equals( wrapped, value ) )
-            {
-                return;
-            }
-        }
-
-        normalizedValue = null;
-        valid = null;
-        super.set( wrapped );
+     * Creates a ServerStringValue with an initial wrapped String value and
+     * a normalized value.
+     *
+     * @param attributeType the schema type associated with this ServerStringValue
+     * @param wrapped the value to wrap which can be null
+     * @param normalizedValue the normalized value
+     */
+    /** No protection */ ServerBinaryValue( AttributeType attributeType, byte[] wrapped, byte[] normalizedValue, boolean same, boolean valid )
+    {
+        super( wrapped );
+        this.normalized = true;
+        this.attributeType = attributeType;
+        this.normalizedValue = normalizedValue;
+        this.valid = valid;
+        this.same = same;
+        this.oid = attributeType.getOid();
     }
 
 
@@ -149,6 +176,12 @@
     // -----------------------------------------------------------------------
     public void normalize() throws NamingException
     {
+        if ( isNormalized() )
+        {
+            // Bypass the normalization if it has already been done. 
+            return;
+        }
+        
         if ( getReference() != null )
         {
             Normalizer normalizer = getNormalizer();
@@ -156,10 +189,12 @@
             if ( normalizer == null )
             {
                 normalizedValue = getCopy();
+                setNormalized( false );
             }
             else
             {
                 normalizedValue = ( byte[] ) normalizer.normalize( getCopy() );
+                setNormalized( true );
             }
             
             if ( Arrays.equals( super.getReference(), normalizedValue ) )
@@ -175,6 +210,7 @@
         {
             normalizedValue = null;
             same = true;
+            setNormalized( false );
         }
     }
 
@@ -190,16 +226,61 @@
      * @return a reference to the normalized version of the wrapped value
      * @throws NamingException with failures to normalize
      */
-    public byte[] getNormalizedReference() throws NamingException
+    public byte[] getNormalizedValueReference()
     {
         if ( isNull() )
         {
             return null;
         }
 
-        if ( normalizedValue == null )
+        if ( !isNormalized() )
         {
-            normalize();
+            try
+            {
+                normalize();
+            }
+            catch ( NamingException ne )
+            {
+                String message = "Cannot normalize the value :" + ne.getMessage();
+                LOG.warn( message );
+                normalized = false;
+            }
+        }
+
+        return normalizedValue;
+    }
+
+
+    /**
+     * Gets the normalized (canonical) representation for the wrapped byte[].
+     * If the wrapped byte[] is null, null is returned, otherwise the normalized
+     * form is returned.  If no the normalizedValue is null, then this method
+     * will attempt to generate it from the wrapped value: repeated calls to
+     * this method do not unnecessarily normalize the wrapped value.  Only changes
+     * to the wrapped value result in attempts to normalize the wrapped value.
+     *
+     * @return gets the normalized value
+     * @throws NamingException if the value cannot be properly normalized
+     */
+    public byte[] getNormalizedValue() 
+    {
+        if ( isNull() )
+        {
+            return null;
+        }
+
+        if ( !normalized )
+        {
+            try
+            {
+                normalize();
+            }
+            catch ( NamingException ne )
+            {
+                String message = "Cannot normalize the value :" + ne.getMessage();
+                LOG.warn( message );
+                normalized = false;
+            }
         }
 
         return normalizedValue;
@@ -215,16 +296,37 @@
      * @return the normalized version of the wrapped value
      * @throws NamingException if schema entity resolution fails or normalization fails
      */
-    public byte[] getNormalizedCopy() throws NamingException
+    public byte[] getNormalizedValueCopy()
     {
+        if ( isNull() )
+        {
+            return null;
+        }
+
         if ( normalizedValue == null )
         {
-            getNormalizedReference();
+            try
+            {
+                normalize();
+            }
+            catch ( NamingException ne )
+            {
+                String message = "Cannot normalize the value :" + ne.getMessage();
+                LOG.warn( message );
+                normalized = false;
+            }
         }
 
-        byte[] copy = new byte[ normalizedValue.length ];
-        System.arraycopy( normalizedValue, 0, copy, 0, normalizedValue.length );
-        return copy;
+        if ( normalizedValue != null )
+        {
+            byte[] copy = new byte[ normalizedValue.length ];
+            System.arraycopy( normalizedValue, 0, copy, 0, normalizedValue.length );
+            return copy;
+        }
+        else
+        {
+            return null;
+        }
     }
 
 
@@ -235,27 +337,46 @@
      * change. Syntax checks only result on the first check, and when the wrapped
      * value changes.
      *
-     * @see ServerValue#isValid()
+     * @see Value<T>#isValid()
      */
-    public final boolean isValid() throws NamingException
+    public final boolean isValid()
     {
         if ( valid != null )
         {
             return valid;
         }
 
-        valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
+        try
+        {
+            valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
+        }
+        catch ( NamingException ne )
+        {
+            String message = "Cannot check the syntax : " + ne.getMessage();
+            LOG.error( message );
+            valid = false;
+        }
+        
         return valid;
     }
 
+    
+    /**
+     * @return Tells if the wrapped value and the normalized value are the same 
+     */
+    public final boolean isSame()
+    {
+        return same;
+    }
+    
 
     /**
      *
-     * @see ServerValue#compareTo(ServerValue)
+     * @see Value<T>#compareTo(ServerValue)
      * @throws IllegalStateException on failures to extract the comparator, or the
      * normalizers needed to perform the required comparisons based on the schema
      */
-    public int compareTo( ServerValue<byte[]> value )
+    public int compareTo( Value<byte[]> value )
     {
         if ( isNull() )
         {
@@ -282,7 +403,16 @@
 
             try
             {
-                return getComparator().compare( getNormalizedReference(), binaryValue.getNormalizedReference() );
+                Comparator<? super Value<byte[]>> comparator = getComparator();
+                
+                if ( comparator != null )
+                {
+                    return getComparator().compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference() );
+                }
+                else
+                {
+                    return ByteArrayComparator.INSTANCE.compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference() );
+                }
             }
             catch ( NamingException e )
             {
@@ -293,11 +423,17 @@
             }
         }
 
-        throw new NotImplementedException( "I don't really know how to compare anything other " +
-                "than ServerBinaryValues at this point in time." );
+        String message = "I don't really know how to compare anything other " +
+        "than ServerBinaryValues at this point in time.";
+        LOG.error( message );
+        throw new NotImplementedException( message );
     }
 
 
+    /**
+     * Get the associated AttributeType
+     * @return The AttributeType
+     */
     public AttributeType getAttributeType()
     {
         return attributeType;
@@ -305,7 +441,15 @@
 
 
     /**
-     * @see ServerValue#instanceOf(AttributeType)
+     * Check if the value is stored into an instance of the given 
+     * AttributeType, or one of its ascendant.
+     * 
+     * For instance, if the Value is associated with a CommonName,
+     * checking for Name will match.
+     * 
+     * @param attributeType The AttributeType we are looking at
+     * @return <code>true</code> if the value is associated with the given
+     * attributeType or one of its ascendant
      */
     public boolean instanceOf( AttributeType attributeType ) throws NamingException
     {
@@ -321,8 +465,6 @@
     // -----------------------------------------------------------------------
     // Object Methods
     // -----------------------------------------------------------------------
-
-
     /**
      * @see Object#hashCode()
      * @throws IllegalStateException on failures to extract the comparator, or the
@@ -337,16 +479,7 @@
             return 0;
         }
 
-        try
-        {
-            return Arrays.hashCode( getNormalizedReference() );
-        }
-        catch ( NamingException e )
-        {
-            String msg = "Failed to normalize \"" + toString() + "\" while trying to get hashCode()";
-            LOG.error( msg, e );
-            throw new IllegalStateException( msg, e );
-        }
+        return Arrays.hashCode( getNormalizedValueReference() );
     }
 
 
@@ -372,30 +505,42 @@
 
         ServerBinaryValue other = ( ServerBinaryValue ) obj;
         
-        if ( isNull() && other.isNull() )
+        if ( !attributeType.equals( other.attributeType ) )
         {
-            return true;
+            return false;
         }
-
-        if ( isNull() != other.isNull() )
+        
+        if ( isNull() )
         {
-            return false;
+            return other.isNull();
         }
 
-        // now unlike regular values we have to compare the normalized values
-        try
+        // Shortcut : if the values are equals, no need to compare
+        // the normalized values
+        if ( Arrays.equals( wrapped, other.get() ) )
         {
-            return Arrays.equals( getNormalizedReference(), other.getNormalizedReference() );
+            return true;
         }
-        catch ( NamingException e )
+        else
         {
-            // 1st this is a warning because we're recovering from it and secondly
-            // we build big string since waste is not an issue when exception handling
-            LOG.warn( "Failed to get normalized value while trying to compare StringValues: "
-                    + toString() + " and " + other.toString() , e );
+            try
+            {
+                Comparator<byte[]> comparator = getComparator();
 
-            // recover by comparing non-normalized values
-            return Arrays.equals( getReference(), other.getReference() );
+                // Compare normalized values
+                if ( comparator == null )
+                {
+                    return Arrays.equals( getNormalizedValueReference(), other.getNormalizedValueReference() );
+                }
+                else
+                {
+                    return comparator.compare( getNormalizedValueReference(), other.getNormalizedValueReference() ) == 0;
+                }
+            }
+            catch ( NamingException ne )
+            {
+                return false;
+            }
         }
     }
 
@@ -403,8 +548,6 @@
     // -----------------------------------------------------------------------
     // Private Helper Methods (might be put into abstract base class)
     // -----------------------------------------------------------------------
-
-
     /**
      * Find a matchingRule to use for normalization and comparison.  If an equality
      * matchingRule cannot be found it checks to see if other matchingRules are
@@ -548,12 +691,14 @@
                 case -1 :
                     // No value, no normalized value
                     same = true;
+                    setNormalized( false );
                     break;
                     
                 case 0 :
                     // Empty value, so is the normalized value
                     wrapped = StringTools.EMPTY_BYTES;
                     normalizedValue = wrapped;
+                    setNormalized( true );
                     same = true;
                     break;
                     
@@ -575,12 +720,14 @@
                         case 0 :
                             normalizedValue = StringTools.EMPTY_BYTES;
                             same = true;
+                            setNormalized( false );
                             break;
                             
                         default :
                             same = false;
                             normalizedValue = new byte[normalizedLength];
                             in.readFully( normalizedValue );
+                            setNormalized( true );
                             break;
                     }
                     
@@ -590,4 +737,4 @@
             set( wrapped );
         }
     }
-}
\ No newline at end of file
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java Mon Mar 17 23:12:41 2008
@@ -20,6 +20,7 @@
 
 
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 
@@ -40,43 +41,6 @@
     // -----------------------------------------------------------------------
     // Schema Related Methods
     // -----------------------------------------------------------------------
-
-
-    /**
-     * Adds an objectClass to the objectClass attribute of this ServerEntry using
-     * a specific alias name with the case provided by the user.
-     *
-     * @param objectClass the objectClass to add to this ServerEntry
-     * @param alias the optional user provided alias to use
-     * @return true if the objectClass is added, false otherwise
-     * @throws NamingException if there are problems resolving entities while
-     * adding the objectClass and its ancestors
-     */
-    boolean addObjectClass( ObjectClass objectClass, String alias ) throws NamingException;
-
-
-    /**
-     * Adds an objectClass to the objectClass attribute of this ServerEntry using
-     * the first alias it can find.  If no alias name exists the numeric OID of the
-     * objectClass is added as a value to the objectClass attribute.
-     *
-     * @param objectClass the objectClass to add to this ServerEntry
-     * @return true if the objectClass is added, false otherwise
-     * @throws NamingException if there are problems resolving entities while
-     * adding the objectClass and its ancestors
-     */
-    boolean addObjectClass( ObjectClass objectClass ) throws NamingException;
-
-
-    /**
-     * Checks to see if this entry is of the objectClass.
-     *
-     * @param objectClass the objectClass to check for in this ServerEntry
-     * @return true if this entry is of the objectClass, false otherwise
-     */
-    boolean hasObjectClass( ObjectClass objectClass );
-
-
     /**
      * Checks to see if this entry is of the objectClass.
      *
@@ -85,78 +49,6 @@
      */
     boolean hasObjectClass( String objectClass );
 
-
-    /**
-     * Gets the first structural objectClass that it can find within the entry.
-     * If the entry is inconsistent and contains no objectClass attribute then
-     * null is returned.  If the entry is inconsistent and contains more than
-     * one structural objectClass which is illegal, then the first to be found
-     * will be returned.
-     *
-     * @return the first structural objectClass found in this entry
-     */
-    ObjectClass getStructuralObjectClass();
-
-
-    /**
-     * Gets all the structural objectClasses that are found within the entry
-     * even though such a condition is considered invalid.  Only one structural
-     * objectClass can be present within a valid entry.  The entry can also be
-     * inconsistent by having no structural objectClasses then an empty set is
-     * returned.
-     *
-     * @return all the structural objectClasses found in this entry
-     */
-    Set<ObjectClass> getStructuralObjectClasses();
-
-
-    /**
-     * Gets all the auxiliary objectClasses that it can find within the entry.
-     * If the entry is inconsistent and contains no objectClass attribute then
-     * the empty set is returned.
-     *
-     * @return the set of auxiliary objectClasses found in this entry
-     */
-    Set<ObjectClass> getAuxiliaryObjectClasses();
-
-
-    /**
-     * Gets all the abstract objectClasses that it can find within the entry.
-     * If the entry is inconsistent and contains no objectClass attribute then
-     * the empty set is returned.
-     *
-     * @return the set of abstract objectClasses found in this entry
-     */
-    Set<ObjectClass> getAbstractObjectClasses();
-
-
-    /**
-     * Gets the objectClasses associated with this entry. If there is no
-     * objectClass attribute contained within this entry then an empty set
-     * is returned.
-     *
-     * @return the objectClasses which govern the structure of this entry
-     */
-    Set<ObjectClass> getAllObjectClasses();
-
-
-    /**
-     * Gets the combinded set of all required attributes for this entry across
-     * all objectClasses.
-     *
-     * @return the combinded set of all required attributes
-     */
-    Set<AttributeType> getMustList();
-
-
-    /**
-     * Gets the combined set of all optional attributes for this entry across
-     * all objectClasses.
-     *
-     * @return the combined set of all optional attributes
-     */
-    Set<AttributeType> getMayList();
-
     
     /**
      * Gets all the attributes type (ObjectClasses, May and Must)
@@ -254,7 +146,7 @@
      *         <code>null</code>
      * @throws NamingException if there are resolution issues
      */
-    ServerAttribute put( AttributeType attributeType, ServerValue<?>... values ) throws NamingException;
+    ServerAttribute put( AttributeType attributeType, Value<?>... values ) throws NamingException;
 
     /**
      * Places a new attribute with the supplied attributeType and value into this
@@ -271,7 +163,7 @@
      *         <code>null</code>
      * @throws NamingException if there are failures
      */
-    ServerAttribute put( String upId, ServerValue<?>... values ) throws NamingException;
+    ServerAttribute put( String upId, Value<?>... values ) throws NamingException;
 
 
     /**

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryPropertyEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryPropertyEditor.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryPropertyEditor.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryPropertyEditor.java Mon Mar 17 23:12:41 2008
@@ -167,7 +167,6 @@
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             return null;
         }
     }



Mime
View raw message