You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/10/28 05:58:33 UTC

svn commit: r589269 - 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/ shared/branches/bigbang/ldap/src/...

Author: akarasulu
Date: Sat Oct 27 21:58:31 2007
New Revision: 589269

URL: http://svn.apache.org/viewvc?rev=589269&view=rev
Log:
fixing odd problem with compareTo calls using wrong implementation

Modified:
    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/ServerStreamedValue.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
    directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.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/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=589269&r1=589268&r2=589269&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 Sat Oct 27 21:58:31 2007
@@ -32,50 +32,118 @@
 
 
 /**
- * A server side value which is also a StringValue.
+ * A server side schema aware wrapper around a binary attribute value.
+ * This value wrapper uses schema information to syntax check values,
+ * and to compare them for equality and ordering.  It caches results
+ * and invalidates them when the wrapped value changes.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class ServerBinaryValue extends BinaryValue implements ServerValue<byte[]>
 {
+    /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
 
-    @SuppressWarnings ( { "AnalyzingVariableNaming" } )
-    static final long serialVersionUID = 2L;
+    /** used to dynamically lookup the attributeType when/if deserializing */
+    @SuppressWarnings ( { "UnusedDeclaration", "FieldCanBeLocal" } )
+    private final String oid;
 
-    private byte[] normalizedValue;
-    private AttributeType attributeType;
+    /** reference to the attributeType which is not serialized */
+    private transient AttributeType attributeType;
 
+    /** the canonical representation of the wrapped binary value */
+    private transient byte[] normalizedValue;
 
-    public ServerBinaryValue( AttributeType attributeType ) throws NamingException
+    /** cached results of the isValid() method call */
+    private transient Boolean valid;
+
+
+    /**
+     * Creates a ServerBinaryValue without an initial wrapped value.
+     *
+     * @param attributeType the schema type associated with this ServerBinaryValue
+     */
+    public ServerBinaryValue( AttributeType attributeType )
     {
         if ( attributeType == null )
         {
             throw new NullPointerException( "attributeType cannot be null" );
         }
 
-        if ( attributeType.getSyntax().isHumanReadable() )
+        try
+        {
+            if ( attributeType.getSyntax().isHumanReadable() )
+            {
+                LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
+            }
+        }
+        catch( NamingException e )
         {
-            LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
+            LOG.error( "Failed to resolve syntax for attributeType {}", attributeType, e );
         }
 
         this.attributeType = attributeType;
+        this.oid = attributeType.getOid();
     }
 
 
