Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 84717 invoked from network); 4 Jun 2006 16:46:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Jun 2006 16:46:48 -0000 Received: (qmail 46484 invoked by uid 500); 4 Jun 2006 16:46:48 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 46446 invoked by uid 500); 4 Jun 2006 16:46:47 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 46435 invoked by uid 99); 4 Jun 2006 16:46:47 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Jun 2006 09:46:47 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Jun 2006 09:46:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CFBF71A983A; Sun, 4 Jun 2006 09:46:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060604164626.CFBF71A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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" ); } }