directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1084411 - in /directory: apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/ shared/trunk/ldap/model/src/main...
Date Tue, 22 Mar 2011 23:37:52 GMT
Author: elecharny
Date: Tue Mar 22 23:37:52 2011
New Revision: 1084411

URL: http://svn.apache.org/viewvc?rev=1084411&view=rev
Log:
First round of cleanup for the Dn class :
o Removed the normalizeInternal() method
o Removed the toNormName() method
o Used the normalize(SchemaManager) method instead

Modified:
    directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java?rev=1084411&r1=1084410&r2=1084411&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java
(original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java
Tue Mar 22 23:37:52 2011
@@ -33,6 +33,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
@@ -180,7 +181,15 @@ public class ServerEntrySerializer imple
             {
                 Rdn rdn = new Rdn( schemaManager );
                 rdn.readExternal( in );
-                entry.setDn( new Dn( schemaManager, rdn ) );
+                
+                try
+                {
+                    entry.setDn( new Dn( schemaManager, rdn ) );
+                }
+                catch ( LdapInvalidDnException lide )
+                {
+                    throw new IOException( lide.getMessage() );
+                }
             }
             else
             {

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java?rev=1084411&r1=1084410&r2=1084411&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
Tue Mar 22 23:37:52 2011
@@ -1803,7 +1803,7 @@ public class DnTest
 
         name = name.add( "ou=East" );
 
-        assertFalse( name.isNormalized() );
+        assertTrue( name.isNormalized() );
 
         assertEquals( name4, name );
 
@@ -2078,12 +2078,10 @@ public class DnTest
     @Test
     public void testLdapNameHashCode() throws Exception
     {
-        Dn name1 = Dn
-            .normalize( schemaManager,
+        Dn name1 = new Dn( schemaManager,
                     "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent
= eXample,0.9.2342.19200300.100.1.25= cOm" );
 
-        Dn name2 = Dn
-            .normalize( schemaManager,
+        Dn name2 = new Dn( schemaManager,
                     "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com"
);
 
         assertEquals( name1.hashCode(), name2.hashCode() );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1084411&r1=1084410&r2=1084411&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
Tue Mar 22 23:37:52 2011
@@ -281,16 +281,7 @@ public class Dn implements Iterable<Rdn>
         upName = sb.toString();
         parseInternal( upName, rdns );
 
-        if ( schemaManager != null )
-        {
-            this.schemaManager = schemaManager;
-            normalize( schemaManager );
-        }
-        else
-        {
-            normalized = false;
-            normalizeInternal();
-        }
+        normalize( schemaManager );
     }
 
 
@@ -320,7 +311,7 @@ public class Dn implements Iterable<Rdn>
      *
      * @param rdns the list of Rdns to be used for the Dn
      */
-    public Dn( Rdn... rdns )
+    public Dn( Rdn... rdns ) throws LdapInvalidDnException
     {
         if ( rdns == null )
         {
@@ -332,7 +323,7 @@ public class Dn implements Iterable<Rdn>
             this.rdns.add( rdn.clone() );
         }
 
-        normalizeInternal();
+        normalize( null );
         toUpName();
         normalized = false;
     }
@@ -357,21 +348,7 @@ public class Dn implements Iterable<Rdn>
         
         rdns.add( rdn );
         
-        schemaManager = dn.schemaManager;
-
-        if ( schemaManager != null )
-        {
-            normalize( schemaManager );
-        }
-        else
-        {
-            normalized = false;
-
-            // Stores the representations of a Dn : internal (as a string and as a
-            // byte[]) and external.
-            normalizeInternal();
-        }
-
+        normalize( dn.schemaManager );
         toUpName();
     }
 
@@ -393,21 +370,7 @@ public class Dn implements Iterable<Rdn>
             rdns.add( rdnParent );
         }
         
-        this.schemaManager = schemaManager;
-
-        if ( schemaManager != null )
-        {
-            normalize( schemaManager );
-        }
-        else
-        {
-            normalized = false;
-
-            // Stores the representations of a Dn : internal (as a string and as a
-            // byte[]) and external.
-            normalizeInternal();
-        }
-
+        normalize( schemaManager );
         toUpName();
     }
 
@@ -418,7 +381,7 @@ public class Dn implements Iterable<Rdn>
      *  @param schemaManager The SchemaManager to use
      * @param rdns the list of Rdns to be used for the Dn
      */
-    public Dn( SchemaManager schemaManager, Rdn... rdns )
+    public Dn( SchemaManager schemaManager, Rdn... rdns ) throws LdapInvalidDnException
     {
         if ( rdns == null )
         {
@@ -430,65 +393,13 @@ public class Dn implements Iterable<Rdn>
             this.rdns.add( rdn.clone() );
         }
 
-        try
-        {
-            normalized = false;
-            
-            if ( this.schemaManager == null )
-            {
-                this.schemaManager = schemaManager;
-            }
-
-            normalize( this.schemaManager );
-            toUpName();
-        }
-        catch( LdapInvalidDnException lide )
-        {
-            throw new IllegalArgumentException( lide.getMessage() );
-        }
-    }
-
-
-    /**
-     * Static factory which creates a normalized Dn from a String and a Map of OIDs.
-     * <br>
-     * This method is for test purpose only, and as it's package protected, won't be usable
-     * out of this scope.
-     *
-     * @param name The Dn as a String
-     * @param oidsMap The OID mapping
-     * @return A valid Dn
-     * @throws LdapInvalidNameException If the Dn is invalid.
-     * @throws LdapInvalidDnException If something went wrong.
-     */
-    public static Dn normalize( SchemaManager schemaManager, String name )
-        throws LdapInvalidDnException
-    {
-        if ( ( name == null ) || ( name.length() == 0 ) || ( schemaManager == null ) )
-        {
-            return Dn.EMPTY_DN;
-        }
-
-        Dn newDn = new Dn( name );
-
-        for ( Rdn rdn : newDn.rdns )
-        {
-            String upName = rdn.getName();
-            rdnOidToName( rdn, schemaManager );
-            rdn.normalize();
-            rdn.setUpName( upName );
-        }
-
-        newDn.normalizeInternal();
-        newDn.normalized = true;
-
-        return newDn;
+        normalize( schemaManager );
     }
 
 
     /**
      * Normalize the Dn by triming useless spaces and lowercasing names.
-     */
+     *
     void normalizeInternal()
     {
         normName = toNormName();
@@ -499,7 +410,7 @@ public class Dn implements Iterable<Rdn>
      * Build the normalized Dn as a String,
      *
      * @return A String representing the normalized Dn
-     */
+     *
     private String toNormName()
     {
         if ( rdns.size() == 0 )
@@ -768,11 +679,6 @@ public class Dn implements Iterable<Rdn>
      */
     public String getNormName()
     {
-        if ( normName == null )
-        {
-            normName = toNormName();
-        }
-
         return normName;
     }
 
@@ -1065,8 +971,7 @@ public class Dn implements Iterable<Rdn>
         }
 
         newDn.toUpName();
-        newDn.toNormName();
-        newDn.normalized = normalized;
+        newDn.normalize( schemaManager );
 
         return newDn;
     }
@@ -1147,8 +1052,7 @@ public class Dn implements Iterable<Rdn>
         }
 
         newDn.toUpName();
-        newDn.toNormName();
-        newDn.normalized = normalized;
+        newDn.normalize( schemaManager );
 
         return newDn;
     }