+    /**
+     * Creates a ServerBinaryValue with an initial wrapped binary value.
+     *
+     * @param attributeType the schema type associated with this ServerBinaryValue
+     * @param wrapped the binary value to wrap which may be null, or a zero length byte array
+     */
     public ServerBinaryValue( AttributeType attributeType, byte[] wrapped )
     {
-        if ( attributeType == null )
+        this( attributeType );
+        super.set( wrapped );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Value<String> Methods
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Sets the wrapped binary value.  Has the side effect of setting the
+     * normalizedValue and the valid flags to null if the wrapped value is
+     * different than what is already set.  These cached values must be
+     * recomputed to be correct with different values.
+     *
+     * @see ServerValue#set(Object)
+     */
+    public final void set( byte[] wrapped )
+    {
+        // Why should we invalidate the normalized value if it's we're setting the
+        // wrapper to it's current value?
+        if ( Arrays.equals( wrapped, get() ) )
         {
-            throw new NullPointerException( "attributeType cannot be null" );
+            return;
         }
 
-        this.attributeType = attributeType;
+        normalizedValue = null;
+        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.
+     *
+     * @see ServerValue#getNormalizedValue()
+     */
     public byte[] getNormalizedValue() throws NamingException
     {
         if ( get() == null )
@@ -101,88 +169,78 @@
     }
 
 
-    public final void set( byte[] wrapped )
-    {
-        normalizedValue = null;
-        super.set( wrapped );
-    }
-
-
+    /**
+     * 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.
+     *
+     * @todo can go into a base class
+     * @see ServerValue#isValid()
+     */
     public final boolean isValid() throws NamingException
     {
-        return attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
+        if ( valid != null )
+        {
+            return valid;
+        }
+
+        valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
+        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( ServerValue<byte[]> value )
     {
-        try
-        {
-            //noinspection unchecked
-            return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
-        }
-        catch ( Exception e )
+        if ( value == null && get() == null )
         {
-            throw new IllegalStateException( "Failed to normalize values.", e );
+            return 0;
         }
-    }
-
-
-    private Normalizer getNormalizer() throws NamingException
-    {
-        MatchingRule mr = getMatchingRule();
 
-        if ( mr == null )
+        if ( value != null && get() == null )
         {
-            return null;
+            if ( value.get() == null )
+            {
+                return 0;
+            }
+            return -1;
         }
 
-        return mr.getNormalizer();
-    }
-
-
-    private MatchingRule getMatchingRule() throws NamingException
-    {
-        MatchingRule mr = attributeType.getEquality();
-
-        if ( mr == null )
+        if ( value == null )
         {
-            mr = attributeType.getOrdering();
+            return 1;
         }
 
-        if ( mr == null )
+        try
         {
-            mr = attributeType.getSubstr();
+            //noinspection unchecked
+            return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
         }
-
-        return mr;
-    }
-
-
-    private Comparator getComparator() throws NamingException
-    {
-        MatchingRule mr = getMatchingRule();
-
-        if ( mr == null )
+        catch ( NamingException e )
         {
-            return null;
+            String msg = "Failed to compare normalized values for " + Arrays.toString( get() )
+                    + " and " + Arrays.toString( value.get() );
+            LOG.error( msg, e );
+            throw new IllegalStateException( msg, e );
         }
-
-        return mr.getComparator();
     }
 
 
-    @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
-    public final ServerBinaryValue clone() throws CloneNotSupportedException
-    {
-        ServerBinaryValue copy = new ServerBinaryValue( attributeType, get() );
-        copy.normalizedValue = normalizedValue;
-        return copy;
-    }
+    // -----------------------------------------------------------------------
+    // Object Methods
+    // -----------------------------------------------------------------------
 
 
     /**
      * @see Object#hashCode()
+     * @throws IllegalStateException on failures to extract the comparator, or the
+     * normalizers needed to perform the required comparisons based on the schema
      */
     public int hashCode()
     {
@@ -199,16 +257,20 @@
         }
         catch ( NamingException e )
         {
-            LOG.warn( "Failed to get normalized value while trying to get hashCode: {}", toString() , e );
-
-            // recover by using non-normalized values
-            return get().hashCode();
+            String msg = "Failed to normalize \"" + toString() + "\" while trying to get hashCode()";
+            LOG.error( msg, e );
+            throw new IllegalStateException( msg, e );
         }
     }
 
 
     /**
-     * @see Object#equals(Object)
+     * Checks to see if this ServerBinaryValue equals the supplied object.
+     *
+     * This equals implementation overrides the BinaryValue 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
      */
     public boolean equals( Object obj )
     {
@@ -255,5 +317,80 @@
             // recover by comparing non-normalized values
             return Arrays.equals( get(), other.get() );
         }
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Private Helper Methods (might be put into abstract base class)
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Find a matchingRule to use for normalization and comparison.  If an equality
+     * matchingRule cannot be found it checks to see if other matchingRules are
+     * available: SUBSTR, and ORDERING.  If a matchingRule cannot be found null is
+     * returned.
+     *
+     * @todo can go into a base class
+     * @return a matchingRule or null if one cannot be found for the attributeType
+     * @throws NamingException if resolution of schema entities fail
+     */
+    private MatchingRule getMatchingRule() throws NamingException
+    {
+        MatchingRule mr = attributeType.getEquality();
+
+        if ( mr == null )
+        {
+            mr = attributeType.getOrdering();
+        }
+
+        if ( mr == null )
+        {
+            mr = attributeType.getSubstr();
+        }
+
+        return mr;
+    }
+
+
+    /**
+     * Gets a normalizer using getMatchingRule() to resolve the matchingRule
+     * that the normalizer is extracted from.
+     *
+     * @todo can go into a base class
+     * @return a normalizer associated with the attributeType or null if one cannot be found
+     * @throws NamingException if resolution of schema entities fail
+     */
+    private Normalizer getNormalizer() throws NamingException
+    {
+        MatchingRule mr = getMatchingRule();
+
+        if ( mr == null )
+        {
+            return null;
+        }
+
+        return mr.getNormalizer();
+    }
+
+
+    /**
+     * Gets a comparator using getMatchingRule() to resolve the matching
+     * that the comparator is extracted from.
+     *
+     * @todo can go into a base class
+     * @return a comparator associated with the attributeType or null if one cannot be found
+     * @throws NamingException if resolution of schema entities fail
+     */
+    private Comparator getComparator() throws NamingException
+    {
+        MatchingRule mr = getMatchingRule();
+
+        if ( mr == null )
+        {
+            return null;
+        }
+
+        return mr.getComparator();
     }
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java?rev=589269&r1=589268&r2=589269&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java Sat Oct 27 21:58:31 2007
@@ -19,24 +19,23 @@
 package org.apache.directory.server.core.entry;
 
 
+import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.entry.StreamedValue;
-import org.apache.directory.shared.ldap.schema.Normalizer;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.naming.NamingException;
 import java.net.URI;
-import java.util.Comparator;
 
 
 /**
- * A large streamed value within the server.  For all practical purposes
- * values of this type are treated like referrals.  They reference some
- * value which could not fit without issue into main memory.  Instead the
- * value is referred to.  This has implications on the semantics of various
- * Value operations:
+ * A server side schema aware wrapper around a large streamed value.
+ * For all practical purposes values of this type are treated like
+ * referrals.  They reference some value which could not fit without
+ * issue into main memory.  Instead the value is referred to using a
+ * URI.  This has implications on the semantics of various Value
+ * operations:
  *
  * <ul>
  *   <li>
@@ -68,22 +67,30 @@
  *   </li>
  * </ul>
  *
+ * NOTE: this implementation of ServerValue<T> is still a work in progress!!!
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class ServerStreamedValue extends StreamedValue implements ServerValue<URI>
 {
+    /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ServerStreamedValue.class );
-    private URI normalizedValue;
 
     // use this to lookup the attributeType when deserializing
-    @SuppressWarnings ( { "UnusedDeclaration" } )
+    @SuppressWarnings ( { "UnusedDeclaration", "FieldCanBeLocal" } )
     private final String oid;
 
     // do not serialize the schema entity graph associated with the type
+    @SuppressWarnings ( { "UnusedDeclaration", "FieldCanBeLocal" } )
     private transient AttributeType attributeType;
 
-    
+
+    /**
+     * Creates a ServerStreamedValue without an initial wrapped value.
+     *
+     * @param attributeType the schema type associated with this ServerBinaryValue
+     */
     public ServerStreamedValue( AttributeType attributeType )
     {
         if ( attributeType == null )
@@ -95,90 +102,88 @@
     }
 
 
+    /**
+     * Creates a ServerStreamedValue with a wrapped URI referring to the
+     * streamed binary value.
+     *
+     * @param attributeType the schema type associated with this ServerStreamedValue
+     * @param wrapped the URI value to wrap which may be null
+     */
     public ServerStreamedValue( AttributeType attributeType, URI wrapped )
     {
-        if ( attributeType == null )
-        {
-            throw new NullPointerException( "attributeType cannot be null" );
-        }
-        this.attributeType = attributeType;
-        this.oid = attributeType.getOid();
+        this( attributeType );
         super.set( wrapped );
     }
 
 
-    public URI getNormalizedValue() throws NamingException
-    {
-        if ( get() == null )
-        {
-            return null;
-        }
-
-        if ( normalizedValue == null )
-        {
-            Normalizer normalizer = getNormalizer();
-
-            if ( normalizer == null )
-            {
-                normalizedValue = get();
-            }
-            else
-            {
-                normalizedValue = ( URI ) normalizer.normalize( get() );
-            }
-        }
-
-        return normalizedValue;
-    }
+    // -----------------------------------------------------------------------
+    // Value<String> Methods
+    // -----------------------------------------------------------------------
 
 
-    private MatchingRule getMatchingRule() throws NamingException
+    /**
+     * Sets the wrapped URI value.  Has the side effect of setting the
+     * normalizedValue and the valid flags to null if the wrapped value is
+     * different than what is already set.  These cached values must be
+     * recomputed to be correct with different values.
+     *
+     * @see ServerValue#set(Object)
+     */
+    public final void set( URI wrapped )
     {
-        MatchingRule mr = attributeType.getEquality();
-
-        if ( mr == null )
-        {
-            mr = attributeType.getOrdering();
-        }
-
-        if ( mr == null )
+        // Why should we invalidate the normalized value if it's we're setting the
+        // wrapper to it's current value?
+        if ( wrapped.equals( get() ) )
         {
-            mr = attributeType.getSubstr();
+            return;
         }
 
-        return mr;
+        super.set( wrapped );
     }
 
 
-    private Normalizer getNormalizer() throws NamingException
-    {
-        MatchingRule mr = getMatchingRule();
-
-        if ( mr == null )
-        {
-            return null;
-        }
-
-        return mr.getNormalizer();
-    }
+    // -----------------------------------------------------------------------
+    // ServerValue<String> Methods
+    // -----------------------------------------------------------------------
 
 
-    private Comparator getComparator() throws NamingException
+    /**
+     * Throws NotImplementedException. To normalize the value and return it
+     * we would have to work on the data on disk.  Normalizing the URI probably
+     * has no value since the Normalizer will not be geared for it but rather
+     * the data stored for streaming.  Perhaps this is a completely wrong value
+     * representation paradigmn for streamed values.
+     *
+     * @todo if URI is already cannonical this method may be useless
+     * @todo consider this while figuring out how to deal with streamed values
+     * @see ServerValue#getNormalizedValue()
+     */
+    public URI getNormalizedValue() throws NamingException
     {
-        MatchingRule mr = getMatchingRule();
-
-        if ( mr == null )
+        if ( get() == null )
         {
             return null;
         }
 
-        return mr.getComparator();
+        throw new NotImplementedException();
     }
 
 
+    /**
+     * Throws NotImplementedException always.
+     *
+     * We cannot attempt to check the syntax of what is wrapped since what is
+     * wrapped is the URI referring to the actual value.  Perhaps the only
+     * allowable syntax should be the binary syntax?  But that does not make
+     * sense since we want to switch to streaming for values (which can be any
+     * kind) in memory when they are greater than some threshold.
+     *
+     * @todo this is totally bogus
+     * @see ServerValue#isValid()
+     */
     public boolean isValid() throws NamingException
     {
-        return attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
+        throw new NotImplementedException();
     }
 
 
@@ -207,42 +212,15 @@
         }
     }
 
