directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r633535 [3/4] - in /directory: apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ apacheds/branches/bigbang/c...
Date Tue, 04 Mar 2008 16:35:19 GMT
Modified: directory/apacheds/branches/bigbang/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/PasswordPolicyInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/PasswordPolicyInterceptor.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/PasswordPolicyInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/PasswordPolicyInterceptor.java Tue Mar  4 08:35:12 2008
@@ -24,7 +24,6 @@
 import org.apache.directory.server.core.entry.ServerBinaryValue;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerStringValue;
-import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.server.core.interceptor.NextInterceptor;
@@ -32,6 +31,7 @@
 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -142,7 +142,7 @@
 
             if ( attr.isA( SchemaConstants.USER_PASSWORD_AT ) )
             {
-                ServerValue<?> userPassword = attr.get();
+                Value<?> userPassword = attr.get();
                 String pwd = "";
 
                 if ( userPassword != null )

Modified: directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Tue Mar  4 08:35:12 2008
@@ -28,7 +28,6 @@
 import org.apache.directory.server.core.entry.ServerAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerEntryUtils;
-import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.partition.Oid;
 import org.apache.directory.server.core.partition.impl.btree.Index;
 import org.apache.directory.server.core.partition.impl.btree.IndexAssertion;
@@ -41,6 +40,7 @@
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
@@ -1338,7 +1338,7 @@
             entry.put( entryAttrToAddTo );
         }
 
-        for ( ServerValue<?> value:mods )
+        for ( Value<?> value:mods )
         {
             entryAttrToAddTo.add( value.get() );
         }
@@ -1399,7 +1399,7 @@
         {
             Attribute entryAttr = AttributeUtils.getAttribute( entry, attrType );
             
-            for ( ServerValue<?> value:mods )
+            for ( Value<?> value:mods )
             {
                 entryAttr.remove( value.get() );
             }

Modified: directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationInterceptor.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationInterceptor.java Tue Mar  4 08:35:12 2008
@@ -36,7 +36,6 @@
 import org.apache.directory.server.core.entry.ServerAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerSearchResult;
-import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.Interceptor;
@@ -57,6 +56,7 @@
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.FilterParser;
@@ -326,7 +326,7 @@
         }
 
         // Iterate all context partitions to send all entries of them.
-        for ( ServerValue<?> namingContext:namingContextsAttr )
+        for ( Value<?> namingContext:namingContextsAttr )
         {
             // Convert attribute value to JNDI name.
             LdapDN contextName;

Modified: directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationClientContextHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationClientContextHandler.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationClientContextHandler.java (original)
+++ directory/apacheds/branches/bigbang/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationClientContextHandler.java Tue Mar  4 08:35:12 2008
@@ -45,9 +45,9 @@
 import org.apache.directory.server.core.entry.ServerAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerSearchResult;
-import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -360,7 +360,7 @@
         }
 
         // Iterate all context partitions to send all entries of them.
-        for ( ServerValue<?> namingContext:namingContextsAttr )
+        for ( Value<?> namingContext:namingContextsAttr )
         {
             // Convert attribute value to JNDI name.
             LdapDN contextName;

Copied: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java (from r631986, directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java)
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java?p2=directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java&p1=directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java&r1=631986&r2=633535&rev=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java Tue Mar  4 08:35:12 2008
@@ -19,17 +19,12 @@
  */
 package org.apache.directory.shared.ldap.entry;
 
+import javax.naming.NamingException;
 
-import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.ByteArrayComparator;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Arrays;
-
-import javax.naming.NamingException;
-
 
 /**
  * A wrapper around byte[] values in entries.
@@ -37,151 +32,127 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public abstract class AbstractBinaryValue implements Value<byte[]>
+public abstract class AbstractValue<T> implements Value<T>
 {
     /** logger for reporting errors that might not be handled properly upstream */
-    private static final Logger LOG = LoggerFactory.getLogger( AbstractBinaryValue.class );
+    private static final Logger LOG = LoggerFactory.getLogger( AbstractValue.class );
 
     
     /** the wrapped binary value */
-    private byte[] wrapped;
+    protected T wrapped;
     
+    /** the canonical representation of the wrapped value */
+    protected T normalizedValue;
+
     /** A flag set when the value has been normalized */
-    private transient boolean normalized;
+    protected boolean normalized;
 
+    /** cached results of the isValid() method call */
+    protected Boolean valid;
 
-    // -----------------------------------------------------------------------
-    // utility methods
-    // -----------------------------------------------------------------------
+    
     /**
-     * Utility method to get some logs if an assert fails
+     * Reset the value
      */
-    protected String logAssert( String message )
+    public void clear()
     {
-        LOG.error(  message );
-        return message;
+        wrapped = null;
+        normalized = false;
+        normalizedValue = null;
+        valid = null;
     }
 
     
-    /**
-     *  Check the attributeType member. It should not be null, 
-     *  and it should contains a syntax.
-     */
-    protected String checkAttributeType( AttributeType attributeType )
+    public Value<T> clone()
     {
         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;
+            return (Value<T>)super.clone();
         }
-        catch ( NamingException ne )
+        catch ( CloneNotSupportedException cnse )
         {
-            return "This AttributeType is incorrect";
+            // Do nothing
+            return null;
         }
     }
-
+    
     
     /**
-     * Creates a new instance of BinaryValue with no initial wrapped value.
+     * Gets a reference to the wrapped binary value.
+     * 
+     * Warning ! The value is not copied !!!
+     *
+     * @return a direct handle on the binary value that is wrapped
      */
-    public AbstractBinaryValue()
+    public T getReference()
     {
-        normalized = false;
+        return wrapped;
     }
 
-
+    
     /**
-     * Creates a new instance of BinaryValue with a wrapped value.
-     *
-     * @param wrapped the binary value to wrap
+     * Gets a copy of the wrapped binary value.
+     * 
+     * @return a copy of the binary value that is wrapped
      */
-    public AbstractBinaryValue( byte[] wrapped )
+    public T get()
     {
-        set( wrapped );
-        
-        normalized = false;
+        // Just call the specific Client copy method.
+        return getCopy();
     }
 
-
+    
     /**
-     * Creates a new instance of BinaryValue copying an existing BinaryValue
+     * Gets the normalized (canonical) representation for the wrapped value.
+     * If the wrapped value is null, null is returned, otherwise the normalized
+     * form is returned.  If the normalized Value is null, then the wrapped 
+     * value is returned
      *
-     * @param value the binary value to copy
+     * @return gets the normalized value
      */
-    public AbstractBinaryValue( AbstractBinaryValue value )
+    public T getNormalizedValue()
     {
-        if ( value != null )
+        if ( isNull() )
         {
-            wrapped = value.getCopy();
+            return null;
         }
-        
-        normalized = false;
-    }
 
+        if ( normalizedValue == null )
+        {
+            return getCopy();
+        }
 
-    /**
-     * @see Object#hashCode()
-     */
-    @Override
-    public int hashCode()
-    {
-        return Arrays.hashCode( wrapped );
+        return getNormalizedValueCopy();
     }
 
 
     /**
-     * Gets a copy of the binary value.
+     * Gets a reference to the the normalized (canonical) representation 
+     * for the wrapped value.
      *
-     * @return a copy of the binary value
+     * @return gets a reference to the normalized value
      */
