You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/12/13 01:49:31 UTC

svn commit: r603787 - in /directory: apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/

Author: elecharny
Date: Wed Dec 12 16:49:28 2007
New Revision: 603787

URL: http://svn.apache.org/viewvc?rev=603787&view=rev
Log:
Improved the new ServerEntry API by using generics and adding some varargs.

Modified:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Modification.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java Wed Dec 12 16:49:28 2007
@@ -32,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class BasicServerAttribute implements ServerAttribute
+public class BasicServerAttribute implements ServerAttribute<ServerValue<?>>
 {
     private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
     private AttributeType attributeType;
@@ -88,6 +88,7 @@
     public BasicServerAttribute( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
     {
         this.attributeType = attributeType;
+        
         if ( val == null )
         {
             if ( attributeType.getSyntax().isHumanReadable() )
@@ -122,6 +123,7 @@
 
             values.add( val );
         }
+        
         setUpId( upId, attributeType );
     }
 
@@ -307,7 +309,7 @@
     }
 
 
-    public Iterator<? extends ServerValue<?>> getAll()
+    public Iterator<ServerValue<?>> getAll()
     {
         return iterator();
     }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java Wed Dec 12 16:49:28 2007
@@ -19,9 +19,11 @@
 package org.apache.directory.server.core.entry;
 
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -44,11 +46,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class DefaultServerEntry implements ServerEntry
+public class DefaultServerEntry implements ServerEntry<ServerAttribute<ServerValue<?>>>
 {
     private static final Logger LOG = LoggerFactory.getLogger( DefaultServerEntry.class );
 
-    private Map<AttributeType, ServerAttribute> serverAttributeMap = new HashMap<AttributeType, ServerAttribute>();
+    private Map<AttributeType, ServerAttribute<ServerValue<?>>> serverAttributeMap = new HashMap<AttributeType, ServerAttribute<ServerValue<?>>>();
     private ObjectClassAttribute objectClassAttribute;
     private final transient Registries registries;
     private transient AttributeType objectClassAT;
@@ -65,13 +67,21 @@
     }
 
 
-    private ServerAttribute setObjectClassAttribute( ObjectClassAttribute objectClassAttribute ) throws NamingException
+    private ServerAttribute<ServerValue<?>> setObjectClassAttribute( ServerAttribute<ServerValue<?>> objectClassAttribute ) throws NamingException
     {
-        this.objectClassAttribute = objectClassAttribute;
+        this.objectClassAttribute = (ObjectClassAttribute)objectClassAttribute;
         return serverAttributeMap.put( objectClassAT, objectClassAttribute );
     }
 
 
+    private ServerAttribute<ServerValue<?>> removeObjectClassAttribute( ServerAttribute<ServerValue<?>> objectClassAttribute ) throws NamingException
+    {
+        this.objectClassAttribute = (ObjectClassAttribute)objectClassAttribute;
+
+        return serverAttributeMap.remove( objectClassAT );
+    }
+
+
     public boolean addObjectClass( ObjectClass objectClass, String alias ) throws NamingException
     {
         return objectClassAttribute.addObjectClass( objectClass, alias );
@@ -144,13 +154,13 @@
     }
 
 
-    public ServerAttribute get( AttributeType attributeType )
+    public ServerAttribute<ServerValue<?>> get( AttributeType attributeType )
     {
         return serverAttributeMap.get( attributeType );
     }
 
 
-    public ServerAttribute put( ServerAttribute serverAttribute ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( ServerAttribute<ServerValue<?>> serverAttribute ) throws NamingException
     {
         if ( serverAttribute.getType().equals( objectClassAT ) && serverAttribute instanceof ObjectClassAttribute )
         {
@@ -160,10 +170,12 @@
         if ( serverAttribute.getType().equals( objectClassAT ) )
         {
             ObjectClassAttribute objectClassAttribute = new ObjectClassAttribute( registries );
+            
             for ( ServerValue<?> val : serverAttribute )
             {
                 objectClassAttribute.add( val );
             }
+            
             return setObjectClassAttribute( objectClassAttribute );
         }
 
@@ -171,19 +183,58 @@
     }
 
 
-    public ServerAttribute put( String upId, AttributeType attributeType ) throws NamingException
+    public List<ServerAttribute<ServerValue<?>>> put( ServerAttribute<ServerValue<?>>... serverAttributes ) throws NamingException
+    {
+        List<ServerAttribute<ServerValue<?>>> duplicatedAttributes = new ArrayList<ServerAttribute<ServerValue<?>>>();
+        
+        for ( ServerAttribute<ServerValue<?>> serverAttribute:serverAttributes )
+        {
+            if ( serverAttribute.getType().equals( objectClassAT ) )
+            {
+                if ( serverAttribute instanceof ObjectClassAttribute )
+                {
+                    setObjectClassAttribute( ( ObjectClassAttribute ) serverAttribute );
+                }
+                else
+                {
+                    ObjectClassAttribute objectClassAttribute = new ObjectClassAttribute( registries );
+                    
+                    for ( ServerValue<?> val : serverAttribute )
+                    {
+                        objectClassAttribute.add( val );
+                    }
+                    
+                    setObjectClassAttribute( objectClassAttribute );
+                }
+            }
+
+            if ( serverAttributeMap.containsKey( serverAttribute.getType() ) )
+            {
+                duplicatedAttributes.add( serverAttribute );
+            }
+            else
+            {
+                serverAttributeMap.put( serverAttribute.getType(), serverAttribute );
+            }
+        }
+        
+        return duplicatedAttributes;
+    }
+
+
+    public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType ) throws NamingException
     {
         throw new NotImplementedException();
     }
 
 
-    public ServerAttribute put( AttributeType attributeType ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( AttributeType attributeType ) throws NamingException
     {
         throw new NotImplementedException();
     }
 
 
-    public ServerAttribute remove( ServerAttribute serverAttribute ) throws NamingException
+    public ServerAttribute<ServerValue<?>> remove( ServerAttribute<ServerValue<?>> serverAttribute ) throws NamingException
     {
         if ( serverAttribute.getType().equals( objectClassAT ) )
         {
@@ -194,9 +245,31 @@
     }
 
 
-    public ServerAttribute put( AttributeType attributeType, ServerValue<?> val ) throws NamingException
+    public List<ServerAttribute<ServerValue<?>>> remove( ServerAttribute<ServerValue<?>>... serverAttributes ) throws NamingException
+    {
+        List<ServerAttribute<ServerValue<?>>> removedAttributes = new ArrayList<ServerAttribute<ServerValue<?>>>();
+        
+        for ( ServerAttribute<ServerValue<?>> serverAttribute:serverAttributes )
+        {
+            if ( serverAttribute.getType().equals( objectClassAT ) )
+            {
+                removeObjectClassAttribute( new ObjectClassAttribute( registries ) );
+            }
+
+            if ( serverAttributeMap.containsKey( serverAttribute.getType() ) )
+            {
+                serverAttributeMap.remove( serverAttribute.getType() );
+                removedAttributes.add( serverAttribute );
+            }
+        }
+        
+        return removedAttributes;
+    }
+
+
+    public ServerAttribute<ServerValue<?>> put( AttributeType attributeType, ServerValue<?> val ) throws NamingException
     {
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        ServerAttribute<ServerValue<?>> existing = serverAttributeMap.get( attributeType );
 
         if ( existing != null )
         {
@@ -209,7 +282,7 @@
     }
 
 
-    public ServerAttribute put( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException
     {
         if ( attributeType.equals( objectClassAT ) )
         {
@@ -220,9 +293,9 @@
     }
 
 
-    public ServerAttribute put( AttributeType attributeType, String val ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( AttributeType attributeType, String val ) throws NamingException
     {
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        ServerAttribute<ServerValue<?>> existing = serverAttributeMap.get( attributeType );
 
         if ( attributeType.equals( objectClassAT ) )
         {
@@ -245,7 +318,7 @@
     }
 
 
-    public ServerAttribute put( String upId, AttributeType attributeType, String val ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType, String val ) throws NamingException
     {
         if ( attributeType.equals( objectClassAT ) )
         {
@@ -256,14 +329,14 @@
     }
 
 
-    public ServerAttribute put( AttributeType attributeType, byte[] val ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( AttributeType attributeType, byte[] val ) throws NamingException
     {
         if ( attributeType.equals( objectClassAT ) )
         {
             throw new UnsupportedOperationException( "Only String values supported for objectClass attribute" );
         }
 
-        ServerAttribute existing = serverAttributeMap.get( attributeType );
+        ServerAttribute<ServerValue<?>> existing = serverAttributeMap.get( attributeType );
 
         if ( existing != null )
         {
@@ -276,7 +349,7 @@
     }
 
 
-    public ServerAttribute put( String upId, AttributeType attributeType, byte[] val ) throws NamingException
+    public ServerAttribute<ServerValue<?>> put( String upId, AttributeType attributeType, byte[] val ) throws NamingException
     {
         if ( attributeType.equals( objectClassAT ) )
         {
@@ -287,7 +360,7 @@
     }
 
 
-    public ServerAttribute remove( AttributeType attributeType ) throws NamingException
+    public ServerAttribute<ServerValue<?>> remove( AttributeType attributeType ) throws NamingException
     {
         if ( attributeType.equals( objectClassAT ) )
         {
@@ -329,7 +402,7 @@
     }
 
 
-    public Iterator<ServerAttribute> iterator()
+    public Iterator<ServerAttribute<ServerValue<?>>> iterator()
     {
         return Collections.unmodifiableMap( serverAttributeMap ).values().iterator();
     }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java Wed Dec 12 16:49:28 2007
@@ -38,7 +38,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ObjectClassAttribute implements ServerAttribute
+public class ObjectClassAttribute implements ServerAttribute<ServerValue<?>>
 {
     /** A logger */
     private static final Logger LOG = LoggerFactory.getLogger( ObjectClassAttribute.class );
@@ -398,7 +398,7 @@
      */
     public boolean add( ServerValue<?> val )
     {
-        return values.add( val );
+        return values.add( (ServerValue<?>)val );
     }
 
 
@@ -450,7 +450,7 @@
     }
 
 
-    public Iterator<? extends ServerValue<?>> getAll()
+    public Iterator<ServerValue<?>> getAll()
     {
         return iterator();
     }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java Wed Dec 12 16:49:28 2007
@@ -26,18 +26,39 @@
 
 
 /**
- * Document me!
+ * The server specific interface extending the EntryAttribute interface. It adds
+ * three more methods which are Server side.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ServerAttribute extends EntryAttribute<ServerValue<?>>, Iterable<ServerValue<?>>
+public interface ServerAttribute<T extends ServerValue<?>> extends EntryAttribute<T>, Iterable<ServerValue<?>>
 {
+    /**
+     * Gets the attribute type associated with this ServerAttribute.
+     *
+     * @return the attributeType associated with this entry attribute
+     */
     AttributeType getType();
 
-
+    /**
+     * 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.
+     *
+     * @return the user provided identifier for this attribute
+     */
     String getUpId();
 
-
+    /**
+     * Checks to see if this attribute is valid along with the values it contains.
+     *
+     * @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;
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Wed Dec 12 16:49:28 2007
@@ -46,10 +46,6 @@
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
 
-    /** used to dynamically lookup the attributeType when/if deserializing */
-    @SuppressWarnings ( { "FieldCanBeLocal", "UnusedDeclaration" } )
-    private final String oid;
-
     /** reference to the attributeType which is not serialized */
     private transient AttributeType attributeType;
 
@@ -85,7 +81,6 @@
         }
 
         this.attributeType = attributeType;
-        this.oid = attributeType.getOid();
     }
 
 

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java Wed Dec 12 16:49:28 2007
@@ -24,6 +24,8 @@
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 
 import javax.naming.NamingException;
+
+import java.util.List;
 import java.util.Set;
 
 
@@ -33,7 +35,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ServerEntry extends Entry<ServerAttribute>, Iterable<ServerAttribute>
+public interface ServerEntry<T extends ServerAttribute<ServerValue<?>>> extends Entry<T>, Iterable<T>
 {
     // -----------------------------------------------------------------------
     // Schema Related Methods
@@ -182,7 +184,7 @@
      * @param attributeType the type of the attribute
      * @return the attribute of the specified type
      */
-    ServerAttribute get( AttributeType attributeType );
+    T get( AttributeType attributeType );
 
 
     /**
@@ -195,13 +197,27 @@
      * @return the existing attribute of the same type if it exists; otherwise
      * <code>null</code>
      */
-    ServerAttribute put( ServerAttribute attribute ) throws NamingException;
+    T put( T attribute ) throws NamingException;
+
+    
+    /**
+     * Places non-null attributes in the attribute collection. If there is
+     * already an attribute with the same OID as any of the new attributes, 
+     * the old ones are removed from the collection and are returned by this 
+     * method. If there was no attribute with the same OID the return value 
+     * is <code>null</code>.
+     *
+     * @param attributes the attributes to be put
+     * @return the old attributes with the same OID, if exist; otherwise
+     *         <code>null</code>
+     */
+    List<T> put( T... attributes ) throws NamingException;
 
     // no value put'ters
 
-    ServerAttribute put( String upId, AttributeType attributeType ) throws NamingException;
+    T put( String upId, AttributeType attributeType ) throws NamingException;
 
-    ServerAttribute put( AttributeType attributeType ) throws NamingException;
+    T put( AttributeType attributeType ) throws NamingException;
 
 
     /**
@@ -223,7 +239,7 @@
      *         <code>null</code>
      * @throws NamingException if there are resolution issues
      */
-    ServerAttribute put( AttributeType attributeType, ServerValue<?> val ) throws NamingException;
+    T put( AttributeType attributeType, ServerValue<?> val ) throws NamingException;
 
     /**
      * Places a new attribute with the supplied attributeType and value into this
@@ -241,7 +257,7 @@
      *         <code>null</code>
      * @throws NamingException if there are failures
      */
-    ServerAttribute put( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException;
+    T put( String upId, AttributeType attributeType, ServerValue<?> val ) throws NamingException;
 
 
     /**
@@ -261,10 +277,10 @@
      *         <code>null</code>
      * @throws NamingException if there are failures
      */
-    ServerAttribute put( AttributeType attributeType, String val ) throws NamingException;
+    T put( AttributeType attributeType, String val ) throws NamingException;
 
 
-    ServerAttribute put( String upId, AttributeType attributeType, String val ) throws NamingException;
+    T put( String upId, AttributeType attributeType, String val ) throws NamingException;
 
 
     /**
@@ -284,10 +300,10 @@
      *         <code>null</code>
      * @throws NamingException if there are failures
      */
-    ServerAttribute put( AttributeType attributeType, byte[] val ) throws NamingException;
+    T put( AttributeType attributeType, byte[] val ) throws NamingException;
 
 
-    ServerAttribute put( String upId, AttributeType attributeType, byte[] val ) throws NamingException;
+    T put( String upId, AttributeType attributeType, byte[] val ) throws NamingException;
 
 
     /**
@@ -299,5 +315,27 @@
      * @return the removed attribute, if exists; otherwise <code>null</code>
      * @throws NamingException if there are failures
      */
-    ServerAttribute remove( AttributeType attributeType ) throws NamingException;
+    T remove( AttributeType attributeType ) throws NamingException;
+
+    /**
+     * Places a non-null attribute into this ServerEntry. If there an attribute
+     * of the same exists, the existing one is removed from the set and is
+     * returned by this method. If there was no attribute of the same type the
+     * return value is <code>null</code>.
+     *
+     * @param attribute the attribute to be put into this ServerEntry
+     * @return the existing attribute of the same type if it exists; otherwise
+     * <code>null</code>
+     */
+    T remove( T attribute ) throws NamingException;
+
+    /**
+     * Removes the specified attributes. The removed attributes are
+     * returned by this method. If there were no attribute the return value
+     * is <code>null</code>.
+     *
+     * @param attributes the attributes to be removed
+     * @return the removed attribute, if exists; otherwise <code>null</code>
+     */
+    List<T> remove( T... attributes ) throws NamingException;
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java Wed Dec 12 16:49:28 2007
@@ -23,10 +23,8 @@
 
 import javax.naming.directory.DirContext;
 
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.Value;
 
 /**
  * An internal implementation for a ModificationItem. The name has been
@@ -35,7 +33,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ServerModification implements Modification, Serializable
+public class ServerModification<T extends ServerAttribute<?>> implements Modification<T>, Serializable
 {
     public static final long serialVersionUID = 1L;
     
@@ -43,7 +41,7 @@
     private ModificationOperation operation;
     
     /** The attribute which contains the modification */
-    private EntryAttribute<? extends Value<?>> attribute;
+    private T attribute;
  
     
     /**
@@ -90,7 +88,7 @@
     /**
      * @return the attribute containing the modifications
      */
-    public EntryAttribute<? extends Value<?>> getAttribute()
+    public T getAttribute()
     {
         return attribute;
     }
@@ -101,7 +99,7 @@
      *
      * @param attribute The modified attribute 
      */
-    public void setAttribute( EntryAttribute<? extends Value<?>> attribute )
+    public void setAttribute( T attribute )
     {
         this.attribute = attribute;
     }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java Wed Dec 12 16:49:28 2007
@@ -24,7 +24,6 @@
 import org.apache.directory.shared.ldap.util.StringTools;
 
 import java.util.Arrays;
-import java.util.Comparator;
 
 
 /**
@@ -35,10 +34,6 @@
  */
 public class BinaryValue implements Value<byte[]>
 {
-    /** A byte array comparator instance */
-	@SuppressWarnings ( { "unchecked" } )
-    private static final Comparator<byte[]> BYTE_ARRAY_COMPARATOR = new ByteArrayComparator();
-    
     /** the wrapped binary value */
     private byte[] wrapped;
 
@@ -63,19 +58,23 @@
 
 
     /**
-     * Dumps binary in hex with label.
+     * Creates a new instance of BinaryValue copying an existing BinaryValue
      *
-     * @see Object#toString()
+     * @param value the binary value to copy
      */
-    public String toString()
+    public BinaryValue( BinaryValue value )
     {
-        return "BinaryValue : " + StringTools.dumpBytes( wrapped );
+        if ( value != null )
+        {
+            wrapped = value.getCopy();
+        }
     }
 
 
     /**
      * @see Object#hashCode()
      */
+    @Override
     public int hashCode()
     {
         return Arrays.hashCode( wrapped );
@@ -150,11 +149,7 @@
     {
         BinaryValue cloned = (BinaryValue)super.clone();
         
-        if ( wrapped != null )
-        {
-            cloned.wrapped = new byte[ wrapped.length ];
-            System.arraycopy( wrapped, 0, cloned.wrapped, 0, wrapped.length );
-        }
+        cloned.wrapped = getCopy();
         
         return cloned;
     }
@@ -163,6 +158,7 @@
     /**
      * @see Object#equals(Object)
      */
+    @Override
     public boolean equals( Object obj )
     {
         if ( this == obj )
@@ -170,30 +166,28 @@
             return true;
         }
 
-        if ( obj == null )
-        {
-            return false;
-        }
-
-        if ( obj.getClass() != this.getClass() )
+        if ( ! ( obj instanceof BinaryValue ) )
         {
             return false;
         }
 
         BinaryValue binaryValue = ( BinaryValue ) obj;
         
-        if ( ( wrapped == null ) && ( binaryValue.wrapped == null ) )
+        if ( isNull() ) 
         {
-            return true;
+            return binaryValue.isNull();
         }
-
-        //noinspection SimplifiableIfStatement
-        if ( isNull() != binaryValue.isNull() )
+        else
         {
-            return false;
+            if ( binaryValue.isNull() )
+            {
+                return false;
+            }
+            else
+            {
+                return Arrays.equals( wrapped, binaryValue.wrapped );
+            }
         }
-
-        return Arrays.equals( wrapped, binaryValue.wrapped );
     }
 
 
@@ -202,7 +196,6 @@
      *
      * @see Comparable#compareTo(Object) 
      */
-    @SuppressWarnings ( { "JavaDoc" } )
     public int compareTo( BinaryValue value )
     {
         if ( value == null )
@@ -222,6 +215,18 @@
             return -1;
         }
 
-        return BYTE_ARRAY_COMPARATOR.compare( wrapped, value.getReference() );
+        return ByteArrayComparator.INSTANCE.compare( wrapped, value.getReference() );
+    }
+
+    
+    /**
+     * Dumps binary in hex with label.
+     *
+     * @see Object#toString()
+     */
+    @Override
+    public String toString()
+    {
+        return "BinaryValue : " + StringTools.dumpBytes( wrapped );
     }
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java Wed Dec 12 16:49:28 2007
@@ -23,6 +23,7 @@
 
 import javax.naming.NamingException;
 import java.util.Iterator;
+import java.util.List;
 
 
 /**
@@ -72,6 +73,20 @@
 
 
     /**
+     * Places non-null attributes in the attribute collection. If there is
+     * already an attribute with the same OID as any of the new attributes, 
+     * the old ones are removed from the collection and are returned by this 
+     * method. If there was no attribute with the same OID the return value 
+     * is <code>null</code>.
+     *
+     * @param attributes the attributes to be put
+     * @return the old attributes with the same OID, if exist; otherwise
+     *         <code>null</code>
+     */
+    List<T> put( T... attributes ) throws NamingException;
+
+
+    /**
      * Places a non-null attribute in the attribute collection. If there is
      * already an attribute with the same OID as the new attribute, the old one
      * is removed from the collection and is returned by this method. If there
@@ -85,16 +100,27 @@
 
 
     /**
-      * Removes the specified attribute. The removed attribute is
+      * Removes the specified attributes. The removed attributes are
       * returned by this method. If there were no attribute the return value
       * is <code>null</code>.
       *
-      * @param attribute the attribute to be removed
+      * @param attributes the attributes to be removed
       * @return the removed attribute, if exists; otherwise <code>null</code>
       */
-    T remove( T attribute ) throws NamingException;
+    List<T> remove( T... attributes ) throws NamingException;
 
 
+    /**
+     * Removes the specified attribute. The removed attribute is
+     * returned by this method. If there were no attribute the return value
+     * is <code>null</code>.
+     *
+     * @param attribute the attribute to be removed
+     * @return the removed attribute, if exists; otherwise <code>null</code>
+     */
+    T remove( T attribute ) throws NamingException;
+    
+    
     /**
       * Returns the number of attributes.
       *

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java Wed Dec 12 16:49:28 2007
@@ -18,17 +18,17 @@
  */
 package org.apache.directory.shared.ldap.entry;
 
-
 import java.util.Iterator;
 
 
 /**
- * Document me!
+ * A generic interface mocking the Attribute JNDI interface. This interface
+ * will be the base interface for the ServerAttribute and ClientAttribute.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface EntryAttribute<E extends Value<?>>
+public interface EntryAttribute<T extends Value<?>>
 {
     /**
      * Adds a value to this attribute. If the new value is already present in
@@ -43,22 +43,6 @@
      * @param val a new value to be added which may be null
      * @return true if a value was added, otherwise false
      */
-    boolean add( E val );
-
-
-    /**
-     * Adds a value to this attribute. If the new value is already present in
-     * the attribute values, the method has no effect.
-     * <p>
-     * The new value is added at the end of list of values.
-     * </p>
-     * <p>
-     * This method returns true or false to indicate whether a value was added.
-     * </p>
-     *
-     * @param val a new value to be added which may be null
-     * @return true if a value was added, otherwise false
-     */
     boolean add( String val );
 
 
@@ -90,7 +74,7 @@
      * @param val the value which may be null
      * @return true if this attribute contains the value, otherwise false
      */
-    boolean contains( E val );
+    boolean contains( String val );
 
 
     /**
@@ -99,19 +83,45 @@
      * @param val the value which may be null
      * @return true if this attribute contains the value, otherwise false
      */
-    boolean contains( String val );
+    boolean contains( byte[] val );
+
+
+   /**
+      * Retrieves the number of values in this attribute.
+      *
+      * @return the number of values in this attribute, including any values
+      * wrapping a null value if there is one
+      */
+    int size();
 
 
     /**
-     * Indicates whether the specified value is one of the attribute's values.
+     * Removes a value that is equal to the given value.
+     * <p>
+     * Returns true if a value is removed. If there is no value equal to <code>
+     * val</code> this method simply returns false.
+     * </p>
      *
-     * @param val the value which may be null
-     * @return true if this attribute contains the value, otherwise false
+     * @param val the value to be removed
+     * @return true if the value is removed, otherwise false
      */
-    boolean contains( byte[] val );
+    boolean remove( byte[] val );
 
 
     /**
+     * Removes a value that is equal to the given value.
+     * <p>
+     * Returns true if a value is removed. If there is no value equal to <code>
+     * val</code> this method simply returns false.
+     * </p>
+     *
+     * @param val the value to be removed
+     * @return true if the value is removed, otherwise false
+     */
+    boolean remove( String val );
+    
+    
+    /**
      * Gets the first value of this attribute. <code>null</code> is a valid value.
      *
      * <p>
@@ -121,7 +131,7 @@
      *
      * @return a value of this attribute
      */
-    E get();
+    T get();
 
 
     /**
@@ -136,16 +146,7 @@
      *
      * @return an enumeration of all values of the attribute
      */
-    Iterator<? extends E> getAll();
-
-
-   /**
-      * Retrieves the number of values in this attribute.
-      *
-      * @return the number of values in this attribute, including any values
-      * wrapping a null value if there is one
-      */
-    int size();
+    Iterator<T> getAll();
 
 
     /**
@@ -158,31 +159,30 @@
      * @param val the value to be removed
      * @return true if the value is removed, otherwise false
      */
-    boolean remove( E val );
+    boolean remove( T val );
 
 
     /**
-     * Removes a value that is equal to the given value.
-     * <p>
-     * Returns true if a value is removed. If there is no value equal to <code>
-     * val</code> this method simply returns false.
-     * </p>
+     * Indicates whether the specified value is one of the attribute's values.
      *
-     * @param val the value to be removed
-     * @return true if the value is removed, otherwise false
+     * @param val the value which may be null
+     * @return true if this attribute contains the value, otherwise false
      */
-    boolean remove( byte[] val );
+    boolean contains( T val );
 
 
     /**
-     * Removes a value that is equal to the given value.
+     * Adds a value to this attribute. If the new value is already present in
+     * the attribute values, the method has no effect.
      * <p>
-     * Returns true if a value is removed. If there is no value equal to <code>
-     * val</code> this method simply returns false.
+     * The new value is added at the end of list of values.
+     * </p>
+     * <p>
+     * This method returns true or false to indicate whether a value was added.
      * </p>
      *
-     * @param val the value to be removed
-     * @return true if the value is removed, otherwise false
+     * @param val a new value to be added which may be null
+     * @return true if a value was added, otherwise false
      */
-    boolean remove( String val );
+    boolean add( T val );
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Modification.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Modification.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Modification.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Modification.java Wed Dec 12 16:49:28 2007
@@ -27,7 +27,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface Modification
+public interface Modification<T extends EntryAttribute<?>>
 {
     /**
      *  @return the operation
@@ -54,7 +54,7 @@
     /**
      * @return the attribute containing the modifications
      */
-    EntryAttribute<? extends Value<?>> getAttribute();
+    T getAttribute();
     
     
     /**
@@ -62,5 +62,5 @@
      *
      * @param attribute The modified attribute 
      */
-    void setAttribute( EntryAttribute<? extends Value<?>> attribute );
+    void setAttribute( T attribute );
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java?rev=603787&r1=603786&r2=603787&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java Wed Dec 12 16:49:28 2007
@@ -29,14 +29,6 @@
  */
 public interface Value<T>
 {
-//    /**
-//     * Get the wrapped value.
-//     *
-//     * @return the wrapped value, as its original type (String,byte[],URI)
-//     */
-//    T get();
-
-
     /**
      * Sets the wrapped value.
      *
@@ -50,5 +42,4 @@
      * @return <code>true</code> if the inner value is null.
      */
     boolean isNull();
-    
 }