+
+    /**
+     * Again the semantics of this operation are completely screwed up since with
+     * normal processing the comparators and normalizers used would be for the data
+     * type streamed to disk rather than the URI value we have in memory.  So the
+     * comparisons would fail.
+     */
     public int compareTo( ServerValue<URI> value )
     {
-        if ( value == null && get() == null )
-        {
-            return 0;
-        }
-
-        if ( value != null && get() == null )
-        {
-            if ( value.get() == null )
-            {
-                return 0;
-            }
-            return -1;
-        }
-
-        if ( value == null )
-        {
-            return 1;
-        }
-
-
-        try
-        {
-            if ( value instanceof ServerStreamedValue )
-            {
-                //noinspection unchecked
-                return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
-            }
-
-            //noinspection unchecked
-            return getComparator().compare( getNormalizedValue(), value.get() );
-        }
-        catch ( NamingException e )
-        {
-            throw new IllegalStateException( "Normalization failed when it should have succeeded", e );
-        }
+        throw new NotImplementedException();
     }
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=589269&r1=589268&r2=589269&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Sat Oct 27 21:58:31 2007
@@ -31,10 +31,10 @@
 
 
 /**
- * A server side schema aware wrapper around a String value.  This value
- * wrapper uses schema information to syntax check values, and to compare
- * them for equality and ordering.  It caches results and invalidates
- * them when the wrapped value changes.
+ * A server side schema aware wrapper around a String attribute value.
+ * This value wrapper uses schema information to syntax check values,
+ * and to compare them for equality and ordering.  It caches results
+ * and invalidates them when the wrapped value changes.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -45,13 +45,13 @@
     private static final Logger LOG = LoggerFactory.getLogger( ServerStringValue.class );
 
     /** used to dynamically lookup the attributeType when/if deserializing */