-    public byte[] getCopy()
+    public T getNormalizedValueReference()
     {
-        if ( wrapped == null )
+        if ( isNull() )
         {
             return null;
         }
 
-        final byte[] copy = new byte[ wrapped.length ];
-        System.arraycopy( wrapped, 0, copy, 0, wrapped.length );
-        return copy;
-    }
+        if ( normalizedValue == null )
+        {
+            return wrapped;
+        }
 
-    
-    /**
-     * Gets a reference to the wrapped binary value.
-     * 
-     * Warning ! The value is not copied !!!
-     *
-     * @return a direct handle on the binary value that is wrapped
-     */
-    public byte[] getReference()
-    {
-        return wrapped;
-    }
+        return normalizedValue;
 
-    
-    /**
-     * Gets a copy of the wrapped binary value.
-     * 
-     * @return a copy of the binary value that is wrapped
-     */
-    public byte[] get()
-    {
-        return getCopy();
     }
 
     
     /**
-     * Returns <code>true</code> if the wrapper contains no value.
+     * Check if the contained value is null or not
+     * 
+     * @return <code>true</code> if the inner value is null.
      */
     public final boolean isNull()
     {
@@ -190,116 +161,80 @@
     
     
     /**
-     * Sets this value's wrapped value to a copy of the src array.
+     * Check if the Valid flag is set or not. This flag is set by a call
+     * to the isValid( SyntaxChecker ) method for client values. It is overridden
+     * for server values.
+     * 
+     * if the flag is not set, returns <code>false</code>
      *
-     * @param wrapped the byte array to use as the wrapped value
+     * @see ServerValue#isValid()
      */
-    public void set( byte[] wrapped )
+    public boolean isValid()
     {
-        if ( wrapped != null )
-        {
-            this.wrapped = new byte[ wrapped.length ];
-            System.arraycopy( wrapped, 0, this.wrapped, 0, wrapped.length );
-        }
-        else
+        if ( valid != null )
         {
-            this.wrapped = null;
+            return valid;
         }
+
+        return false;
     }
 
 
     /**
-     * @see Object#equals(Object)
+     * Uses the syntaxChecker associated with the attributeType to check if the
+     * value is valid.  Repeated calls to this method do not attempt to re-check
+     * the syntax of the wrapped value every time if the wrapped value does not
+     * change. Syntax checks only result on the first check, and when the wrapped
+     * value changes.
+     *
+     * @see ServerValue#isValid()
      */
-    @Override
-    public boolean equals( Object obj )
+    public final boolean isValid( SyntaxChecker syntaxChecker ) throws NamingException
     {
-        if ( this == obj )
+        if ( valid != null )
         {
-            return true;
+            return valid;
         }
-
-        if ( ! ( obj instanceof AbstractBinaryValue ) )
-        {
-            return false;
-        }
-
-        AbstractBinaryValue binaryValue = ( AbstractBinaryValue ) obj;
         
-        if ( isNull() ) 
+        if ( syntaxChecker == null )
         {
-            return binaryValue.isNull();
-        }
-        else
-        {
-            if ( binaryValue.isNull() )
-            {
-                return false;
-            }
-            else
-            {
-                return Arrays.equals( wrapped, binaryValue.wrapped );
-            }
+            String message = "Cannot validate " + toString() + " with a null SyntaxChecker";
+            LOG.error( message );
+            throw new NamingException( message );
         }
+        
+        valid = syntaxChecker.isValidSyntax( getReference() );
+        return valid;
     }
 
 
     /**
-     * Compare with the current BinaryValue 
-     *
-     * @see Comparable#compareTo(Object) 
+     * Normalize the value. In order to use this method, the Value
+     * must be schema aware.
+     * 
+     * @exception NamingException If the value cannot be normalized
      */
-    public int compareTo( AbstractBinaryValue value )
+    public void normalize() throws NamingException
     {
-        if ( value == null )
-        {
-            if ( wrapped == null )
-            {
-                return 0;
-            }
-            else
-            {
-                return 1;
-            }
-        }
-
-        if ( wrapped == null )
-        {
-            return -1;
-        }
-
-        return ByteArrayComparator.INSTANCE.compare( wrapped, value.getReference() );
+        normalized = true;
+        normalizedValue = wrapped;
     }
 
-    
+
     /**
-     * Makes a deep copy of the BinaryValue.
+     * Sets this value's wrapped value to a copy of the src array.
      *
-     * @return a deep copy of the Value.
+     * @param wrapped the byte array to use as the wrapped value
      */
-    public AbstractBinaryValue clone()
-    {
-        try
-        {
-            AbstractBinaryValue clone = (AbstractBinaryValue)super.clone();
-            
-            clone.wrapped = getCopy();
-            
-            return clone;
-        }
-        catch ( CloneNotSupportedException cnse )
-        {
-            return null;
-        }
-    }
-    
+    public abstract void set( T wrapped );
+
     
     /**
      * Tells if the value has already be normalized or not.
      *
      * @return <code>true</code> if the value has already been normalized.
      */
-    public boolean isNormalized()
+    public final boolean isNormalized()
     {
         return normalized;
     }
@@ -310,35 +245,8 @@
      * 
      * @param the value : true or false
      */
-    public void setNormalized( boolean normalized )
+    public final void setNormalized( boolean normalized )
     {
         this.normalized = normalized;
-    }
-
-    
-    /**
-     * Dumps binary in hex with label.
-     *
-     * @see Object#toString()
-     */
-    @Override
-    public String toString()
-    {
-        if ( wrapped == null )
-        {
-            return "null";
-        }
-        else if ( wrapped.length > 16 )
-        {
-            byte[] copy = new byte[16];
-            
-            System.arraycopy( wrapped, 0, copy, 0, 16 );
-            
-            return "'" + StringTools.dumpBytes( copy ) + "...'";
-        }
-        else
-        {
-            return "'" + StringTools.dumpBytes( wrapped ) + "'";
-        }
     }
 }

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=633535&r1=633534&r2=633535&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 Tue Mar  4 08:35:12 2008
@@ -21,6 +21,11 @@
 
 import java.io.Serializable;
 
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+
 
 /**
  * A interface for wrapping attribute values stored into an EntryAttribute. These
@@ -29,14 +34,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface Value<T> extends Cloneable, Serializable
+public interface Value<T> extends Cloneable, Serializable, Comparable<Value<T>>
 {
-    /**
-     * Sets the wrapped value.
-     *
-     * @param wrapped the value to set. Should be either a String, URI, or a byte[]
-     */
-    void set( T wrapped );
+    
+    Value<T> clone();
+    
     
     /**
      * Check if the contained value is null or not
@@ -47,9 +49,126 @@
     
     
     /**
+     * Sets the wrapped value.
+     *
+     * @param wrapped the value to set. Should be either a String, URI, or a byte[]
+     */
+    void set( T wrapped );
+    
+
+    /**
      * Get the stored value.
      *
      * @return The stored value
      */
     T get();
