directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1073535 - in /directory/shared/trunk: integ/src/test/java/org/apache/directory/shared/ldap/name/ ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/
Date Tue, 22 Feb 2011 23:02:45 GMT
Author: elecharny
Date: Tue Feb 22 23:02:44 2011
New Revision: 1073535

URL: http://svn.apache.org/viewvc?rev=1073535&view=rev
Log:
o Removed useless fields in Ava
o Reworked the Ava constructors to leverage the scheamManager
o Deleted commented code

Modified:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
    directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
    directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java?rev=1073535&r1=1073534&r2=1073535&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
Tue Feb 22 23:02:44 2011
@@ -227,7 +227,7 @@ public class AvaTest
     {
         byte[] normValue = Strings.getBytesUtf8("Test");
 
-        Ava atav = new Ava( schemaManager, "JpegPhoto", normValue );
+        Ava atav = new Ava( schemaManager, "userPKCS12", normValue );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -342,7 +342,7 @@ public class AvaTest
     {
         byte[] upValue = Strings.getBytesUtf8("  Test  ");
 
-        Ava atav = new Ava( schemaManager, "JpegPhoto", upValue );
+        Ava atav = new Ava( schemaManager, "userPKCS12", upValue );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );

Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java?rev=1073535&r1=1073534&r2=1073535&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
Tue Feb 22 23:02:44 2011
@@ -72,6 +72,9 @@ public final class Ava implements Extern
 
     /** The normalized Name type */
     private String normType;
+    
+    /** The attributeType if the Ava is schemaAware */
+    private transient AttributeType attributeType;
 
     /** The user provided Name type */
     private String upType;
@@ -85,12 +88,6 @@ public final class Ava implements Extern
     /** The user provided Ava */
     private String upName;
 
-    /** Two values used for comparison, case sensitive */
-    private static final boolean CASE_SENSITIVE = true;
-
-    /** Two values used for comparison, case insensitive */
-    private static final boolean CASE_INSENSITIVE = false;
-
     /** the schema manager */
     private transient SchemaManager schemaManager;
 
@@ -136,7 +133,25 @@ public final class Ava implements Extern
      */
     public Ava( SchemaManager schemaManager, String upType, byte[] upValue ) throws LdapInvalidDnException
     {
-        this( schemaManager, upType, new BinaryValue( upValue ) );
+        if ( schemaManager != null )
+        { 
+            try
+            {
+                attributeType = schemaManager.lookupAttributeTypeRegistry( upType );
+            }
+            catch ( LdapException le )
+            {
+                String message =  I18n.err( I18n.ERR_04188 );
+                LOG.error( message );
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message
);
+            }
+            
+            createAva( schemaManager, upType, new BinaryValue( attributeType, upValue ) );
+        }
+        else
+        {
+            createAva( upType, new BinaryValue( upValue ) );
+        }
     }
 
     
@@ -155,7 +170,25 @@ public final class Ava implements Extern
      */
     public Ava( SchemaManager schemaManager, String upType, String upValue ) throws LdapInvalidDnException
     {
-        this( schemaManager, upType, new StringValue( upValue ) );
+        if ( schemaManager != null )
+        { 
+            try
+            {
+                attributeType = schemaManager.lookupAttributeTypeRegistry( upType );
+            }
+            catch ( LdapException le )
+            {
+                String message =  I18n.err( I18n.ERR_04188 );
+                LOG.error( message );
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message
);
+            }
+            
+            createAva( schemaManager, upType, new StringValue( attributeType, upValue ) );
+        }
+        else
+        {
+            createAva( upType, new StringValue( upValue ) );
+        }
     }
 
     
@@ -172,21 +205,8 @@ public final class Ava implements Extern
      * @param upValue The User Provided value
      * @param normValue The normalized value
      */
-    private Ava( SchemaManager schemaManager, String upType, Value<?> upValue ) throws
LdapInvalidDnException
+    private void createAva( SchemaManager schemaManager, String upType, Value<?> upValue
) throws LdapInvalidDnException
     {
-        AttributeType attributeType = null;
-        
-        try
-        {
-            attributeType = schemaManager.lookupAttributeTypeRegistry( upType );
-        }
-        catch ( LdapException le )
-        {
-            String message =  I18n.err( I18n.ERR_04188 );
-            LOG.error( message );
-            throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message );
-        }
-        
         normType = attributeType.getOid();
         this.upType = upType;
             
@@ -252,6 +272,59 @@ public final class Ava implements Extern
     {
         this( upType, normType, new BinaryValue( upValue ), new BinaryValue( normValue )
);
     }
