directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r411582 - in /directory/branches/shared/optimization/ldap/src: main/java/org/apache/directory/shared/ldap/name/LdapDN.java test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java
Date Sun, 04 Jun 2006 16:46:26 GMT
Author: akarasulu
Date: Sun Jun  4 09:46:25 2006
New Revision: 411582

URL: http://svn.apache.org/viewvc?rev=411582&view=rev
Log:
adding startsWith logic for testing a javax.naming.Name

Modified:
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java

Modified: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=411582&r1=411581&r2=411582&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
(original)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
Sun Jun  4 09:46:25 2006
@@ -536,6 +536,44 @@
 
             return true;
         }
+        else if ( name instanceof Name )
+        {
+            if ( name.size() == 0 )
+            {
+                return true;
+            }
+
+            if ( name.size() > size() )
+            {
+                // The name is longer than the current LdapDN.
+                return false;
+            }
+
+            // Ok, iterate through all the RDN of the name,
+            // starting a the end of the current list.
+
+            for ( int i = name.size() - 1; i >= 0; i-- )
+            {
+                Rdn ldapRdn = ( Rdn ) rdns.get( rdns.size() - i - 1 );
+                Rdn nameRdn = null;
+                try
+                {
+                    nameRdn = new Rdn( ( String ) name.get( name.size() - i - 1 ) );
+                }
+                catch ( InvalidNameException e )
+                {
+                    e.printStackTrace();
+                    log.error( "Failed to parse RDN for name " + name.toString(), e );
+                }
+                
+                if ( nameRdn.compareTo( ldapRdn ) != 0 )
+                {
+                    return false;
+                }
+            }
+
+            return true;
+        }
         else
         {
             // We don't accept a Name which is not a LdapName

Modified: directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java?rev=411582&r1=411581&r2=411582&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java
(original)
+++ directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java
Sun Jun  4 09:46:25 2006
@@ -20,8 +20,10 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import javax.naming.Name;
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
 
@@ -91,5 +93,20 @@
         args = NamespaceTools.getCompositeComponents( "cn=Alex" );
         assertEquals( "expecting one part : ", 1, args.length );
         assertEquals( "cn=Alex", args[0] );
+    }
+    
+    
+    public void testGetRelativeName() throws NamingException
+    {
+        // test the basis case first with the root
+        LdapDN ancestor = new LdapDN( "" );
+        LdapDN descendant = new LdapDN( "ou=system" );
+        Name relativeName = NamespaceTools.getRelativeName( ancestor, descendant );
+        assertEquals( relativeName.toString(), "ou=system" );
+        
+        ancestor = new LdapDN( "ou=system" );
+        descendant = new LdapDN( "ou=users,ou=system" );
+        relativeName = NamespaceTools.getRelativeName( ancestor, descendant );
+        assertEquals( relativeName.toString(), "ou=users" );
     }
 }



Mime
View raw message