+    
+    
+    /**
+     * Get a reference on the stored value.
+     *
+     * @return A reference on the stored value.
+     */
+    T getReference();
+    
+    
+    /**
+     * Get a copy of the stored value.
+     *
+     * @return A copy of the stored value.
+     */
+    T getCopy();
+    
+    
+    /**
+     * Reset the value
+     */
+    void clear();
+    
+    
+    /**
+     * Tells if the value has already be normalized or not.
+     *
+     * @return <code>true</code> if the value has already been normalized.
+     */
+    boolean isNormalized();
+    
+    
+    /**
+     * Tells if the value is valid. The value must have already been
+     * validated at least once through a call to isValid( SyntaxChecker ).  
+     * 
+     * @return <code>true</code> if the value is valid
+     */
+    boolean isValid();
+
+    
+    /**
+     * Tells if the value is valid wrt a Syntax checker
+     * 
+     * @param SyntaxChecker the Syntax checker to use to validate the value
+     * @return <code>true</code> if the value is valid
+     * @exception NamingException if the value cannot be validated
+     */
+    boolean isValid( SyntaxChecker checker ) throws NamingException;
+
+    
+    /**
+     * Set the normalized flag.
+     * 
+     * @param the value : true or false
+     */
+    void setNormalized( boolean normalized );
+
+    
+    /**
+     * Gets the normalized (canonical) representation for the wrapped string.
+     * If the wrapped String is null, null is returned, otherwise the normalized
+     * form is returned.  If 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
+     */
+    T getNormalizedValue();
+    
+    
+    /**
+     * Gets a reference to the the normalized (canonical) representation 
+     * for the wrapped value.
+     *
+     * @return gets a reference to the normalized value
+     */
+    T getNormalizedValueReference();
+
+    
+    /**
+     * Gets a copy of the the normalized (canonical) representation 
+     * for the wrapped value.
+     *
+     * @return gets a copy of the normalized value
+     */
+    T getNormalizedValueCopy();
+
+    
+    /**
+     * Normalize the value. In order to use this method, the Value
+     * must be schema aware.
+     * 
+     * @exception NamingException If the value cannot be normalized
+     */
+    void normalize() throws NamingException;
+
+    
+    /**
+     * Normalize the value. For a client String value, applies the given normalizer.
+     * 
+     * It supposes that the client has access to the schema in order to select the
+     * appropriate normalizer.
+     * 
+     * @param Normalizer The normalizer to apply to the value
+     * @exception NamingException If the value cannot be normalized
+     */
+    void normalize( Normalizer normalizer ) throws NamingException;
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java Tue Mar  4 08:35:12 2008
@@ -20,6 +20,7 @@
 
 
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,7 +46,7 @@
     private static final Logger LOG = LoggerFactory.getLogger( AbstractClientAttribute.class );
 
     /** The set of contained values */
-    protected List<ClientValue<?>> values = new ArrayList<ClientValue<?>>();
+    protected List<Value<?>> values = new ArrayList<Value<?>>();
     
     /** The User provided ID */
     protected String upId;
