directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r359025 - /directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DnComparator.java
Date Mon, 26 Dec 2005 00:37:08 GMT
Author: elecharny
Date: Sun Dec 25 16:37:03 2005
New Revision: 359025

URL: http://svn.apache.org/viewcvs?rev=359025&view=rev
Log:
Huge refactoring of this class.
The comparizon now relies on LdapDN class.

Modified:
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DnComparator.java

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DnComparator.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DnComparator.java?rev=359025&r1=359024&r2=359025&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DnComparator.java
(original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DnComparator.java
Sun Dec 25 16:37:03 2005
@@ -20,135 +20,44 @@
 import java.util.Comparator ;
 
 import javax.naming.Name ;
-import javax.naming.NameParser ;
-import javax.naming.NamingException ;
+import javax.naming.NamingException;
 
-import org.apache.ldap.common.name.DnParser ;
-import org.apache.ldap.common.name.NameComponentNormalizer;
+import org.apache.ldap.common.name.LdapDN;
 
 
 /**
- * A DnComparator that uses a parser to parse Dn strings.  The parser may
- * or may not be Schema enabled.
+ * A DnComparator that works on two LdapDN objects
  *
- * @todo start using some kinda name cache here; it is way too expensive to be
- *       doing this over and over again
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
  */
 public class DnComparator implements Comparator
 {
-    /** The parser used to parse DN Strings */
-    private NameParser parser ;
-    
-    private static final Object parserMutex = new Object();
-    
-    
-    // ------------------------------------------------------------------------
-    // C O N S T R U C T O R S
-    // ------------------------------------------------------------------------
-
-
-    /**
-     * Creates a default schema-less DN Comparator whose parser does not attempt
-     * to normalize assertion valeus while comparing DN components.
-     */
-    public DnComparator() throws NamingException
-    {
-        synchronized ( parserMutex )
-        {
-            parser = new DnParser() ;
-        }
-    }
-    
-    
     /**
      * Creates a DN Comparator using a name component normalizer which should
      * use schema normalizers for attribute equality matching rules to
      * normalize assertion values.
      */
-    public DnComparator( NameComponentNormalizer normalizer ) throws NamingException
+    public DnComparator() throws NamingException
     {
-        synchronized ( parserMutex )
-        {
-            parser = new DnParser( normalizer ) ;
-        }
     }
-    
-    
-    // ------------------------------------------------------------------------
-    // Comparator Methods
-    // ------------------------------------------------------------------------
-    
-    
+
     /**
+     * The comparator is working on LdapDN objects, nothing else.
      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
      */
     public int compare( Object obj1, Object obj2 )
     {
-        Name dn1 = null ;
-        Name dn2 = null ;
+        Name dn1 = (LdapDN)obj1;
+        Name dn2 = (LdapDN)obj2;
         
-        // Figure out how to compose the Name for the first object
-        if ( obj1 instanceof Name )
-        {
-            dn1 = ( Name ) obj1 ;
-        }
-        else if ( obj1 instanceof String )
-        {
-        	// Speedup the comparison
-        	if ( ((String)obj1).compareTo((String)obj2) == 0)
-        	{
-        		return 0;
-        	}
-        	else
-        	{
-	            try
-	            {
-                    synchronized ( parserMutex )
-                    {
-                        dn1 = parser.parse( ( String ) obj1 ) ;
-                    }
-	            }
-	            catch ( NamingException ne )
-	            {
-	                throw new IllegalArgumentException( 
-	                    "first argument (" + obj1 + ") was not a distinguished name" ) ;
-	            }
-        	}
-        }
-        else
-        {
-            throw new IllegalArgumentException( 
-                "first argument (" + obj1 + ") was not a Name or a String" ) ;
-        }
-
-        // Figure out how to compose the Name for the second object
-        if ( obj2 instanceof Name )
-        {
-            dn2 = ( Name ) obj2 ;
-        }
-        else if ( obj2 instanceof String )
-        {
-            try
-            {
-                synchronized ( parserMutex )
-                {
-                    dn2 = parser.parse( ( String ) obj2 ) ;
-                }
-            }
-            catch ( NamingException ne )
-            {
-                throw new IllegalArgumentException( 
-                    "second argument was not a distinguished name" ) ;
-            }
-        }
-        else
-        {
-            throw new IllegalArgumentException( 
-                "second argument was not a distinguished name" ) ;
-        }
-
         return dn1.compareTo( dn2 ) ;
+    }
+    
+    /**
+     * A String representation of this class
+     */
+    public String toString()
+    {
+    	return "Dn comparator";
     }
 }



Mime
View raw message