directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1404693 - in /directory: apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/entry/ shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/ shared/trunk/ldap/model/src/main/java/org/apache/directory/...
Date Thu, 01 Nov 2012 17:52:42 GMT
Author: elecharny
Date: Thu Nov  1 17:52:42 2012
New Revision: 1404693

URL: http://svn.apache.org/viewvc?rev=1404693&view=rev
Log:
Fix for DIRSHARED-142

Modified:
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/entry/SchemaAwareEntryTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/entry/SchemaAwareEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/entry/SchemaAwareEntryTest.java?rev=1404693&r1=1404692&r2=1404693&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/entry/SchemaAwareEntryTest.java
(original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/entry/SchemaAwareEntryTest.java
Thu Nov  1 17:52:42 2012
@@ -63,6 +63,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.apache.directory.shared.util.Strings;
 import org.apache.directory.shared.util.exception.Exceptions;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -80,24 +81,24 @@ import com.mycila.junit.concurrent.Concu
 @Concurrency()
 public class SchemaAwareEntryTest
 {
-    private static final byte[] BYTES1 = new byte[]
+    private final byte[] BYTES1 = new byte[]
         { 'a', 'b' };
-    private static final byte[] BYTES2 = new byte[]
+    private final byte[] BYTES2 = new byte[]
         { 'b' };
-    private static final byte[] BYTES3 = new byte[]
+    private final byte[] BYTES3 = new byte[]
         { 'c' };
 
     private static LdifSchemaLoader loader;
     private static SchemaManager schemaManager;
 
-    private static AttributeType atObjectClass;
-    private static AttributeType atCN;
-    private static AttributeType atDC;
-    private static AttributeType atSN;
-    private static AttributeType atC;
-    private static AttributeType atEMail;
-    private static AttributeType atL;
-    private static AttributeType atOC;
+    private AttributeType atObjectClass;
+    private AttributeType atCN;
+    private AttributeType atDC;
+    private AttributeType atSN;
+    private AttributeType atC;
+    private AttributeType atEMail;
+    private AttributeType atL;
+    private AttributeType atOC;
 
     // A Binary attribute
     private static AttributeType atPwd;
@@ -134,7 +135,12 @@ public class SchemaAwareEntryTest
         {
             fail( "Schema load failed : " + Exceptions.printErrors( errors ) );
         }
+    }
+    
 
+    @Before
+    public void init() throws Exception
+    {
         atObjectClass = schemaManager.lookupAttributeTypeRegistry( "objectClass" );
         atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
         atDC = schemaManager.lookupAttributeTypeRegistry( "dc" );
@@ -759,6 +765,10 @@ public class SchemaAwareEntryTest
         Value<String> test2 = new StringValue( atDC, "test2" );
         Value<String> test3 = new StringValue( atDC, "test3" );
 
+        Value<String> testEMail1 = new StringValue( atEMail, "test1" );
+        Value<String> testEMail2 = new StringValue( atEMail, "test2" );
+        Value<String> testEMail3 = new StringValue( atEMail, "test3" );
+
         Value<byte[]> testB1 = new BinaryValue( atPassword, b1 );
         Value<byte[]> testB2 = new BinaryValue( atPassword, b2 );
         Value<byte[]> testB3 = new BinaryValue( atPassword, b3 );
@@ -775,13 +785,13 @@ public class SchemaAwareEntryTest
         }
 
         // Test a simple addition in atEMail
-        entry.add( atEMail, test1 );
+        entry.add( atEMail, testEMail1 );
         assertNotNull( entry.get( atEMail ) );
         assertEquals( 1, entry.get( atEMail ).size() );
         assertEquals( "test1", entry.get( atEMail ).get().getString() );
 
         // Test some more addition
-        entry.add( atEMail, test2, test3 );
+        entry.add( atEMail, testEMail2, testEMail3 );
         assertNotNull( entry.get( atEMail ) );
         assertEquals( 3, entry.get( atEMail ).size() );
         assertTrue( entry.contains( atEMail, "test1" ) );
@@ -789,7 +799,7 @@ public class SchemaAwareEntryTest
         assertTrue( entry.contains( atEMail, "test3" ) );
 
         // Test some addition of existing values
-        entry.add( atEMail, test2 );
+        entry.add( atEMail, testEMail2 );
         assertNotNull( entry.get( atEMail ) );
         assertEquals( 3, entry.get( atEMail ).size() );
         assertTrue( entry.contains( atEMail, "test1" ) );

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java?rev=1404693&r1=1404692&r2=1404693&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
Thu Nov  1 17:52:42 2012
@@ -50,6 +50,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.apache.directory.shared.util.StringConstants;
 import org.apache.directory.shared.util.Strings;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -67,40 +68,40 @@ import com.mycila.junit.concurrent.Concu
  */
 public class SchemaAwareAttributeTest
 {
-    private static AttributeType atCN = null;
-    private static AttributeType atDC;
-    private static AttributeType atSN;
-    private static AttributeType atName;
+    private AttributeType atCN = null;
+    private AttributeType atDC;
+    private AttributeType atSN;
+    private AttributeType atName;
 
     // A SINGLE-VALUE attribute
-    private static AttributeType atC;
+    private AttributeType atC;
 
     // A Binary attribute
-    private static AttributeType atPwd;
+    private AttributeType atPwd;
 
     // A String attribute which allows null value
-    private static AttributeType atEMail;
+    private AttributeType atEMail;
 
-    private static final Value<String> NULL_STRING_VALUE = new StringValue( ( String
) null );
-    private static final Value<byte[]> NULL_BINARY_VALUE = new BinaryValue( ( byte[]
) null );
-    private static final byte[] BYTES1 = new byte[]
+    private final Value<String> NULL_STRING_VALUE = new StringValue( ( String ) null
);
+    private final Value<byte[]> NULL_BINARY_VALUE = new BinaryValue( ( byte[] ) null
);
+    private final byte[] BYTES1 = new byte[]
         { 'a', 'b' };
-    private static final byte[] BYTES2 = new byte[]
+    private final byte[] BYTES2 = new byte[]
         { 'b' };
-    private static final byte[] BYTES3 = new byte[]
+    private final byte[] BYTES3 = new byte[]
         { 'c' };
-    private static final byte[] BYTES4 = new byte[]
+    private final byte[] BYTES4 = new byte[]
         { 'd' };
 
-    private static final StringValue STR_VALUE1 = new StringValue( "a" );
-    private static final StringValue STR_VALUE2 = new StringValue( "b" );
-    private static final StringValue STR_VALUE3 = new StringValue( "c" );
-    private static final StringValue STR_VALUE4 = new StringValue( "d" );
-
-    private static final BinaryValue BIN_VALUE1 = new BinaryValue( BYTES1 );
-    private static final BinaryValue BIN_VALUE2 = new BinaryValue( BYTES2 );
-    private static final BinaryValue BIN_VALUE3 = new BinaryValue( BYTES3 );
-    private static final BinaryValue BIN_VALUE4 = new BinaryValue( BYTES4 );
+    private final StringValue STR_VALUE1 = new StringValue( "a" );
+    private final StringValue STR_VALUE2 = new StringValue( "b" );
+    private final StringValue STR_VALUE3 = new StringValue( "c" );
+    private final StringValue STR_VALUE4 = new StringValue( "d" );
+
+    private final BinaryValue BIN_VALUE1 = new BinaryValue( BYTES1 );
+    private final BinaryValue BIN_VALUE2 = new BinaryValue( BYTES2 );
+    private final BinaryValue BIN_VALUE3 = new BinaryValue( BYTES3 );
+    private final BinaryValue BIN_VALUE4 = new BinaryValue( BYTES4 );
 
     private static SchemaManager schemaManager;
 
@@ -180,14 +181,20 @@ public class SchemaAwareAttributeTest
         }
     }
 