@@ -143,7 +144,7 @@
      */
     public boolean isValid() throws NamingException
     {
-        for ( ClientValue<?> value : values )
+        for ( Value<?> value : values )
         {
             if ( ! value.isValid() )
             {
@@ -158,11 +159,11 @@
     /**
      * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public int add( ClientValue<?>... vals ) throws InvalidAttributeValueException, NamingException
+    public int add( Value<?>... vals ) throws InvalidAttributeValueException, NamingException
     {
         int nbAdded = 0;
         
-        for ( ClientValue<?> val:vals )
+        for ( Value<?> val:vals )
         {
             values.add( val );
             nbAdded ++;
@@ -175,7 +176,7 @@
     /**
      * @see EntryAttribute#put(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public int put( ClientValue<?>... vals ) throws InvalidAttributeValueException, NamingException
+    public int put( Value<?>... vals ) throws InvalidAttributeValueException, NamingException
     {
         values.clear();
         return add( vals );
@@ -282,9 +283,9 @@
             // Copy the values. The attributeType is immutable.
             if ( ( values != null ) && ( values.size() != 0 ) )
             {
-                clone.values = new ArrayList<ClientValue<?>>( values.size() );
+                clone.values = new ArrayList<Value<?>>( values.size() );
                 
-                for ( ClientValue<?> value:values )
+                for ( Value<?> value:values )
                 {
                     clone.values.add( value.clone() );
                 }
@@ -303,7 +304,7 @@
     /**
      * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value)
      */
-    public boolean contains( ClientValue<?> val )
+    public boolean contains( Value<?> val )
     {
         return values.contains( val );
     }
@@ -312,11 +313,11 @@
     /**
      * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public boolean contains( ClientValue<?>... vals )
+    public boolean contains( Value<?>... vals )
     {
         // Iterate through all the values, and quit if we 
         // don't find one in the values
-        for ( ClientValue<?> val:vals )
+        for ( Value<?> val:vals )
         {
             if ( !values.contains( val ) )
             {
@@ -397,7 +398,7 @@
      * 
      *  @return The first value for this attribute.
      */
-    public ClientValue<?> get()
+    public Value<?> get()
     {
         if ( values.isEmpty() )
         {
@@ -413,7 +414,7 @@
      * 
      * @return An iterator over the values stored into the attribute
      */
-    public Iterator<ClientValue<?>> getAll()
+    public Iterator<Value<?>> getAll()
     {
         return iterator();
     }
@@ -434,7 +435,7 @@
     /**
      * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value)
      */
-    public boolean remove( ClientValue<?> val )
+    public boolean remove( Value<?> val )
     {
         return values.remove( val );
     }
@@ -443,13 +444,13 @@
     /**
      * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public boolean remove( ClientValue<?>... vals )
+    public boolean remove( Value<?>... vals )
     {
         boolean removed = false;
         
         // Loop through all the values to remove. If one of
         // them is not present, the method will return false.
-        for ( ClientValue<?> val:vals )
+        for ( Value<?> val:vals )
         {
             removed &= values.remove( val );
         }
@@ -517,7 +518,7 @@
      * 
      * @return an iterator over the stored values.
      */
-    public Iterator<ClientValue<?>> iterator()
+    public Iterator<Value<?>> iterator()
     {
         return values.iterator();
     }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java Tue Mar  4 08:35:12 2008
@@ -20,6 +20,7 @@
 
 
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
 
 import javax.naming.NamingException;
 
@@ -31,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ClientAttribute extends EntryAttribute<ClientValue<?>>
+public interface ClientAttribute extends EntryAttribute<Value<?>>
 {
     /**
      * Get's the user provided identifier for this entry.  This is the value

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java Tue Mar  4 08:35:12 2008
@@ -20,7 +20,11 @@
 
 
 import org.apache.directory.shared.ldap.NotImplementedException;
-import org.apache.directory.shared.ldap.entry.AbstractBinaryValue;
+import org.apache.directory.shared.ldap.entry.AbstractValue;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.schema.ByteArrayComparator;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,7 +41,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ClientBinaryValue extends AbstractBinaryValue implements ClientValue<byte[]>
+public class ClientBinaryValue extends AbstractValue<byte[]>
 {
     /** Used for serialization */
     public static final long serialVersionUID = 2L;
@@ -45,12 +49,6 @@
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ClientBinaryValue.class );
 
-    /** the canonical representation of the wrapped binary value */
-    private transient byte[] normalizedValue;
-
-    /** cached results of the isValid() method call */
-    private transient Boolean valid;
-
 
     /**
      * Creates a ServerBinaryValue without an initial wrapped value.
@@ -59,6 +57,10 @@
      */
     public ClientBinaryValue()
     {
+        wrapped = null;
+        normalized = false;
+        valid = null;
+        normalizedValue = null;
     }
 
 
@@ -70,16 +72,40 @@
      */
     public ClientBinaryValue( byte[] wrapped )
     {
-        super.set( wrapped );
+        if ( wrapped != null )
+        {
+            this.wrapped = new byte[ wrapped.length ];
+            System.arraycopy( wrapped, 0, this.wrapped, 0, wrapped.length );
+        }
+        else
+        {
+            wrapped = null;
+        }
+        
+        normalized = false;
+        valid = null;
+        normalizedValue = null;
     }
 
 
     // -----------------------------------------------------------------------
     // Value<String> Methods
     // -----------------------------------------------------------------------
+    /**
+     * Reset the value
+     */
+    public void clear()
+    {
+        wrapped = null;
+        normalized = false;
+        normalizedValue = null;
+        valid = null;
+    }
 
 
-    /**
+
+
+    /*
      * 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
@@ -102,42 +128,24 @@
         }
 
         normalizedValue = null;
+        normalized = false;
         valid = null;
-        super.set( wrapped );
-    }
-
-
-    // -----------------------------------------------------------------------
-    // ServerValue<String> Methods
-    // -----------------------------------------------------------------------
-
-
-    /**
-     * Gets the normalized (cannonical) representation for the wrapped string.
-     * If the wrapped String 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 a reference to the normalized version of the wrapped value
-     * @throws NamingException with failures to normalize
-     */
-    public byte[] getNormalizedReference() throws NamingException
-    {
-        if ( isNull() )
+        
+        if ( wrapped == null )
         {
-            return null;
+            this.wrapped = wrapped;
         }
-
-        if ( normalizedValue == null )
+        else
         {
+            this.wrapped = new byte[ wrapped.length ];
+            System.arraycopy( wrapped, 0, this.wrapped, 0, wrapped.length );
         }
-
-        return normalizedValue;
     }
 
 
+    // -----------------------------------------------------------------------
+    // ServerValue<String> Methods
+    // -----------------------------------------------------------------------
     /**
      * Gets a direct reference to the normalized representation for the
      * wrapped value of this ServerValue wrapper. Implementations will most
@@ -147,11 +155,11 @@
      * @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 ( normalizedValue == null )
         {
-            getNormalizedReference();
+            return null;
         }
 
         byte[] copy = new byte[ normalizedValue.length ];
@@ -161,32 +169,38 @@
 
 
     /**
-     * Uses the syntaxChecker associated with the attributeType to check if the
-     * value is valid.  Repeated calls to this method do not attempt to re-check
-     * the syntax of the wrapped value every time if the wrapped value does not
-     * change. Syntax checks only result on the first check, and when the wrapped
-     * value changes.
-     *
-     * @see ServerValue#isValid()
+     * Normalize the value. For a client String value, applies the given normalizer.
+     * 
+     * It supposes that the client has access to the schema in order to select the
+     * appropriate normalizer.
+     * 
+     * @param Normalizer The normalizer to apply to the value
+     * @exception NamingException If the value cannot be normalized
      */
-    public final boolean isValid() throws NamingException
+    public final void normalize( Normalizer normalizer ) throws NamingException
     {
-        if ( valid != null )
+        if ( normalizer != null )
         {
-            return valid;
+            if ( wrapped == null )
+            {
+                normalized = true;
+            }
+            else
+            {
+                normalizedValue = (byte[])normalizer.normalize( wrapped );
+                normalized = true;
+            }
         }
-
-        return valid;
     }
 
-
+    
     /**
      *
      * @see ServerValue#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( ClientValue<byte[]> value )
+    public int compareTo( Value<byte[]> value )
     {
         if ( isNull() )
         {
@@ -210,8 +224,10 @@
         if ( value instanceof ClientBinaryValue )
         {
             ClientBinaryValue binaryValue = ( ClientBinaryValue ) value;
-        }
 
+            return ByteArrayComparator.INSTANCE.compare( getNormalizedValue(), binaryValue.getNormalizedValue() );
+        }
+        
         throw new NotImplementedException( "I don't really know how to compare anything other " +
                 "than ServerBinaryValues at this point in time." );
     }
@@ -236,16 +252,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() );
     }
 
 
@@ -263,7 +270,7 @@
         {
             return true;
         }
-
+        
         if ( ! ( obj instanceof ClientBinaryValue ) )
         {
             return false;
@@ -271,31 +278,13 @@
 
         ClientBinaryValue other = ( ClientBinaryValue ) obj;
         
-        if ( isNull() && other.isNull() )
-        {
-            return true;
-        }
-
-        if ( isNull() != other.isNull() )
+        if ( isNull() )
         {
-            return false;
+            return other.isNull();
         }
 
         // now unlike regular values we have to compare the normalized values
-        try
-        {
-            return Arrays.equals( getNormalizedReference(), other.getNormalizedReference() );
-        }
-        catch ( NamingException e )
-        {
-            // 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 );
-
-            // recover by comparing non-normalized values
-            return Arrays.equals( getReference(), other.getReference() );
-        }
+        return Arrays.equals( getNormalizedValueReference(), other.getNormalizedValueReference() );
     }
 
 
@@ -315,6 +304,58 @@
             System.arraycopy( normalizedValue, 0, clone.normalizedValue, 0, normalizedValue.length );
         }
         
+        if ( wrapped != null )
+        {
+            clone.wrapped = new byte[ wrapped.length ];
+            System.arraycopy( wrapped, 0, clone.wrapped, 0, wrapped.length );
+        }
+        
         return clone;
+    }
+
+
+    /**
+     * Gets a copy of the binary value.
+     *
+     * @return a copy of the binary value
+     */
+    public byte[] getCopy()
+    {
+        if ( wrapped == null )
+        {
+            return null;
+        }
+
+        
+        final byte[] copy = new byte[ wrapped.length ];
+        System.arraycopy( wrapped, 0, copy, 0, wrapped.length );
+        return copy;
+    }
+
+
+    /**
+     * Dumps binary in hex with label.
+     *
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        if ( wrapped == null )
+        {
+            return "null";
+        }
+        else if ( wrapped.length > 16 )
+        {
+            // Just dump the first 16 bytes...
+            byte[] copy = new byte[16];
+            
+            System.arraycopy( wrapped, 0, copy, 0, 16 );
+            
+            return "'" + StringTools.dumpBytes( copy ) + "...'";
+        }
+        else
+        {
+            return "'" + StringTools.dumpBytes( wrapped ) + "'";
+        }
     }
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java Tue Mar  4 08:35:12 2008
@@ -20,7 +20,9 @@
 
 
 import org.apache.directory.shared.ldap.NotImplementedException;
-import org.apache.directory.shared.ldap.entry.AbstractStringValue;
+import org.apache.directory.shared.ldap.entry.AbstractValue;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,26 +38,26 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ClientStringValue extends AbstractStringValue implements ClientValue<String>
+public class ClientStringValue extends AbstractValue<String>
 {
     /** Used for serialization */
     public static final long serialVersionUID = 2L;
     
+    
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ClientStringValue.class );
 
-    /** the canonical representation of the wrapped String value */
-    private transient String normalizedValue;
-
-    /** cached results of the isValid() method call */
-    private transient Boolean valid;
-
-
+    
+    // -----------------------------------------------------------------------
+    // Constructors
+    // -----------------------------------------------------------------------
     /**
      * Creates a ServerStringValue without an initial wrapped value.
      */
     public ClientStringValue()
     {
+        normalized = false;
+        valid = null;
     }
 
 
@@ -66,16 +68,40 @@
      */
     public ClientStringValue( String wrapped )
     {
-        super.set( wrapped );
+        this.wrapped = wrapped;
+        normalized = false;
+        valid = null;
     }
 
 
     // -----------------------------------------------------------------------
     // Value<String> Methods
     // -----------------------------------------------------------------------
+    /**
+     * Get the stored value.
+     *
+     * @return The stored value
+     */
+    public String get()
+    {
+        return wrapped;
+    }
 
 
     /**
+     * Get a copy of the stored value.
+     *
+     * @return A copy of the stored value.
+     */
+    public String getCopy()
+    {
+        // The String is immutable, we can safely return the internal
+        // object without copying it.
+        return wrapped;
+    }
+    
+    
+    /**
      * Sets the wrapped String 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
@@ -87,34 +113,29 @@
     {
         // Why should we invalidate the normalized value if it's we're setting the
         // wrapper to it's current value?
-        if ( wrapped.equals( get() ) )
+        if ( ( wrapped != null ) && wrapped.equals( get() ) )
         {
             return;
         }
 
         normalizedValue = null;
+        normalized = false;
         valid = null;
-        super.set( wrapped );
+        this.wrapped = wrapped;
     }
 
 
-    // -----------------------------------------------------------------------
-    // ServerValue<String> Methods
-    // -----------------------------------------------------------------------
-
-
     /**
-     * Gets the normalized (cannonical) representation for the wrapped string.
+     * Gets the normalized (canonical) representation for the wrapped string.
      * If the wrapped String is null, null is returned, otherwise the normalized
-     * form is returned.  If no the normalizedValue is null, then this method
+     * form is returned.  If 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 String getNormalized() throws NamingException
+    public String getNormalizedValue()
     {
         if ( isNull() )
         {
@@ -123,6 +144,7 @@
 
         if ( normalizedValue == null )
         {
+            return wrapped;
         }
 
         return normalizedValue;
@@ -130,31 +152,45 @@
 
 
     /**
-     * Uses the syntaxChecker associated with the attributeType to check if the
-     * value is valid.  Repeated calls to this method do not attempt to re-check
-     * the syntax of the wrapped value every time if the wrapped value does not
-     * change. Syntax checks only result on the first check, and when the wrapped
-     * value changes.
+     * Gets a copy of the the normalized (canonical) representation 
+     * for the wrapped value.
      *
-     * @see ServerValue#isValid()
+     * @return gets a copy of the normalized value
+     */
+    public String getNormalizedValueCopy()
+    {
+        return getNormalizedValue();
+    }
+
+
+    /**
+     * Normalize the value. For a client String value, applies the given normalizer.
+     * 
+     * It supposes that the client has access to the schema in order to select the
+     * appropriate normalizer.
+     * 
+     * @param Normalizer The normalizer to apply to the value
+     * @exception NamingException If the value cannot be normalized
      */
-    public final boolean isValid() throws NamingException
+    public final void normalize( Normalizer normalizer ) throws NamingException
     {
-        if ( valid != null )
+        if ( normalizer != null )
         {
-            return valid;
+            normalizedValue = (String)normalizer.normalize( wrapped );
+            normalized = true;
         }
-
-        return valid;
     }
 
-
+    
+    // -----------------------------------------------------------------------
+    // Comparable<String> Methods
+    // -----------------------------------------------------------------------
     /**
      * @see ServerValue#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( ClientValue<String> value )
+    public int compareTo( Value<String> value )
     {
         if ( isNull() )
         {
@@ -175,17 +211,35 @@
         if ( value instanceof ClientStringValue )
         {
             ClientStringValue stringValue = ( ClientStringValue ) value;
+            
+            return getNormalizedValue().compareTo( stringValue.getNormalizedValue() );
+        }
+        else 
+        {
+            String message = "Cannot compare " + toString() + " with the unknown value " + value.getClass();
+            LOG.error( message );
+            throw new NotImplementedException( message );
         }
-
-        throw new NotImplementedException( "I don't know what to do if value is not a ServerStringValue" );
     }
 
 
     // -----------------------------------------------------------------------
-    // Object Methods
+    // Cloneable methods
     // -----------------------------------------------------------------------
+    /**
+     * Get a clone of the Client Value
+     * 
+     * @return a copy of the current value
+     */
+    public ClientStringValue clone()
+    {
+        return (ClientStringValue)super.clone();
+    }
 
 
+    // -----------------------------------------------------------------------
+    // Object Methods
+    // -----------------------------------------------------------------------
     /**
      * @see Object#hashCode()
      * @throws IllegalStateException on failures to extract the comparator, or the
@@ -200,26 +254,16 @@
             return 0;
         }
 
-        try
-        {
-            return getNormalized().hashCode();
-        }
-        catch ( NamingException e )
-        {
-            String msg = "Failed to normalize \"" + get() + "\" while trying to get hashCode()";
-            LOG.error( msg, e );
-            throw new IllegalStateException( msg, e );
-        }
+        // If the normalized value is null, will default to wrapped
+        // which cannot be null at this pont.
+        return getNormalizedValue().hashCode();
     }
 
 
     /**
-     * Checks to see if this ServerStringValue equals the supplied object.
-     *
-     * This equals implementation overrides the StringValue implementation which
-     * is not schema aware.
-     * @throws IllegalStateException on failures to extract the comparator, or the
-     * normalizers needed to perform the required comparisons based on the schema
+     * @see Object#equals(Object)
+     * 
+     * Two ClientStringValue are equals if their normalized values are equal
      */
     public boolean equals( Object obj )
     {
@@ -235,46 +279,21 @@
 
         ClientStringValue other = ( ClientStringValue ) obj;
         
-        if ( isNull() && other.isNull() )
-        {
-            return true;
-        }
-
-        if ( isNull() != other.isNull() )
+        if ( this.isNull() )
         {
-            return false;
-        }
-
-        // now unlike regular values we have to compare the normalized values
-        try
-        {
-            return getNormalized().equals( other.getNormalized() );
-        }
-        catch ( NamingException e )
-        {
-            String msg = "Failed to normalize while testing for equality on String values: \"";
-            msg += get() + "\"" + " and \"" + other.get() + "\"" ;
-            LOG.error( msg, e );
-            throw new IllegalStateException( msg, e );
+            return other.isNull();
         }
+        
+        // Test the normalized values
+        return this.getNormalizedValue().equals( other.getNormalizedValue() );
     }
-
-
-    // -----------------------------------------------------------------------
-    // Private Helper Methods (might be put into abstract base class)
-    // -----------------------------------------------------------------------
+    
+    
     /**
-     * @return a copy of the current value
+     * @see Object#toString()
      */
-    public ClientStringValue clone()
+    public String toString()
     {
-        try
-        {
-            return (ClientStringValue)super.clone();
-        }
-        catch ( CloneNotSupportedException cnse )
-        {
-            return null;
-        }
+        return "'" + wrapped + "'";
     }
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java Tue Mar  4 08:35:12 2008
@@ -20,6 +20,7 @@
 
 
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -76,7 +77,7 @@
      * @param vals an initial set of values for this attribute
      * @throws NamingException if there are problems creating the new attribute
      */
-    public DefaultClientAttribute( ClientValue<?>... vals ) throws NamingException
+    public DefaultClientAttribute( Value<?>... vals ) throws NamingException
     {
         this( null, vals );
     }
@@ -96,7 +97,7 @@
      * @param vals an initial set of values for this attribute
      * @throws NamingException if there are problems creating the new attribute
      */
-    public DefaultClientAttribute( String upId, ClientValue<?>... vals ) throws NamingException
+    public DefaultClientAttribute( String upId, Value<?>... vals ) throws NamingException
     {
         // The value can be null, this is a valid value.
         if ( vals[0] == null )
@@ -105,7 +106,7 @@
         }
         else
         {
-            for ( ClientValue<?> val:vals )
+            for ( Value<?> val:vals )
             {
                 if ( val instanceof ClientStringValue )
                 {
@@ -205,7 +206,7 @@
      */
     public boolean isValid() throws NamingException
     {
-        for ( ClientValue<?> value : values )
+        for ( Value<?> value : values )
         {
             if ( ! value.isValid() )
             {
@@ -220,11 +221,11 @@
     /**
      * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value)
      */
-    public boolean add( ClientValue<?> val ) throws InvalidAttributeValueException, NamingException
+    public boolean add( Value<?> val ) throws InvalidAttributeValueException, NamingException
     {
         if ( val == null )
         {
-            ClientValue<String> nullSV = new ClientStringValue( (String)null );
+            Value<String> nullSV = new ClientStringValue( (String)null );
             
             if ( values.contains( nullSV ) )
             {
@@ -249,11 +250,11 @@
     /**
      * @see EntryAttribute#add(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public int add( ClientValue<?>... vals ) throws InvalidAttributeValueException, NamingException
+    public int add( Value<?>... vals ) throws InvalidAttributeValueException, NamingException
     {
         int nbAdded = 0;
         
-        for ( ClientValue<?> val:vals )
+        for ( Value<?> val:vals )
         {
             if ( add( val ) )
             {
@@ -334,7 +335,7 @@
     /**
      * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value)
      */
-    public boolean contains( ClientValue<?> val )
+    public boolean contains( Value<?> val )
     {
         return values.contains( val );
     }
@@ -343,11 +344,11 @@
     /**
      * @see EntryAttribute#contains(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public boolean contains( ClientValue<?>... vals )
+    public boolean contains( Value<?>... vals )
     {
         // Iterate through all the values, and quit if we 
         // don't find one in the values
-        for ( ClientValue<?> val:vals )
+        for ( Value<?> val:vals )
         {
             if ( !values.contains( val ) )
             {
@@ -486,7 +487,7 @@
      * 
      *  @return The first value for this attribute.
      */
-    public ClientValue<?> get()
+    public Value<?> get()
     {
         if ( values.isEmpty() )
         {
@@ -502,7 +503,7 @@
      * 
      * @return An iterator over the values stored into the attribute
      */
-    public Iterator<ClientValue<?>> getAll()
+    public Iterator<Value<?>> getAll()
     {
         return iterator();
     }
@@ -523,7 +524,7 @@
     /**
      * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value)
      */
-    public boolean remove( ClientValue<?> val )
+    public boolean remove( Value<?> val )
     {
         return values.remove( val );
     }
@@ -532,13 +533,13 @@
     /**
      * @see EntryAttribute#remove(org.apache.directory.shared.ldap.entry.Value...)
      */
-    public boolean remove( ClientValue<?>... vals )
+    public boolean remove( Value<?>... vals )
     {
         boolean removed = false;
         
         // Loop through all the values to remove. If one of
         // them is not present, the method will return false.
-        for ( ClientValue<?> val:vals )
+        for ( Value<?> val:vals )
         {
             removed &= values.remove( val );
         }
@@ -606,7 +607,7 @@
      * 
      * @return an iterator over the stored values.
      */
-    public Iterator<ClientValue<?>> iterator()
+    public Iterator<Value<?>> iterator()
     {
         return values.iterator();
     }
@@ -633,7 +634,7 @@
         
         if ( ( values != null ) && ( values.size() != 0 ) )
         {
-            for ( ClientValue<?> value:values )
+            for ( Value<?> value:values )
             {
                 sb.append( "    " ).append( upId ).append( ": " ).append( value ).append( '\n' );
             }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ComparableComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ComparableComparator.java?rev=633535&r1=633534&r2=633535&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ComparableComparator.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ComparableComparator.java Tue Mar  4 08:35:12 2008
@@ -48,14 +48,37 @@
      */
     public int compare( Object o1, Object o2 )
     {
+        if ( ( o1 == null ) && ( o2 == null ) )
+        {
+            return 0;
+        }
+        
         if ( o1 instanceof Comparable )
         {
-            return ( ( Comparable ) o1 ).compareTo( o2 );
+            if ( o2 == null )
+            {
+                return -1;
+            }
+            else
+            {
+                return ( ( Comparable ) o1 ).compareTo( o2 );
+            }
         }
 
-        if ( o2 instanceof Comparable )
+        if ( o2 == null )
+        {
+            return 1;
+        }
+        else if ( o2 instanceof Comparable )
         {
-            return -( ( Comparable ) o2 ).compareTo( o1 );
+            if ( o1 == null )
+            {
+                return -1;
+            }
+            else
+            {
+                return -( ( Comparable ) o2 ).compareTo( o1 );
+            }
         }
 
         // before https://issues.apache.org/jira/browse/DIRSERVER-928 it was

Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java?rev=633535&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java Tue Mar  4 08:35:12 2008
@@ -0,0 +1,639 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.shared.ldap.entry.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+
+import javax.naming.NamingException;
+import javax.naming.directory.InvalidAttributeValueException;
+import javax.print.DocFlavor.BYTE_ARRAY;
+
+import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.syntax.Ia5StringSyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntax.OctetStringSyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * 
+ * Test the ClientBinaryValue class
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ClientBinaryValueTest
+{
+    private static final byte[] BYTES1 = new byte[]{0x01, 0x02, 0x03, 0x04};
+    private static final byte[] BYTES2 = new byte[]{(byte)0x81, (byte)0x82, (byte)0x83, (byte)0x84};
+    private static final byte[] INVALID_BYTES = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05};
+    private static final byte[] BYTES_MOD = new byte[]{0x11, 0x02, 0x03, 0x04};
+    
+    private static final Normalizer BINARY_NORMALIZER = new Normalizer()
+    {
+        public static final long serialVersionUID = 1L;
+        
+        public Object normalize( Object value ) throws NamingException
+        {
+            if ( value instanceof byte[] )
+            {
+                byte[] val = (byte[])value;
+                // each byte will be changed to be > 0, and spaces will be trimmed
+                byte[] newVal = new byte[ val.length ];
+                int i = 0;
+                
+                for ( byte b:val )
+                {
+                    newVal[i++] = (byte)(b & 0x007F); 
+                }
+                
+                return StringTools.trim( newVal );
+            }
+
+            throw new IllegalStateException( "expected byte[] to normalize" );
+        }
+    };
+    
+    private static final SyntaxChecker BINARY_CHECKER = new SyntaxChecker()
+    {
+        public String getSyntaxOid()
+        {
+            return "1.1.1";
+        }
+        public boolean isValidSyntax( Object value )
+        {
+            if ( value == null )
+            {
+                return true;
+            }
+            
+            return ((byte[])value).length < 5 ;
+        }
+
+        public void assertSyntax( Object value ) throws NamingException
+        {
+            if ( ! isValidSyntax( value ) )
+            {
+                throw new InvalidAttributeValueException();
+            }
+        }
+    };
+
+    @Test
+    public void testHashCode()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        assertEquals( 0, cbv.hashCode() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        int h = Arrays.hashCode( StringTools.EMPTY_BYTES );
+        assertEquals( h, cbv.hashCode() );
+        
+        h = Arrays.hashCode( BYTES1 );
+        cbv.set( BYTES1 );
+        assertEquals( h, cbv.hashCode() );
+    }
+
+
+    @Test
+    public void testClear() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue( BYTES2 );
+        cbv.normalize( BINARY_NORMALIZER );
+        cbv.isValid( BINARY_CHECKER );
+        
+        cbv.clear();
+        assertTrue( cbv.isNull() );
+        assertFalse( cbv.isNormalized() );
+        assertFalse( cbv.isValid() );
+        assertNull( cbv.get() );
+        assertNull( cbv.getCopy() );
+        assertNull( cbv.getReference() );
+        assertNull( cbv.getNormalizedValue() );
+        assertNull( cbv.getNormalizedValueCopy() );
+        assertNull( cbv.getNormalizedValueReference() );
+    }
+
+
+    @Test
+    public void testClientBinaryValueNull() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue( null );
+        
+        assertEquals( null, cbv.get() );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertTrue( cbv.isNull() );
+        assertNull( cbv.getNormalizedValue() );
+    }
+
+
+    @Test
+    public void testClientBinaryValueEmpty() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue( StringTools.EMPTY_BYTES );
+        
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.get() ) );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getCopy() ) );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getReference() ) );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertFalse( cbv.isNull() );
+        assertNotNull( cbv.getNormalizedValue() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getNormalizedValue() ) );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getNormalizedValueReference() ) );
+    }
+
+
+    @Test
+    public void testClientBinaryValue() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue( BYTES1 );
+        
+        assertTrue( Arrays.equals( BYTES1, cbv.get() ) );
+        assertTrue( Arrays.equals( BYTES1, cbv.getCopy() ) );
+        assertTrue( Arrays.equals( BYTES1, cbv.getReference() ) );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertFalse( cbv.isNull() );
+        assertNotNull( cbv.getNormalizedValue() );
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+    }
+
+
+    @Test
+    public void testSetByteArray() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        cbv.set( BYTES1 );
+        
+        assertTrue( Arrays.equals( BYTES1, cbv.get() ) );
+        assertTrue( Arrays.equals( BYTES1, cbv.getCopy() ) );
+        assertTrue( Arrays.equals( BYTES1, cbv.getReference() ) );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertFalse( cbv.isNull() );
+        assertNotNull( cbv.getNormalizedValue() );
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+    }
+
+
+    @Test
+    public void testGetNormalizedValueCopy()  throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue( BYTES2 );
+        
+        assertTrue( Arrays.equals( BYTES2, cbv.get() ) );
+        assertTrue( Arrays.equals( BYTES2, cbv.getCopy() ) );
+        assertTrue( Arrays.equals( BYTES2, cbv.getReference() ) );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertFalse( cbv.isNull() );
+        assertNotNull( cbv.getNormalizedValue() );
+        assertTrue( Arrays.equals( BYTES2, cbv.getNormalizedValue() ) );
+        
+        cbv.normalize( BINARY_NORMALIZER );
+        byte[] copy = cbv.getNormalizedValueCopy();
+        assertTrue( Arrays.equals( BYTES1, copy ) );
+        cbv.getNormalizedValueReference()[0]=0x11;
+        assertTrue( Arrays.equals( BYTES1, copy ) );
+    }
+
+
+    @Test
+    public void testNormalizeNormalizer() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        cbv.normalize( BINARY_NORMALIZER );
+        assertTrue( cbv.isNormalized() );
+        assertEquals( null, cbv.getNormalizedValue() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        cbv.normalize( BINARY_NORMALIZER );
+        assertTrue( cbv.isNormalized() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.get() ) );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getNormalizedValue() ) );
+        
+        cbv.set( BYTES1 );
+        cbv.normalize( BINARY_NORMALIZER );
+        assertTrue( cbv.isNormalized() );
+        assertTrue( Arrays.equals( BYTES1, cbv.get() ) );
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+
+        cbv.set( BYTES2 );
+        cbv.normalize( BINARY_NORMALIZER );
+        assertTrue( cbv.isNormalized() );
+        assertTrue( Arrays.equals( BYTES2, cbv.get() ) );
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+    }
+
+
+    @Test
+    public void testCompareToValueOfbyte() throws NamingException
+    {
+        ClientBinaryValue cbv1 = new ClientBinaryValue();
+        ClientBinaryValue cbv2 = new ClientBinaryValue();
+        
+        assertEquals( 0, cbv1.compareTo( cbv2 ) );
+        
+        cbv1.set(  BYTES1 );
+        assertEquals( 1, cbv1.compareTo( cbv2 ) );
+
+        cbv2.set(  BYTES2 );
+        assertEquals( 1, cbv1.compareTo( cbv2 ) );
+        
+        cbv2.normalize( BINARY_NORMALIZER );
+        assertEquals( 0, cbv1.compareTo( cbv2 ) );
+        
+        cbv1.set( BYTES2 );
+        assertEquals( -1, cbv1.compareTo( cbv2 ) );
+    }
+
+
+    @Test
+    public void testEquals() throws NamingException
+    {
+        ClientBinaryValue cbv1 = new ClientBinaryValue();
+        ClientBinaryValue cbv2 = new ClientBinaryValue();
+        
+        assertEquals( cbv1, cbv2 );
+        
+        cbv1.set(  BYTES1 );
+        assertNotSame( cbv1, cbv2 );
+
+        cbv2.set(  BYTES2 );
+        assertNotSame( cbv1, cbv2 );
+        
+        cbv2.normalize( BINARY_NORMALIZER );
+        assertEquals( cbv1, cbv2 );
+        
+        cbv1.set( BYTES2 );
+        assertNotSame( cbv1, cbv2 );
+    }
+
+
+    @Test
+    public void testClone()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        ClientBinaryValue copy = cbv.clone();
+        
+        assertEquals( cbv, copy );
+        
+        cbv.set( BYTES1 );
+        assertNotSame( cbv, copy );
+        
+        copy = cbv.clone();
+        assertEquals( cbv, copy );
+
+        cbv.getReference()[0] = 0x11;
+        
+        assertTrue( Arrays.equals( BYTES_MOD, cbv.get() ) );
+        assertTrue( Arrays.equals( BYTES1, copy.get() ) );
+    }
+
+
+    @Test
+    public void testGetCopy()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertNull( cbv.getCopy() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertNotNull( cbv.getCopy() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getCopy() ) );
+        
+        cbv.set( BYTES1 );
+        byte[] copy = cbv.getCopy();
+        
+        assertTrue( Arrays.equals( BYTES1, copy ) );
+
+        cbv.getReference()[0] = 0x11;
+        assertTrue( Arrays.equals( BYTES1, copy ) );
+        assertTrue( Arrays.equals( BYTES_MOD, cbv.get() ) );
+    }
+
+
+    @Test
+    public void testCompareTo() throws NamingException
+    {
+        ClientBinaryValue cbv1 = new ClientBinaryValue();
+        ClientBinaryValue cbv2 = new ClientBinaryValue();
+        
+        assertEquals( 0, cbv1.compareTo( cbv2 ) );
+        
+        cbv1.set( BYTES1 );
+        assertEquals( 1, cbv1.compareTo( cbv2 ) );
+        assertEquals( -1, cbv2.compareTo( cbv1 ) );
+        
+        cbv2.set( BYTES1 );
+        assertEquals( 0, cbv1.compareTo( cbv2 ) );
+
+        // Now check that the equals method works on normalized values.
+        cbv1.set( BYTES2 );
+        cbv2.set( BYTES1 );
+        cbv1.normalize( BINARY_NORMALIZER );
+        assertEquals( 0, cbv1.compareTo( cbv2 ) );
+        
+        cbv1.set( BYTES1 );
+        cbv2.set( BYTES2 );
+        assertEquals( 1, cbv1.compareTo( cbv2 ) );
+
+        cbv1.set( BYTES2 );
+        cbv2.set( BYTES1 );
+        assertEquals( -1, cbv1.compareTo( cbv2 ) );
+    }
+
+
+    @Test
+    public void testToString()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertEquals( "null", cbv.toString() );
+
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertEquals( "''", cbv.toString() );
+
+        cbv.set( BYTES1 );
+        assertEquals( "'0x01 0x02 0x03 0x04 '", cbv.toString() );
+        
+        cbv.clear();
+        assertEquals( "null", cbv.toString() );
+    }
+
+
+    @Test
+    public void testGetReference()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertNull( cbv.getReference() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertNotNull( cbv.getReference() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getReference() ) );
+        
+        cbv.set( BYTES1 );
+        byte[] reference = cbv.getReference();
+        
+        assertTrue( Arrays.equals( BYTES1, reference ) );
+
+        cbv.getReference()[0] = 0x11;
+        assertTrue( Arrays.equals( BYTES_MOD, reference ) );
+        assertTrue( Arrays.equals( BYTES_MOD, cbv.get() ) );
+    }
+
+
+    @Test
+    public void testGet()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertNull( cbv.get() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertNotNull( cbv.get() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.get() ) );
+        
+        cbv.set( BYTES1 );
+        byte[] get = cbv.get();
+        
+        assertTrue( Arrays.equals( BYTES1, get ) );
+
+        cbv.getReference()[0] = 0x11;
+        assertTrue( Arrays.equals( BYTES1, get ) );
+        assertTrue( Arrays.equals( BYTES_MOD, cbv.get() ) );
+    }
+
+
+    @Test
+    public void testGetNormalizedValue() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertFalse( cbv.isNormalized() );
+
+        cbv.normalize( BINARY_NORMALIZER );
+        byte[] value = cbv.getNormalizedValue();
+        assertNull( value );
+        assertTrue( cbv.isNormalized() );
+        
+        cbv.set( BYTES2 );
+        cbv.normalize( BINARY_NORMALIZER );
+        value = cbv.getNormalizedValue();
+        assertTrue( Arrays.equals( BYTES1, value ) );
+        cbv.getNormalizedValueReference()[0]=0x11;
+        assertFalse( Arrays.equals( BYTES_MOD, value ) );
+    }
+
+
+    @Test
+    public void testGetNormalizedValueReference() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertFalse( cbv.isNormalized() );
+
+        cbv.normalize( BINARY_NORMALIZER );
+        byte[] value = cbv.getNormalizedValueReference();
+        assertNull( value );
+        assertTrue( cbv.isNormalized() );
+        
+        cbv.set( BYTES2 );
+        cbv.normalize( BINARY_NORMALIZER );
+        value = cbv.getNormalizedValueReference();
+        assertTrue( Arrays.equals( BYTES1, value ) );
+        cbv.getNormalizedValueReference()[0]=0x11;
+        assertTrue( Arrays.equals( BYTES_MOD, value ) );
+    }
+
+
+    @Test
+    public void testIsNull()
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertTrue( cbv.isNull() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertFalse( cbv.isNull() );
+        
+        cbv.set( BYTES1 );
+        assertFalse( cbv.isNull() );
+        
+        cbv.clear();
+        assertTrue( cbv.isNull() );
+    }
+
+
+    @Test
+    public void testIsValid() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertFalse( cbv.isValid() );
+        cbv.isValid( BINARY_CHECKER );
+        assertTrue( cbv.isValid() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertFalse( cbv.isValid() );
+        cbv.isValid( BINARY_CHECKER );
+        assertTrue( cbv.isValid() );
+        
+        cbv.set( BYTES1 );
+        assertFalse( cbv.isNull() );
+        cbv.isValid( BINARY_CHECKER );
+        assertTrue( cbv.isValid() );
+
+        cbv.set( INVALID_BYTES );
+        assertFalse( cbv.isNull() );
+        cbv.isValid( BINARY_CHECKER );
+        assertFalse( cbv.isValid() );
+    }
+
+
+    @Test
+    public void testIsValidSyntaxChecker() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertTrue( cbv.isValid( BINARY_CHECKER ) ) ;
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        
+        cbv.set( BYTES1 );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+
+        cbv.set( INVALID_BYTES );
+        assertFalse( cbv.isValid( BINARY_CHECKER ) );
+    }
+
+
+    @Test
+    public void testNormalize() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        cbv.normalize();
+        assertTrue( cbv.isNormalized() );
+        assertEquals( null, cbv.getNormalizedValue() );
+        
+        cbv.set( StringTools.EMPTY_BYTES );
+        cbv.normalize();
+        assertTrue( cbv.isNormalized() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getNormalizedValue() ) );
+        
+        cbv.set( BYTES2 );
+        cbv.normalize();
+        assertTrue( cbv.isNormalized() );
+        assertTrue( Arrays.equals( BYTES2, cbv.getNormalizedValue() ) );
+    }
+
+
+    @Test
+    public void testSet() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        cbv.set( null );
+        assertNull( cbv.get() );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertTrue( cbv.isNull() );
+
+        cbv.set( StringTools.EMPTY_BYTES );
+        assertNotNull( cbv.get() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.get() ) );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertFalse( cbv.isNull() );
+
+        cbv.set( BYTES1 );
+        assertNotNull( cbv.get() );
+        assertTrue( Arrays.equals( BYTES1, cbv.get() ) );
+        assertFalse( cbv.isNormalized() );
+        assertTrue( cbv.isValid( BINARY_CHECKER ) );
+        assertFalse( cbv.isNull() );
+    }
+
+
+    @Test
+    public void testIsNormalized() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertFalse( cbv.isNormalized() );
+        
+        cbv.set( BYTES2 );
+        assertFalse( cbv.isNormalized() );
+        
+        cbv.normalize( BINARY_NORMALIZER );
+        
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+        assertTrue( cbv.isNormalized() );
+        
+        cbv.set( BYTES2 );
+        assertTrue( cbv.isNormalized() );
+
+        cbv.set( BYTES_MOD );
+        assertFalse( cbv.isNormalized() );
+    }
+
+
+    @Test
+    public void testSetNormalized() throws NamingException
+    {
+        ClientBinaryValue cbv = new ClientBinaryValue();
+        
+        assertFalse( cbv.isNormalized() );
+        
+        cbv.setNormalized( true );
+        assertTrue( cbv.isNormalized() );
+        
+        cbv.set(  BYTES2 );
+        assertFalse( cbv.isNormalized() );
+        
+        cbv.normalize( BINARY_NORMALIZER );
+        
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+        assertTrue( cbv.isNormalized() );
+        
+        cbv.setNormalized( false );
+        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
+        assertFalse( cbv.isNormalized() );
+
+        cbv.normalize( BINARY_NORMALIZER );
+        cbv.clear();
+        assertFalse( cbv.isNormalized() );
+    }
+}



Mime
View raw message