-    @SuppressWarnings ( { "UnusedDeclaration" } )
+    @SuppressWarnings ( { "UnusedDeclaration", "FieldCanBeLocal" } )
     private final String oid;
 
     /** reference to the attributeType which is not serialized */
     private transient AttributeType attributeType;
 
-    /** the canonical representation of the wrapped value */
+    /** the canonical representation of the wrapped String value */
     private transient String normalizedValue;
 
     /** cached results of the isValid() method call */
@@ -69,32 +69,48 @@
         {
             throw new NullPointerException( "attributeType cannot be null" );
         }
+
+        try
+        {
+            if ( ! attributeType.getSyntax().isHumanReadable() )
+            {
+                LOG.warn( "Treating a value of a binary attribute {} as a String: " +
+                        "\nthis could cause data corruption!", attributeType.getName() );
+            }
+        }
+        catch( NamingException e )
+        {
+            LOG.error( "Failed to resolve syntax for attributeType {}", attributeType, e );
+        }
+
         this.attributeType = attributeType;
         this.oid = attributeType.getOid();
     }
 
 
     /**
-     * Creates a ServerStringValue with an initial wrapped value.
+     * Creates a ServerStringValue with an initial wrapped String value.
      *
      * @param attributeType the schema type associated with this ServerStringValue
      * @param wrapped the value to wrap which can be null
      */
     public ServerStringValue( AttributeType attributeType, String wrapped )
     {
-        if ( attributeType == null )
-        {
-            throw new NullPointerException( "attributeType cannot be null" );
-        }
-        this.attributeType = attributeType;
-        this.oid = attributeType.getOid();
+        this( attributeType );
         super.set( wrapped );
     }
 
 