-
+    
+    @BeforeClass
+    public static void startup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+    
+    
     /**
      * Initialize the schemaManager
      */
-    @BeforeClass
-    public static void setup() throws Exception
+    @Before
+    public void setup() throws Exception
     {
-        schemaManager = new DefaultSchemaManager();
         atCN = schemaManager.getAttributeType( "cn" );
         atDC = schemaManager.lookupAttributeTypeRegistry( "dc" );
         atC = schemaManager.lookupAttributeTypeRegistry( "c" );

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java?rev=1404693&r1=1404692&r2=1404693&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
Thu Nov  1 17:52:42 2012
@@ -312,7 +312,7 @@ public class SchemaAwareValueSerializati
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = StringValue.deserialize( cn, in );
+        StringValue svDeser = StringValue.deserialize( dc, in );
 
         assertEquals( value, svDeser );
     }
@@ -333,7 +333,7 @@ public class SchemaAwareValueSerializati
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = StringValue.deserialize( cn, in );
+        StringValue svDeser = StringValue.deserialize( dc, in );
 
         assertEquals( value, svDeser );
     }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java?rev=1404693&r1=1404692&r2=1404693&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
Thu Nov  1 17:52:42 2012
@@ -30,6 +30,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
+import org.apache.directory.shared.ldap.model.schema.MatchingRule;
+import org.apache.directory.shared.ldap.model.schema.Normalizer;
 import org.apache.directory.shared.ldap.model.schema.comparators.ByteArrayComparator;
 import org.apache.directory.shared.util.Strings;
 