@@ -1179,7 +1083,15 @@ public class Dn implements Iterable<Rdn>
             newDn.rdns.add( rdns.get( i ).clone() );
         }
 
-        newDn.normName = newDn.toNormName();
+        try
+        {
+            newDn.normalize( schemaManager );
+        }
+        catch ( LdapInvalidDnException lide )
+        {
+            // Do nothing
+        }
+        
         newDn.upName = getUpNameSuffix( posn );
 
         return newDn;
@@ -1278,18 +1190,7 @@ public class Dn implements Iterable<Rdn>
         }
         else
         {
-            if ( schemaManager != null )
-            {
-                clonedDn.normalize( schemaManager );
-
-                normalizeInternal();
-            }
-            else
-            {
-                clonedDn.normalizeInternal();
-                clonedDn.normalized = false;
-            }
-
+            clonedDn.normalize( schemaManager );
             clonedDn.toUpName();
         }
 
@@ -1314,18 +1215,9 @@ public class Dn implements Iterable<Rdn>
 
         clonedDn.rdns.add( 0, newRdn );
 
-        if ( schemaManager != null )
-        {
-            clonedDn.normalize( schemaManager );
-        }
-        else
-        {
-            clonedDn.normalizeInternal();
-            clonedDn.normalized = false;
-        }
+        clonedDn.normalize( schemaManager );
 
         clonedDn.toUpName();
