directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
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 GMT
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<RDN>();
 
             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() );
+    }
 }



Mime
View raw message