@@ -234,67 +236,157 @@ public class BinaryValue extends Abstrac
         }
 
         BinaryValue other = ( BinaryValue ) obj;
-
-        if ( isNull() )
-        {
-            return other.isNull();
-        }
-
-        // If we have an attributeType, it must be equal
-        // We should also use the comparator if we have an AT
+        
+        // First check if we have an attrbuteType.
         if ( attributeType != null )
         {
+            // yes : check for the other value
             if ( other.attributeType != null )
             {
-                if ( !attributeType.equals( other.attributeType ) )
+                if ( attributeType.getOid().equals( other.getAttributeType().getOid() ) )
                 {
+                    // Both AttributeType have the same OID, we can assume they are 
+                    // equals. We don't check any further, because the unicity of OID
+                    // makes it unlikely that the two AT are different.
+                    // The values may be both null
+                    if ( isNull() )
+                    {
+                        return other.isNull();
+                    }
+
+                    // Shortcut : if we have an AT for both the values, check the 
+                    // already normalized values
+                    if ( Arrays.equals( wrappedValue, other.wrappedValue ) )
+                    {
+                        return true;
+                    }
+                    
+                    // We have an AttributeType, we use the associated comparator
+                    try
+                    {
+                        Comparator<byte[]> comparator = ( Comparator<byte[]>
) getLdapComparator();
+
+                        // Compare normalized values
+                        if ( comparator == null )
+                        {
+                            return Arrays.equals( getNormReference(), other.getNormReference()
);
+                        }
+                        else
+                        {
+                            return comparator.compare( getNormReference(), other.getNormReference()
) == 0;
+                        }
+                    }
+                    catch ( LdapException ne )
+                    {
+                        return false;
+                    }
+                }
+                else
+                {
+                    // We can't compare two values when the two ATs are different
                     return false;
                 }
             }
             else
             {
-                other.attributeType = attributeType;
-            }
-        }
-        else if ( other.attributeType != null )
-        {
-            attributeType = other.attributeType;
-        }
+                // We only have one AT : we will assume that both values are for the 
+                // same AT.
+                // The values may be both null
+                if ( isNull() )
+                {
+                    return other.isNull();
+                }
 