-        clonedDn.toNormName();
 
         return clonedDn;
     }
@@ -1348,22 +1240,7 @@ public class Dn implements Iterable<Rdn>
         // instead this method should throw the LdapInvalidDnException
         try
         {
-            if ( clonedDn.isNormalized() && newRdn.isSchemaAware() )
-            {
-                clonedDn.normalizeInternal();
-            }
-            else
-            {
-                if ( schemaManager != null )
-                {
-                    clonedDn.normalize( schemaManager );
-                }
-                else
-                {
-                    clonedDn.normalizeInternal();
-                    clonedDn.normalized = false;
-                }
-            }
+            clonedDn.normalize( schemaManager );
         }
         catch ( LdapInvalidDnException e )
         {
@@ -1429,7 +1306,15 @@ public class Dn implements Iterable<Rdn>
             newDn.rdns.add( rdns.get( i ).clone() );
         }
 
-        newDn.normName = newDn.toNormName();
+        try
+        {
+            newDn.normalize( schemaManager );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            LOG.error( e.getMessage(), e );
+        }
+
         newDn.upName = getUpNamePrefix( posn );
         newDn.normalized = normalized;
 
@@ -1591,40 +1476,88 @@ public class Dn implements Iterable<Rdn>
      */
     public Dn normalize( SchemaManager schemaManager ) throws LdapInvalidDnException
     {
-        if ( this.schemaManager == null )
-        {
-            this.schemaManager = schemaManager;
-        }
+        this.schemaManager = schemaManager;
 
         if ( this.schemaManager != null )
         {
-            if ( normalized )
-            {
-                return this;
-            }
-
             synchronized ( this )
             {
                 if ( size() == 0 )
                 {
                     normalized = true;
+                    bytes = null;
+                    normName = "";
+                    
                     return this;
                 }
 
+                StringBuffer sb = new StringBuffer();
+                boolean isFirst = true;
+
                 for ( Rdn rdn : rdns )
                 {
                     rdn.applySchemaManager( schemaManager );
+
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
+                    else
+                    {
+                        sb.append( ',' );
+                    }
+
+                    sb.append( rdn.getNormName() );
                 }
 
-                normalizeInternal();
+                String newNormName = sb.toString();
+
+                if ( ( normName == null ) || !normName.equals( newNormName ) )
+                {
+                    bytes = Strings.getBytesUtf8(newNormName);
+                    normName = newNormName;
+                }
 
                 normalized = true;
 
                 return this;
             }
         }
+        else
+        {
+            if ( rdns.size() == 0 )
+            {
+                bytes = null;
+                normName = "";
+            }
+            else
+            {
+                StringBuffer sb = new StringBuffer();
+                boolean isFirst = true;
+
+                for ( Rdn rdn : rdns )
+                {
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
+                    else
+                    {
+                        sb.append( ',' );
+                    }
 
-        normalizeInternal();
+                    sb.append( rdn.getNormName() );
+                }
+
+                String newNormName = sb.toString();
+
+                if ( ( normName == null ) || !normName.equals( newNormName ) )
+                {
+                    bytes = Strings.getBytesUtf8(newNormName);
+                    normName = newNormName;
+                }
+            }
+        }
 
         return this;
     }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java?rev=1084411&r1=1084410&r2=1084411&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
Tue Mar 22 23:37:52 2011
@@ -68,7 +68,7 @@ import org.apache.directory.shared.util.
     {
         parseDn(name, dn.rdns);
         dn.setUpName( name );
-        dn.normalizeInternal();
+        dn.normalize( null );
     }
     
     



Mime
View raw message