+    // -----------------------------------------------------------------------
+    // Value<String> Methods
+    // -----------------------------------------------------------------------
+
+
     /**
-     * The normalizedValue will be invalidated (set to null) when a new different
-     * wrapper value is set.
+     * 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
+     * recomputed to be correct with different values.
      *
      * @see ServerValue#set(Object)
      */
@@ -160,6 +176,7 @@
      * change. Syntax checks only result on the first check, and when the wrapped
      * value changes.
      *
+     * @todo can go into a base class
      * @see ServerValue#isValid()
      */
     public final boolean isValid() throws NamingException
@@ -310,6 +327,7 @@
      * available: SUBSTR, and ORDERING.  If a matchingRule cannot be found null is
      * returned.
      *
+     * @todo can go into a base class
      * @return a matchingRule or null if one cannot be found for the attributeType
      * @throws NamingException if resolution of schema entities fail
      */
@@ -335,6 +353,7 @@
      * Gets a normalizer using getMatchingRule() to resolve the matchingRule
      * that the normalizer is extracted from.
      *
+     * @todo can go into a base class
      * @return a normalizer associated with the attributeType or null if one cannot be found
      * @throws NamingException if resolution of schema entities fail
      */
@@ -355,6 +374,7 @@
      * Gets a comparator using getMatchingRule() to resolve the matching
      * that the comparator is extracted from.
      *
