directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1743354 - in /directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model: name/Ava.java schema/LdapComparator.java schema/comparators/DeepTrimToLowerComparator.java
Date Wed, 11 May 2016 13:00:30 GMT
Author: elecharny
Date: Wed May 11 13:00:29 2016
New Revision: 1743354

URL: http://svn.apache.org/viewvc?rev=1743354&view=rev
Log:
o Make the DeepTrimTOLower comparator only normalize the value. The key is supposed to be
normalized beforehand
o Added a getNormalizer() method in the LdapComparator class
o Fixed the Ava.equals() method to have it normalizing the left side of the comparator

Modified:
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapComparator.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/comparators/DeepTrimToLowerComparator.java

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java?rev=1743354&r1=1743353&r2=1743354&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
Wed May 11 13:00:29 2016
@@ -35,6 +35,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.LdapComparator;
 import org.apache.directory.api.ldap.model.schema.MatchingRule;
+import org.apache.directory.api.ldap.model.schema.Normalizer;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.api.util.Serialize;
 import org.apache.directory.api.util.Strings;
@@ -1503,8 +1504,18 @@ public class Ava implements Externalizab
 
                 if ( equalityMatchingRule != null )
                 {
-                    return equalityMatchingRule.getLdapComparator().compare( value.getValue(),
-                        instance.value.getValue() ) == 0;
+                    Normalizer normalizer = equalityMatchingRule.getNormalizer();
+                    
+                    try
+                    {
+                        return equalityMatchingRule.getLdapComparator().compare( normalizer.normalize(
value.getValue() ),
+                            instance.value.getValue() ) == 0;
+                    }
+                    catch ( LdapException le )
+                    {
+                        LOG.error( "Cannot normalize the value", le.getMessage() );
+                        return false;
+                    }
                 }
                 else
                 {

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapComparator.java?rev=1743354&r1=1743353&r2=1743354&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapComparator.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapComparator.java
Wed May 11 13:00:29 2016
@@ -23,6 +23,8 @@ package org.apache.directory.api.ldap.mo
 import java.io.Serializable;
 import java.util.Comparator;
 
+import org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer;
+
 
 /**
  * An class used for Comparator. It inherits from the general AbstractAdsSchemaObject class.
It
@@ -35,6 +37,9 @@ public abstract class LdapComparator<T>
     /** The serial version UID */
     private static final long serialVersionUID = 2L;
 
+    /** A default normalizer*/
+    protected Normalizer normalizer = new NoOpNormalizer();
+
 
     /**
      * Create a new instance of a Comparator
@@ -71,6 +76,15 @@ public abstract class LdapComparator<T>
 
         return o instanceof LdapComparator<?>;
     }
+    
+    
+    /**
+     * @return The associated normalizer
+     */
+    public Normalizer getNormalizer()
+    {
+        return normalizer;
+    }
 
 
     /**

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/comparators/DeepTrimToLowerComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/comparators/DeepTrimToLowerComparator.java?rev=1743354&r1=1743353&r2=1743354&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/comparators/DeepTrimToLowerComparator.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/comparators/DeepTrimToLowerComparator.java
Wed May 11 13:00:29 2016
@@ -58,44 +58,30 @@ public class DeepTrimToLowerComparator e
      * If any normalization attempt fails we compare using the unnormalized
      * object.
      */
-    public int compare( String o1, String o2 )
+    public int compare( String key, String value )
     {
-        String n1 = o1;
-        String n2 = o2;
+        String normalizedValue;
 
         try
         {
-            n1 = normalizer.normalize( o1 );
+            normalizedValue = normalizer.normalize( value );
         }
         catch ( LdapException e )
         {
-            LOG.warn( "Failed to normalize: " + o1, e );
-            n1 = o1;
+            LOG.warn( "Failed to normalize: " + value, e );
+            normalizedValue = value;
         }
 
-        try
-        {
-            n2 = normalizer.normalize( o2 );
-        }
-        catch ( LdapException e )
-        {
-            LOG.warn( "Failed to normalize: " + o2, e );
-            n2 = o2;
-        }
-
-        return n1.compareTo( n2 );
+        return key.compareTo( normalizedValue );
     }
-
-
+    
+    
     /**
      * {@inheritDoc}
-     * 
-     * This implementation makes sure we update the oid property of the contained normalizer
and 
-     * comparator.
      */
     @Override
-    public void setOid( String oid )
+    public Normalizer getNormalizer()
     {
-        super.setOid( oid );
+        return normalizer;
     }
 }



Mime
View raw message