You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/08/03 15:32:30 UTC

svn commit: r981868 - /directory/shared/branches/shared-dnfactory-experiment/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java

Author: kayyagari
Date: Tue Aug  3 13:32:30 2010
New Revision: 981868

URL: http://svn.apache.org/viewvc?rev=981868&view=rev
Log:
o replaced 'normalized' flag with AtomicBoolean
o synchronized the normalize method
o added a new normalize() method which takes schema manager

Modified:
    directory/shared/branches/shared-dnfactory-experiment/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java

Modified: directory/shared/branches/shared-dnfactory-experiment/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-dnfactory-experiment/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java?rev=981868&r1=981867&r2=981868&view=diff
==============================================================================
--- directory/shared/branches/shared-dnfactory-experiment/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java (original)
+++ directory/shared/branches/shared-dnfactory-experiment/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java Tue Aug  3 13:32:30 2010
@@ -1156,7 +1156,7 @@ public class DN implements Cloneable, Se
             clonedDn.rdns.add( clonedDn.size() - posn, rdn );
         }
 
-        clonedDn.normalizeInternal();
+        clonedDn.normalize( schemaManager );
         clonedDn.toUpName();
 
         return clonedDn;
@@ -1190,7 +1190,7 @@ public class DN implements Cloneable, Se
         }
         else
         {
-            clonedDn.normalizeInternal();
+            clonedDn.normalize( schemaManager );
             clonedDn.toUpName();
         }
 
@@ -1214,7 +1214,7 @@ public class DN implements Cloneable, Se
         
         clonedDn.rdns.add( 0, newRdn );
         
-        clonedDn.normalizeInternal();
+        clonedDn.normalize( schemaManager );
         clonedDn.toUpName();
 
         return clonedDn;
@@ -1233,7 +1233,17 @@ public class DN implements Cloneable, Se
         
         clonedDn.rdns.add( 0, newRdn );
         
-        clonedDn.normalizeInternal();
+        // FIXME this try-catch block shouldn't be here
+        // instead this method should throw the LdapInvalidDnException
+        try
+        {
+            clonedDn.normalize( schemaManager );
+        }
+        catch( LdapInvalidDnException e )
+        {
+            LOG.error( e.getMessage(), e );
+        }
+        
         clonedDn.toUpName();
 
         return clonedDn;
@@ -1253,7 +1263,17 @@ public class DN implements Cloneable, Se
         
         clonedDn.rdns.add( newRdn );
         
-        clonedDn.normalizeInternal();
+        // FIXME this try-catch block shouldn't be here
+        // instead this method should throw the LdapInvalidDnException
+        try
+        {
+            clonedDn.normalize( schemaManager );
+        }
+        catch( LdapInvalidDnException e )
+        {
+            LOG.error( e.getMessage(), e );
+        }
+
         clonedDn.toUpName();
 
         return clonedDn;
@@ -1313,7 +1333,7 @@ public class DN implements Cloneable, Se
         int realPos = clonedDn.size() - posn;
         clonedDn.rdns.add( realPos, newRdn );
 
-        clonedDn.normalizeInternal();
+        clonedDn.normalize( schemaManager );
         clonedDn.toUpName();
 
         return clonedDn;
@@ -1617,10 +1637,18 @@ 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 )
         {
@@ -1648,6 +1676,33 @@ public class DN implements Cloneable, Se
         }
     }
 
+    
+    /**
+     * normalizes the DN @see {@link #normalize(Map)} however
+     * if the schema manager of the DN is null then sets the given schema manager
+     * as the DN's schema manager.
+     * 
+     * If both, the given schema manager and that of the DN are null then the
+     * {@link #normalizeInternal()} will be called. 
+     *
+     */
+    public DN normalize( SchemaManager schemaManager ) throws LdapInvalidDnException
+    {
+        if( this.schemaManager == null )
+        {
+            this.schemaManager = schemaManager;
+        }
+        
+        if( this.schemaManager != null )
+        {
+            return normalize( schemaManager.getNormalizerMapping() );
+        }
+
+        normalizeInternal();
+        
+        return this;
+    }
+    
 
     /**
      * Check if a DistinguishedName is syntactically valid.
@@ -1761,7 +1816,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 );