+     * @todo can go into a base class
      * @return a comparator associated with the attributeType or null if one cannot be found
      * @throws NamingException if resolution of schema entities fail
      */

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java?rev=589269&r1=589268&r2=589269&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java Sat Oct 27 21:58:31 2007
@@ -51,7 +51,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ServerValue<T> extends Value<T>
+public interface ServerValue<T> extends Value<T>, Comparable<ServerValue<T>>
 {
     /**
      * Gets the normalized representation for the wrapped value of this

Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java?rev=589269&r1=589268&r2=589269&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java Sat Oct 27 21:58:31 2007
@@ -29,6 +29,126 @@
  */
 public class ServerStringValueTest extends TestCase
 {
+    private AttributeType getCaseIgnoringAttributeNoNumbersType()
+    {
+        S s = new S( "1.1.1.1", true );
+
+        s.setSyntaxChecker( new SyntaxChecker(){
+            public String getSyntaxOid()
+            {
+                return "1.1.1.1";
+            }
+            public boolean isValidSyntax( Object value )
+            {
+                if ( !( value instanceof String ) )
+                {
+                    return false;
+                }
+
+                String strval = ( String ) value;
+                for ( int ii = 0; ii < strval.length(); ii++ )
+                {
+                    if ( Character.isDigit( strval.charAt( ii ) ) )
+                    {
+                        return false;
+                    }
+                }
+                return true;
+            }
+
+            public void assertSyntax( Object value ) throws NamingException
+            {
+                if ( ! isValidSyntax( value ) )
+                {
+                    throw new InvalidAttributeValueException();
+                }
+            }
+        } );
+
+        final MR mr = new MR( "1.1.2.1" );
+        mr.syntax = s;
+        mr.comparator = new Comparator<String>()
+        {
+            public int compare( String o1, String o2 )
+            {
+                if ( o1 == null && o2 == null )
+                {
+                    return 0;
+                }
+
+                //noinspection ConstantConditions
+                if ( o1 == null && o2 != null )
+                {
+                    return -1;
+                }
+
+                //noinspection ConstantConditions
+                if ( o1 != null && o2 == null )
+                {
+                    return 1;
+                }
+
+                return o1.compareTo( o2 );
+            }
+
+            int getValue( String val )
+            {
+                if ( val.equals( "LOW" ) ) return 0;
+                if ( val.equals( "MEDIUM" ) ) return 1;
+                if ( val.equals( "HIGH" ) ) return 2;
+                throw new IllegalArgumentException( "Not a valid value" );
+            }
+        };
+        mr.normalizer = new Normalizer(){
+
+            public Object normalize( Object value ) throws NamingException
+            {
+                if ( value instanceof String )
+                {
+                    return ( ( String ) value ).toLowerCase();
+                }
+
+                throw new IllegalStateException( "expected string to normalize" );
+            }
+        };
+        AT at = new AT( "1.1.3.1" );
+        at.setEquality( mr );
+        at.setSyntax( s );
+        return at;
+    }
+
+
+    /**
+     * Tests to make sure the hashCode method is working properly.
+     * @throws Exception on errors
+     */
+    public void testHashCodeValidEquals() throws Exception
+    {
+        AttributeType at = getCaseIgnoringAttributeNoNumbersType();
+        ServerStringValue v0 = new ServerStringValue( at, "Alex" );
+        ServerStringValue v1 = new ServerStringValue( at, "ALEX" );
+        ServerStringValue v2 = new ServerStringValue( at, "alex" );
+        assertEquals( v0.hashCode(), "alex".hashCode() );
+        assertEquals( v1.hashCode(), "alex".hashCode() );
+        assertEquals( v2.hashCode(), "alex".hashCode() );
+        assertEquals( v0, v1 );
+        assertEquals( v0, v2 );
+        assertEquals( v1, v2 );
+        assertTrue( v0.isValid() );
+        assertTrue( v1.isValid() );
+        assertTrue( v2.isValid() );
+
+        ServerStringValue v3 = new ServerStringValue( at, "Timber" );
+        assertFalse( v3.equals( v0 ) );
+        assertFalse( v3.equals( v1 ) );
+        assertFalse( v3.equals( v2 ) );
+        assertTrue( v3.isValid() );
+
+        ServerStringValue v4 = new ServerStringValue( at, "Timber123" );
+        assertFalse( v4.isValid() );
+    }
+
+
     /**
      * Presumes an attribute which constrains it's values to some constant
      * strings: LOW, MEDUIM, HIGH.  Normalization does nothing. MatchingRules
@@ -148,7 +268,7 @@
         assertTrue( "since v4.equals( v5 ) and v4 was added then this should be true", set.contains( v5 ) );
 
         // check ordering based on the comparator
-        ArrayList<ServerStringValue> list = new ArrayList<ServerStringValue>();
+        ArrayList<ServerValue<String>> list = new ArrayList<ServerValue<String>>();
         list.add( v1 );
         list.add( v3 );
         list.add( v5 );
@@ -159,16 +279,19 @@
         //noinspection unchecked
         Collections.sort( list );
 
+        // null ones are at first 2 indices
         assertTrue( "since v4 equals v5 and has no value either could be at index 0 & 1", list.get( 0 ).equals( v4 ) );
         assertTrue( "since v4 equals v5 and has no value either could be at index 0 & 1", list.get( 0 ).equals( v5 ) );
         assertTrue( "since v4 equals v5 and has no value either could be at index 0 & 1", list.get( 1 ).equals( v4 ) );
         assertTrue( "since v4 equals v5 and has no value either could be at index 0 & 1", list.get( 1 ).equals( v5 ) );
 
+        // low ones are at the 3rd and 4th indices
         assertTrue( "since v0 equals v1 either could be at index 2 & 3", list.get( 2 ).equals( v0 ) );
         assertTrue( "since v0 equals v1 either could be at index 2 & 3", list.get( 2 ).equals( v1 ) );
         assertTrue( "since v0 equals v1 either could be at index 2 & 3", list.get( 3 ).equals( v0 ) );
         assertTrue( "since v0 equals v1 either could be at index 2 & 3", list.get( 3 ).equals( v1 ) );
 
+        // medium then high next
         assertTrue( "since v2 \"MEDIUM\" should be at index 4", list.get( 4 ).equals( v2 ) );
         assertTrue( "since v3 \"HIGH\" should be at index 5", list.get( 5 ).equals( v3 ) );
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java?rev=589269&r1=589268&r2=589269&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java Sat Oct 27 21:58:31 2007
@@ -124,27 +124,27 @@
     }
 
 
-    public int compareTo( Value<String> value )
-    {
-        if ( value == null && wrapped == null )
-        {
-            return 0;
-        }
-
-        if ( value != null && wrapped == null )
-        {
-            if ( value.get() == null )
-            {
-                return 0;
-            }
-            return -1;
-        }
-
-        if ( value == null || value.get() == null )
-        {
-            return 1;
-        }
-
-        return wrapped.compareTo( value.get() );
-    }
+//    public int compareTo( Value<String> value )
+//    {
+//        if ( value == null && wrapped == null )
+//        {
+//            return 0;
+//        }
+//
+//        if ( value != null && wrapped == null )
+//        {
+//            if ( value.get() == null )
+//            {
+//                return 0;
+//            }
+//            return -1;
+//        }
+//
+//        if ( value == null || value.get() == null )
+//        {
+//            return 1;
+//        }
+//
+//        return wrapped.compareTo( value.get() );
+//    }
 }

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=589269&r1=589268&r2=589269&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 Sat Oct 27 21:58:31 2007
@@ -30,7 +30,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface Value<T> extends Serializable, Cloneable, Comparable<Value<T>>
+public interface Value<T>
 {
     /**
      * Get the wrapped value.