-        // Shortcut : if the values are equals, no need to compare
-        // the normalized values
-        if ( Arrays.equals( wrappedValue, other.wrappedValue ) )
-        {
-            return true;
-        }
+                // We have an AttributeType on the base value, we need to use its comparator
+                try
+                {
+                    Comparator<byte[]> comparator = ( Comparator<byte[]> ) getLdapComparator();
 
-        if ( attributeType != null )
+                    // Compare normalized values. We have to normalized the other value,
+                    // as it has no AT
+                    MatchingRule equality = getAttributeType().getEquality();
+                    
+                    if ( equality == null )
+                    {
+                        // No matching rule : compare the raw values
+                        return Arrays.equals( getNormReference(), other.getNormReference()
);
+                    }
+                    
+                    Normalizer normalizer = equality.getNormalizer();
+                    
+                    BinaryValue otherValue = (BinaryValue)normalizer.normalize( other );
+                    
+                    if ( comparator == null )
+                    {
+                        return Arrays.equals( getNormReference(), otherValue.getNormReference()
);
+                    }
+                    else
+                    {
+                        return comparator.compare( getNormReference(), otherValue.getNormReference()
) == 0;
+                    }
+                }
+                catch ( LdapException ne )
+                {
+                    return false;
+                }
+            }
+        }
+        else
         {
-            // We have an AttributeType, we eed to use the comparator
-            try
+            // No : check for the other value
+            if ( other.attributeType != null )
             {
-                Comparator<byte[]> comparator = ( Comparator<byte[]> ) getLdapComparator();
-
-                // Compare normalized values
-                if ( comparator == null )
+                // We only have one AT : we will assume that both values are for the 
+                // same AT.
+                // The values may be both null
+                if ( isNull() )
                 {
-                    return Arrays.equals( getNormReference(), other.getNormReference() );
+                    return other.isNull();
                 }
-                else
+                
+                try
                 {
-                    return comparator.compare( getNormReference(), other.getNormReference()
) == 0;
+                    Comparator<byte[]> comparator = ( Comparator<byte[]> ) other.getLdapComparator();
+
+                    // Compare normalized values. We have to normalized the other value,
+                    // as it has no AT
+                    MatchingRule equality = other.getAttributeType().getEquality();
+                    
+                    if ( equality == null )
+                    {
+                        // No matching rule : compare the raw values
+                        return Arrays.equals( getNormReference(), other.getNormReference()
);
+                    }
+                    
+                    Normalizer normalizer = equality.getNormalizer();
+                    
+                    BinaryValue thisValue = (BinaryValue)normalizer.normalize( this );
+                    
+                    if ( comparator == null )
+                    {
+                        return Arrays.equals( thisValue.getNormReference(), other.getNormReference()
);
+                    }
+                    else
+                    {
+                        return comparator.compare( thisValue.getNormReference(), other.getNormReference()
) == 0;
+                    }
+                }
+                catch ( LdapException ne )
+                {
+                    return false;
                 }
             }
-            catch ( LdapException ne )
+            else
             {
-                return false;
+                // The values may be both null
+                if ( isNull() )
+                {
+                    return other.isNull();
+                }
+                
+                // Now check the normalized values
+                return Arrays.equals( getNormReference(), other.getNormReference() );
             }
-
-        }
-        else
-        {
-            // now unlike regular values we have to compare the normalized values
-            return Arrays.equals( getNormReference(), other.getNormReference() );
         }
     }
 
