Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 10924 invoked from network); 4 Aug 2010 09:16:16 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 4 Aug 2010 09:16:16 -0000 Received: (qmail 91168 invoked by uid 500); 4 Aug 2010 09:16:15 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 91119 invoked by uid 500); 4 Aug 2010 09:16:14 -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 91112 invoked by uid 99); 4 Aug 2010 09:16:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Aug 2010 09:16:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Aug 2010 09:16:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2DFA823889BB; Wed, 4 Aug 2010 09:14:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r982170 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/name/DN.java test/java/org/apache/directory/shared/ldap/name/DNTest.java Date: Wed, 04 Aug 2010 09:14:52 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100804091452.2DFA823889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kayyagari Date: Wed Aug 4 09:14:49 2010 New Revision: 982170 URL: http://svn.apache.org/viewvc?rev=982170&view=rev Log: o updated all addXXX() methods to appropriately set/reset 'normalized' flag after cloning the original DN o added a check to normalize(oidMap) method o added another test Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java?rev=982170&r1=982169&r2=982170&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java Wed Aug 4 09:14:49 2010 @@ -1156,7 +1156,16 @@ public class DN implements Cloneable, Se clonedDn.rdns.add( clonedDn.size() - posn, rdn ); } - clonedDn.normalize( schemaManager ); + if( schemaManager != null ) + { + clonedDn.normalize( schemaManager ); + } + else + { + clonedDn.normalizeInternal(); + clonedDn.normalized.set( false ); + } + clonedDn.toUpName(); return clonedDn; @@ -1190,7 +1199,16 @@ public class DN implements Cloneable, Se } else { - clonedDn.normalize( schemaManager ); + if( schemaManager != null ) + { + clonedDn.normalize( schemaManager ); + } + else + { + clonedDn.normalizeInternal(); + clonedDn.normalized.set( false ); + } + clonedDn.toUpName(); } @@ -1214,7 +1232,16 @@ public class DN implements Cloneable, Se clonedDn.rdns.add( 0, newRdn ); - clonedDn.normalize( schemaManager ); + if( schemaManager != null ) + { + clonedDn.normalize( schemaManager ); + } + else + { + clonedDn.normalizeInternal(); + clonedDn.normalized.set( false ); + } + clonedDn.toUpName(); return clonedDn; @@ -1237,7 +1264,22 @@ public class DN implements Cloneable, Se // instead this method should throw the LdapInvalidDnException try { - clonedDn.normalize( schemaManager ); + if( clonedDn.isNormalized() && newRdn.isNormalized() ) + { + clonedDn.normalizeInternal(); + } + else + { + if( schemaManager != null ) + { + clonedDn.normalize( schemaManager ); + } + else + { + clonedDn.normalizeInternal(); + clonedDn.normalized.set( false ); + } + } } catch( LdapInvalidDnException e ) { @@ -1267,7 +1309,22 @@ public class DN implements Cloneable, Se // instead this method should throw the LdapInvalidDnException try { - clonedDn.normalize( schemaManager ); + if( clonedDn.isNormalized() && newRdn.isNormalized() ) + { + clonedDn.normalizeInternal(); + } + else + { + if( schemaManager != null ) + { + clonedDn.normalize( schemaManager ); + } + else + { + clonedDn.normalizeInternal(); + clonedDn.normalized.set( false ); + } + } } catch( LdapInvalidDnException e ) { @@ -1333,7 +1390,16 @@ public class DN implements Cloneable, Se int realPos = clonedDn.size() - posn; clonedDn.rdns.add( realPos, newRdn ); - clonedDn.normalize( schemaManager ); + if( schemaManager != null ) + { + clonedDn.normalize( schemaManager ); + } + else + { + clonedDn.normalizeInternal(); + clonedDn.normalized.set( false ); + } + clonedDn.toUpName(); return clonedDn; @@ -1404,7 +1470,7 @@ public class DN implements Cloneable, Se try { DN dn = ( DN ) super.clone(); - dn.normalized = new AtomicBoolean( normalized.get() ); + dn.normalized = new AtomicBoolean( normalized.get() ); dn.rdns = new ArrayList(); for ( RDN rdn : rdns ) @@ -1638,18 +1704,10 @@ public class DN implements Cloneable, Se return this; } - /* having the below check improves perf but - * there are many places where a non-normalized RDN gets - * added to a normalized DN and when normalized is called on the new DN - * this check is preventing it from being normalized - * cause the cloned DN (right before adding new RDN(s) ) retains the - * original DN's 'normalized' status - if( normalized.get() ) { return this; } - */ synchronized ( this ) { @@ -1817,7 +1875,7 @@ public class DN implements Cloneable, Se } // A serialized DN is always normalized. - normalized.set( true ); + normalized = new AtomicBoolean( true ); // Should we read the byte[] ??? bytes = StringTools.getBytesUtf8( upName ); Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java?rev=982170&r1=982169&r2=982170&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java (original) +++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java Wed Aug 4 09:14:49 2010 @@ -2253,7 +2253,13 @@ public class DNTest assertEquals( name, new DN( "" ) ); DN name4 = new DN( "ou=East" ); + + assertTrue( name.isNormalized() ); + name = name.add( "ou=East" ); + + assertFalse( name.isNormalized() ); + assertEquals( name4, name ); DN name3 = new DN( "ou=Marketing,ou=East" ); @@ -3709,4 +3715,49 @@ public class DNTest assertTrue( dn.isChildOf( parent3 ) ); assertFalse( notParent.isChildOf( dn ) ); } + + + @Test + public void testNormalize() throws Exception + { + DN dn = new DN( "ou=system" ); + assertFalse( dn.isNormalized() ); + + dn = dn.add( "ou=users" ); + assertFalse( dn.isNormalized() ); + + dn.normalize( oidOids ); + assertTrue( dn.isNormalized() ); + + dn = dn.add( "ou=x" ); + assertFalse( dn.isNormalized() ); + + assertEquals( "ou=x,2.5.4.11=users,2.5.4.11=system", dn.getNormName() ); + assertEquals( "ou=x,ou=users,ou=system", dn.getName() ); + + dn.normalize( oidOids ); + assertEquals( "2.5.4.11=x,2.5.4.11=users,2.5.4.11=system", dn.getNormName() ); + assertEquals( "ou=x,ou=users,ou=system", dn.getName() ); + + RDN rdn = new RDN( "ou=system" ); + dn = new DN(); + assertTrue( dn.isNormalized() ); + + dn = dn.add( rdn ); + assertFalse( dn.isNormalized() ); + + dn.normalize( oidOids ); + assertTrue( dn.isNormalized() ); + + DN anotherDn = new DN( "ou=x,ou=users" ); + + dn = dn.addAll( anotherDn ); + assertFalse( dn.isNormalized() ); + + dn.normalize( oidOids ); + assertTrue( dn.isNormalized() ); + + dn = dn.remove( 0 ); + assertTrue( dn.isNormalized() ); + } }