+    
+    
+    /**
+     * Construct an Ava. The type and value are normalized :
+     * <li> the type is trimmed and lowercased </li>
+     * <li> the value is trimmed </li>
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The User Provided type
+     * @param normType The normalized type
+     * @param upValue The User Provided value
+     * @param normValue The normalized value
+     */
+    private void createAva( String upType, Value<?> upValue ) throws LdapInvalidDnException
+    {
+        String upTypeTrimmed = Strings.trim(upType);
+        String normTypeTrimmed = Strings.trim(normType);
+        
+        if ( Strings.isEmpty(upTypeTrimmed) )
+        {
+            if ( Strings.isEmpty(normTypeTrimmed) )
+            {
+                String message =  I18n.err( I18n.ERR_04188 );
+                LOG.error( message );
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message
);
+            }
+            else
+            {
+                // In this case, we will use the normType instead
+                this.normType = Strings.lowerCaseAscii( normTypeTrimmed );
+                this.upType = normType;
+            }
+        }
+        else if ( Strings.isEmpty(normTypeTrimmed) )
+        {
+            // In this case, we will use the upType instead
+            this.normType = Strings.lowerCaseAscii( upTypeTrimmed );
+            this.upType = upType;
+        }
+        else
+        {
+            this.normType = Strings.lowerCaseAscii( normTypeTrimmed );
+            this.upType = upType;
+            
+        }
+            
+        this.normValue = upValue;
+        this.upValue = upValue;
+        
+        upName = this.upType + '=' + ( this.upValue == null ? "" : this.upValue.getString()
);
+    }
 
 
     /**
@@ -624,7 +697,21 @@ public final class Ava implements Extern
         }
         else
         {
-            return normValue.equals( instance.normValue );
+            if ( schemaManager != null )
+            {
+                MatchingRule equalityMatchingRule = attributeType.getEquality();
+                
+                if ( equalityMatchingRule != null )
+                {
+                    return equalityMatchingRule.getLdapComparator().compare( normValue, instance.normValue
) == 0;
+                }
+                
+                return false;
+            }
+            else
+            {
+                return normValue.equals( instance.normValue );
+            }
         }
     }
 

Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java?rev=1073535&r1=1073534&r2=1073535&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
Tue Feb 22 23:02:44 2011
@@ -855,76 +855,6 @@ public class Rdn implements Cloneable, E
 
 
     /**
-     * Compares two RDNs. They are equals if :
-     * <li>their have the same number of NC (AttributeTypeAndValue)
-     * <li>each ATAVs are equals
-     * <li>comparison of type are done case insensitive
-     * <li>each value is equal, case sensitive
-     * <li>Order of ATAV is not important If the RDNs are not equals, a positive number
is
-     * returned if the first Rdn is greater, negative otherwise
-     *
-     * @param rdn the Rdn to be compared
-     * @return 0 if both RDNs are equals. -1 if the current Rdn is inferior, 1 if
-     *         the current Rdn is superior, UNDEFINED otherwise.
-     *
-    public int compareTo( Rdn rdn )
-    {
-        if ( rdn == null )
-        {
-            return SUPERIOR;
-        }
-
-        if ( rdn.nbAtavs != nbAtavs )
-        {
-            // We don't have the same number of ATAVs. The Rdn which
-            // has the higher number of Atav is the one which is
-            // superior
-            return nbAtavs - rdn.nbAtavs;
-        }
-
-        switch ( nbAtavs )
-        {
-            case 0:
-                return EQUAL;
-
-            case 1:
-                return atav.compareTo( rdn.atav );
-
-            default:
-                // We have more than one value. We will
-                // go through all of them.
-
-                // the types are already normalized and sorted in the atavs TreeSet
-                // so we could compare the 1st with the 1st, then the 2nd with the 2nd, etc.
-                Iterator<Ava> localIterator = atavs.iterator();
-                Iterator<Ava> paramIterator = rdn.atavs.iterator();
-
-                while ( localIterator.hasNext() || paramIterator.hasNext() )
-                {
-                    if ( !localIterator.hasNext() )
-                    {
-                        return SUPERIOR;
-                    }
-                    if ( !paramIterator.hasNext() )
-                    {
-                        return INFERIOR;
-                    }
-
-                    Ava localAtav = localIterator.next();
-                    Ava paramAtav = paramIterator.next();
-                    int result = localAtav.compareTo( paramAtav );
-                    if ( result != EQUAL )
-                    {
-                        return result;
-                    }
-                }
-
-                return EQUAL;
-        }
-    }
-
-
-    /**
      * @return the user provided name
      */
     public String getName()



Mime
View raw message