@@ -461,12 +553,32 @@ public class BinaryValue extends Abstrac
         }
         else
         {
-            // Copy the wrappedValue into the normalizedValue
-            if ( wrappedLength >= 0 )
+            if ( attributeType != null )
+            {
+                try
+                {
+                    normalizedValue = attributeType.getEquality().getNormalizer().normalize(
this ).getBytes();
+                }
+                catch ( LdapException le )
+                {
+                    // Copy the wrappedValue into the normalizedValue
+                    if ( wrappedLength >= 0 )
+                    {
+                        normalizedValue = new byte[wrappedLength];
+
+                        System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength
);
+                    }
+                }
+            }
+            else
             {
-                normalizedValue = new byte[wrappedLength];
+                // Copy the wrappedValue into the normalizedValue
+                if ( wrappedLength >= 0 )
+                {
+                    normalizedValue = new byte[wrappedLength];
 
-                System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength );
+                    System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength
);
+                }
             }
         }
 

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java?rev=1404693&r1=1404692&r2=1404693&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
Thu Nov  1 17:52:42 2012
@@ -22,12 +22,15 @@ package org.apache.directory.shared.ldap
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.Comparator;
 
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
+import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.Normalizer;
 import org.apache.directory.shared.util.Strings;
 import org.apache.directory.shared.util.exception.NotImplementedException;
@@ -267,89 +270,158 @@ public class StringValue extends Abstrac
         }
 
         StringValue other = ( StringValue ) obj;
-
-        if ( this.isNull() )
-        {
-            return other.isNull();
-        }
-
-        // First check the upValue. If they are equal, the Values are equal
-        if ( wrappedValue == other.wrappedValue )
-        {
-            return true;
-        }
-        else if ( wrappedValue != null )
-        {
-            if ( wrappedValue.equals( other.wrappedValue ) )
-            {
-                return true;
-            }
-        }
-
-        // If we have an attributeType, it must be equal
-        // We should also use the comparator if we have an AT
+        
+        // First check if we have an attrbuteType.
         if ( attributeType != null )
         {
+            // yes : check for the other value
             if ( other.attributeType != null )
             {
-                if ( !attributeType.equals( other.attributeType ) )
+                if ( attributeType.getOid().equals( other.getAttributeType().getOid() ) )
                 {
+                    // Both AttributeType have the same OID, we can assume they are 
+                    // equals. We don't check any further, because the unicity of OID
+                    // makes it unlikely that the two AT are different.
+                    // The values may be both null
+                    if ( isNull() )
+                    {
+                        return other.isNull();
+                    }
+
+                    // Shortcut : if we have an AT for both the values, check the 
+                    // already normalized values
+                    if ( wrappedValue.equals( other.wrappedValue ) )
+                    {
+                        return true;
+                    }
+                    
+                    // We have an AttributeType, we use the associated comparator
+                    try
+                    {
+                        Comparator<String> comparator = ( Comparator<String>
) getLdapComparator();
+
+                        // Compare normalized values
+                        if ( comparator == null )
+                        {
+                            return getNormReference().equals( other.getNormReference() );
+                        }
+                        else
+                        {
+                            return comparator.compare( getNormReference(), other.getNormReference()
) == 0;
+                        }
+                    }
+                    catch ( LdapException ne )
+                    {
+                        return false;
+                    }
+                }
+                else
+                {
+                    // We can't compare two values when the two ATs are different
                     return false;
                 }
             }
             else
             {
-                return this.getNormValue().equals( other.getNormValue() );
-            }
-        }
-        else if ( other.attributeType != null )
-        {
-            return this.getNormValue().equals( other.getNormValue() );
-        }
+                // We only have one AT : we will assume that both values are for the 
+                // same AT.
+                // The values may be both null
+                if ( isNull() )
+                {
+                    return other.isNull();
+                }
 
-        // Shortcut : compare the values without normalization
-        // If they are equal, we may avoid a normalization.
-        // Note : if two values are equal, then their normalized
-        // value are equal too if their attributeType are equal.
-        if ( getReference().equals( other.getReference() ) )
-        {
-            return true;
-        }
+                // We have an AttributeType on the base value, we need to use its comparator
+                try
+                {
+                    Comparator<String> comparator = ( Comparator<String> ) getLdapComparator();
 
-        if ( attributeType != null )
+                    // Compare normalized values. We have to normalized the other value,
+                    // as it has no AT
+                    MatchingRule equality = getAttributeType().getEquality();
+                    
+                    if ( equality == null )
+                    {
+                        // No matching rule : compare the raw values
+                        return getNormReference().equals( other.getNormReference() );
+                    }
+                    
+                    Normalizer normalizer = equality.getNormalizer();
+                    
+                    StringValue otherValue = (StringValue)normalizer.normalize( other );
+                    
+                    if ( comparator == null )
+                    {
+                        return getNormReference().equals( otherValue.getNormReference() );
+                    }
+                    else
+                    {
+                        return comparator.compare( getNormReference(), otherValue.getNormReference()
) == 0;
+                    }
+                }
+                catch ( LdapException ne )
+                {
+                    return false;
+                }
+            }
+        }
+        else
         {
-            try
+            // No : check for the other value
+            if ( other.attributeType != null )
             {
-                LdapComparator<String> comparator = getLdapComparator();
-
-                // Compare normalized values
-                if ( comparator == null )
+                // We only have one AT : we will assume that both values are for the 
+                // same AT.
+                // The values may be both null
+                if ( isNull() )
                 {
-                    return getNormValue().equals( other.getNormValue() );
+                    return other.isNull();
                 }
-                else
+                
+                try
                 {
-                    if ( isSchemaAware() )
+                    Comparator<String> comparator = ( Comparator<String> ) other.getLdapComparator();
+
+                    // Compare normalized values. We have to normalized the other value,
+                    // as it has no AT
+                    MatchingRule equality = other.getAttributeType().getEquality();
+                    
+                    if ( equality == null )
+                    {
+                        // No matching rule : compare the raw values
+                        return getNormReference().equals( other.getNormReference() );
+                    }
+                    
+                    Normalizer normalizer = equality.getNormalizer();
+                    
+                    StringValue thisValue = (StringValue)normalizer.normalize( this );
+                    
+                    if ( comparator == null )
                     {
-                        return comparator.compare( getNormValue(), other.getNormValue() )
== 0;
+                        return thisValue.getNormReference().equals( other.getNormReference()
);
                     }
                     else
                     {
-                        Normalizer normalizer = attributeType.getEquality().getNormalizer();
-                        return comparator.compare( normalizer.normalize( getValue() ),
-                            normalizer.normalize( other.getValue() ) ) == 0;
+                        return comparator.compare( thisValue.getNormReference(), other.getNormReference()
) == 0;
                     }
                 }
+                catch ( LdapException ne )
+                {
+                    return false;
+                }
             }
-            catch ( LdapException ne )
+            else
             {
-                return false;
+                // The values may be both null
+                if ( isNull() )
+                {
+                    return other.isNull();
+                }
+                
+                // Now check the normalized values
+                return getNormReference().equals( other.getNormReference() );
             }
         }
-        else
-        {
-            return this.getNormValue().equals( other.getNormValue() );
-        }
     }
 
 
@@ -461,7 +533,21 @@ public class StringValue extends Abstrac
         }
         else
         {
-            normalizedValue = wrappedValue;
+            if ( attributeType != null )
+            {
+                try
+                {
+                    normalizedValue = attributeType.getEquality().getNormalizer().normalize(
wrappedValue );
+                }
+                catch ( LdapException le )
+                {
+                    normalizedValue = wrappedValue;
+                }
+            }
+            else
+            {
+                normalizedValue = wrappedValue;
+            }
         }
 
         // The hashCoe

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java?rev=1404693&r1=1404692&r2=1404693&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java
Thu Nov  1 17:52:42 2012
@@ -316,7 +316,7 @@ public class StringValueAttributeTypeTes
         assertFalse( value1.equals( "test" ) );
         assertFalse( value1.equals( null ) );
 
-        assertTrue( value1.equals( valueString ) );
+        assertFalse( value1.equals( valueString ) );
         assertFalse( value1.equals( valueBytes ) );
     }
 



Mime
View raw message