directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r966205 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap: name/ schema/comparators/ schema/normalizers/
Date Wed, 21 Jul 2010 12:24:49 GMT
Author: kayyagari
Date: Wed Jul 21 12:24:48 2010
New Revision: 966205

URL: http://svn.apache.org/viewvc?rev=966205&view=rev
Log:
o made DN and RDN classes schema aware
o removed call to DN.normalize(oidMap) wherever possible

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.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=966205&r1=966204&r2=966205&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 Jul 21 12:24:48 2010
@@ -41,6 +41,7 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.shared.ldap.util.UTFUtils;
@@ -110,6 +111,8 @@ public class DN implements Cloneable, Se
     /** A null DN */
     public static final DN EMPTY_DN = new DN();
 
+    /** the schema manager */
+    private transient SchemaManager schemaManager;
 
     // ~ Methods
     // ------------------------------------------------------------------------------------
@@ -119,20 +122,42 @@ public class DN implements Cloneable, Se
      */
     public DN()
     {
+        this( ( SchemaManager ) null );
+    }
+
+    
+    /**
+     * Construct an empty DN object
+     */
+    public DN( SchemaManager schemaManger )
+    {
+        this.schemaManager = schemaManger;
         upName = "";
         normName = null;
         normalized = true;
     }
 
+    
+    /**
+     * @see #DN(DN, SchemaManager)
+     */
+    public DN( DN dn ) throws LdapInvalidDnException
+    {
+       this( dn, null);
+    }
+
 
     /**
      * Copies a DN to an DN.
      *
      * @param dn composed of String name components.
+     * @param schemaManager the schema manager
      * @throws LdapInvalidDnException If the Name is invalid.
      */
-    public DN( DN dn ) throws LdapInvalidDnException
+    public DN( DN dn, SchemaManager schemaManager ) throws LdapInvalidDnException
     {
+        this.schemaManager = schemaManager;
+
         if ( ( dn != null ) && ( dn.size() != 0 ) )
         {
             for ( int ii = 0; ii < dn.size(); ii++ )
@@ -142,10 +167,17 @@ public class DN implements Cloneable, Se
             }
         }
 
-        normalized = false;
+        if( schemaManager != null )
+        {
+            normalized = true;
+        }
+        else
+        {
+            normalized = false;
+        }
     }
 
-
+    
     /**
      * Parse a String and checks that it is a valid DN <br>
      * <p>
@@ -160,20 +192,45 @@ public class DN implements Cloneable, Se
      */
     public DN( String upName ) throws LdapInvalidDnException
     {
+        this( upName, null );
+    }
+
+
+    
+    public DN( String upName, SchemaManager schemaManager ) throws LdapInvalidDnException
+    {
         if ( upName != null )
         {
             DnParser.parseInternal( upName, rdns );
         }
+        
+        if( schemaManager != null )
+        {
+            this.schemaManager = schemaManager;
+            normalize( schemaManager.getNormalizerMapping() );
+            normalized = true;
+        }
+        else
+        {
+            normalized = false;
 
-        // Stores the representations of a DN : internal (as a string and as a
-        // byte[]) and external.
-        normalizeInternal();
-        normalized = false;
+            // Stores the representations of a DN : internal (as a string and as a
+            // byte[]) and external.
+            normalizeInternal();
+        }
 
         this.upName = upName;
     }
 
+    /**
+     * @see #DN(SchemaManager, String...)
+     */
+    public DN( String... upRdns ) throws LdapInvalidDnException
+    {
+        this( null, upRdns );
+    }
 
+    
     /**
      * Creates a new instance of DN, using varargs to declare the RDNs. Each
      * String is either a full RDN, or a couple of AttributeType DI and a value.
@@ -191,10 +248,11 @@ public class DN implements Cloneable, Se
      *     baseDn);
      * </pre>
      *
+     * @param schemaManager the schema manager
      * @param upRdns
      * @throws LdapInvalidDnException
      */
-    public DN( String... upRdns ) throws LdapInvalidDnException
+    public DN( SchemaManager schemaManager, String... upRdns ) throws LdapInvalidDnException
     {
         StringBuilder sb = new StringBuilder();
         boolean valueExpected = false;
@@ -237,10 +295,21 @@ public class DN implements Cloneable, Se
         // byte[]) and external.
         upName = sb.toString();
         DnParser.parseInternal( upName, rdns );
-        normalizeInternal();
-        normalized = false;
+        
+        if( schemaManager != null )
+        {
+            this.schemaManager = schemaManager;
+            normalize( schemaManager.getNormalizerMapping() );
+            normalized = true;
+        }
+        else
+        {
+            normalized = false;
+            normalizeInternal();
+        }
     }
     
+
     /**
      * Create a DN when deserializing it.
      * 
@@ -269,7 +338,7 @@ public class DN implements Cloneable, Se
      */
     public static DN normalize( String name, Map<String, OidNormalizer> oidsMap ) throws
LdapInvalidDnException
     {
-        if ( ( name == null ) || ( name.length() == 0 ) || ( oidsMap == null ) || ( oidsMap.size()
== 0 ) )
+        if ( ( name == null ) || ( name.length() == 0 ) || ( oidsMap == null ) || ( oidsMap.isEmpty()
) )
         {
             return DN.EMPTY_DN;
         }
@@ -1102,7 +1171,7 @@ public class DN implements Cloneable, Se
         try
         {
             // We have to parse the nameComponent which is given as an argument
-            RDN newRdn = new RDN( comp );
+            RDN newRdn = new RDN( comp, schemaManager );
             
             rdns.add( 0, newRdn );
         }
@@ -1526,7 +1595,8 @@ public class DN implements Cloneable, Se
      */
     public DN normalize( Map<String, OidNormalizer> oidsMap ) throws LdapInvalidDnException
     {
-        if ( ( oidsMap == null ) || ( oidsMap.size() == 0 ) )
+        
+        if ( ( oidsMap == null ) || ( oidsMap.isEmpty() ) )
         {
             return this;
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java?rev=966205&r1=966204&r2=966205&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
Wed Jul 21 12:24:48 2010
@@ -37,6 +37,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.shared.ldap.util.UTFUtils;
@@ -187,15 +189,31 @@ public class RDN implements Cloneable, C
     /** A flag used to tell if the RDN has been normalized */
     private boolean normalized;
 
+    /** the schema manager */
+    private transient SchemaManager schemaManager;
+
 
     /**
      * A empty constructor.
      */
     public RDN()
     {
+        this( ( SchemaManager ) null );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of RDN.
+     *
+     * @param schemaManager the schema manager
+     */
+    public RDN( SchemaManager schemaManager )
+    {
         // Don't waste space... This is not so often we have multiple
         // name-components in a RDN... So we won't initialize the Map and the
         // treeSet.
+        this.schemaManager = schemaManager;
         upName = "";
         normName = "";
         normalized = false;
@@ -206,9 +224,10 @@ public class RDN implements Cloneable, C
      * A constructor that parse a String representing a RDN.
      *
      * @param rdn The String containing the RDN to parse
+     * @param schemaManager the schema manager
      * @throws LdapInvalidDnException If the RDN is invalid
      */
-    public RDN( String rdn ) throws LdapInvalidDnException
+    public RDN( String rdn, SchemaManager schemaManager ) throws LdapInvalidDnException
     {
         start = 0;
 
@@ -219,7 +238,18 @@ public class RDN implements Cloneable, C
 
             // create the internal normalized form
             // and store the user provided form
-            normalize();
+            if ( schemaManager != null )
+            {
+                this.schemaManager = schemaManager;
+                normalize( schemaManager.getNormalizerMapping() );
+                normalized = true;
+            }
+            else
+            {
+                normalize();
+                normalized = false;
+            }
+
             upName = rdn;
             length = rdn.length();
         }
@@ -228,9 +258,20 @@ public class RDN implements Cloneable, C
             upName = "";
             normName = "";
             length = 0;
+            normalized = false;
         }
+    }
 
-        normalized = false;
+
+    /**
+     * A constructor that parse a String representing a RDN.
+     *
+     * @param rdn The String containing the RDN to parse 
+     * @throws LdapInvalidDnException
+     */
+    public RDN( String rdn ) throws LdapInvalidDnException
+    {
+        this( rdn, ( SchemaManager ) null );
     }
 
 
@@ -244,23 +285,43 @@ public class RDN implements Cloneable, C
      * @param upValue The user provided value of the RDN
      * @param normType The normalized provided type of the RDN
      * @param normValue The normalized provided value of the RDN
+     * @param schemaManager the schema manager
      * @throws LdapInvalidDnException If the RDN is invalid
      */
-    public RDN( String upType, String normType, String upValue, String normValue ) throws
LdapInvalidDnException
+    public RDN( String upType, String normType, String upValue, String normValue, SchemaManager
schemaManager ) throws LdapInvalidDnException
     {
+        this.schemaManager = schemaManager;
+
         addAttributeTypeAndValue( upType, normType, new StringValue( upValue ), new StringValue(
normValue ) );
 
         upName = upType + '=' + upValue;
         start = 0;
         length = upName.length();
+        
         // create the internal normalized form
         normalize();
-        
-        // As strange as it seems, the RDN is *not* normalized against the schema at this
point
-        normalized = false;
+
+        if( schemaManager != null )
+        {
+            normalized = true;
+        }
+        else
+        {
+            // As strange as it seems, the RDN is *not* normalized against the schema at
this point
+            normalized = false;
+        }
     }
 
+    
+    /**
+     * @see #RDN(String, String, String, String, SchemaManager)
+     */
+    public RDN( String upType, String normType, String upValue, String normValue ) throws
LdapInvalidDnException
+    {
+        this( upType, normType, upValue, normValue, null );
+    }
 
+    
     /**
      * A constructor that constructs a RDN from a type and a value. Constructs
      * an Rdn from the given attribute type and value. The string attribute
@@ -269,22 +330,42 @@ public class RDN implements Cloneable, C
      *
      * @param upType The user provided type of the RDN
      * @param upValue The user provided value of the RDN
+     * @param schemaManager the schema manager
      * @throws LdapInvalidDnException If the RDN is invalid
      */
-    public RDN( String upType, String upValue ) throws LdapInvalidDnException
+    public RDN( String upType, String upValue, SchemaManager schemaManager ) throws LdapInvalidDnException
     {
         addAttributeTypeAndValue( upType, upType, new StringValue( upValue ), new StringValue(
upValue ) );
 
         upName = upType + '=' + upValue;
         start = 0;
         length = upName.length();
-        // create the internal normalized form
-        normalize();
         
-        // As strange as it seems, the RDN is *not* normalized against the schema at this
point
-        normalized = false;
+        if( schemaManager != null )
+        {
+            this.schemaManager = schemaManager;
+            normalize( schemaManager.getNormalizerMapping() );
+            normalized = true;
+        }
+        else
+        {
+            // create the internal normalized form
+            normalize();
+            
+            // As strange as it seems, the RDN is *not* normalized against the schema at
this point
+            normalized = false;
+        }
     }
 
+    
+    /**
+     * @see #RDN(String, String, SchemaManager)
+     */
+    public RDN( String upType, String upValue ) throws LdapInvalidDnException
+    {
+        this( upType, upValue, null );
+    }
+    
 
     /**
      * A constructor that constructs a RDN from a type, a position and a length.
@@ -300,7 +381,7 @@ public class RDN implements Cloneable, C
         this.length = length;
         this.upName = upName;
         this.normName = normName;
-        normalized = false;
+        normalized = true;            
     }
 
 
@@ -407,7 +488,7 @@ public class RDN implements Cloneable, C
      * Transform a RDN by changing the value to its OID counterpart and
      * normalizing the value accordingly to its type.
      *
-     * @param oidsMap The map of all existing oids and normalizer.
+     * @param oidsMap The mapping between names and oids.
      * @throws LdapException If the RDN is invalid.
      */
     public RDN normalize( Map<String, OidNormalizer> oidsMap ) throws LdapInvalidDnException
@@ -439,14 +520,28 @@ public class RDN implements Cloneable, C
         Value<?> value ) throws LdapInvalidDnException
     {
         // First, let's normalize the type
-        String normalizedType = StringTools.lowerCaseAscii( type );
         Value<?> normalizedValue = value;
+        String normalizedType = StringTools.lowerCaseAscii( type );
+        
+        if( schemaManager != null )
+        {
+            OidNormalizer oidNormalizer = schemaManager.getNormalizerMapping().get( normalizedType
);
+            normalizedType = oidNormalizer.getAttributeTypeOid();
+            try
+            {
+                normalizedValue = oidNormalizer.getNormalizer().normalize( value );
+            }
+            catch( LdapException e )
+            {
+                throw new LdapInvalidDnException( e.getMessage() );
+            }
+        }
 
         switch ( nbAtavs )
         {
             case 0:
                 // This is the first AttributeTypeAndValue. Just stores it.
-                atav = new AVA( upType, type, upValue, normalizedValue );
+                atav = new AVA( upType, normalizedType, upValue, normalizedValue );
                 nbAtavs = 1;
                 atavType = normalizedType;
                 return;
@@ -469,7 +564,7 @@ public class RDN implements Cloneable, C
 
             default:
                 // add a new AttributeTypeAndValue
-                AVA newAtav = new AVA( upType, type, upValue, normalizedValue );
+                AVA newAtav = new AVA( upType, normalizedType, upValue, normalizedValue );
                 atavs.add( newAtav );
                 atavTypes.put( normalizedType, newAtav );
 
@@ -1310,8 +1405,8 @@ public class RDN implements Cloneable, C
 
         return escapeValue( value );
     }
-    
-    
+
+
     /**
      * Tells if the RDN has already been normalized or not
      *

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java?rev=966205&r1=966204&r2=966205&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java
Wed Jul 21 12:24:48 2010
@@ -80,8 +80,7 @@ public class DnComparator extends LdapCo
         }
         else if ( obj instanceof String )
         {
-            dn = new DN( ( String ) obj );
-            dn.normalize( schemaManager.getNormalizerMapping() );
+            dn = new DN( ( String ) obj, schemaManager );
         }
         else
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java?rev=966205&r1=966204&r2=966205&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
Wed Jul 21 12:24:48 2010
@@ -169,8 +169,7 @@ public class UniqueMemberComparator exte
         }
         else if ( obj instanceof String )
         {
-            dn = new DN( ( String ) obj );
-            dn.normalize( schemaManager.getNormalizerMapping() );
+            dn = new DN( ( String ) obj, schemaManager );
         }
         else
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java?rev=966205&r1=966204&r2=966205&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java
Wed Jul 21 12:24:48 2010
@@ -60,9 +60,8 @@ public class DnNormalizer extends Normal
         
         String dnStr = value.getString();
         
-        dn = new DN( dnStr );
+        dn = new DN( dnStr, schemaManager );
         
-        dn.normalize( schemaManager.getNormalizerMapping() );
         return new StringValue( dn.getNormName() );
     }
 
@@ -74,9 +73,8 @@ public class DnNormalizer extends Normal
     {
         DN dn = null;
         
-        dn = new DN( value );
+        dn = new DN( value, schemaManager );
         
-        dn.normalize( schemaManager.getNormalizerMapping() );
         return dn.getNormName();
     }
 
@@ -91,9 +89,8 @@ public class DnNormalizer extends Normal
     {
         DN dn = null;
         
-        dn = new DN( value );
+        dn = new DN( value, schemaManager );
         
-        dn.normalize( schemaManager.getNormalizerMapping() );
         return dn.getNormName();
     }
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java?rev=966205&r1=966204&r2=966205&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java
Wed Jul 21 12:24:48 2010
@@ -80,9 +80,7 @@ public class UniqueMemberNormalizer exte
             
             if ( sharpPos > 0 )
             {
-                DN dn = new DN( nameAndUid.substring( 0, sharpPos ) );
-                
-                dn.normalize( schemaManager.getNormalizerMapping() );
+                DN dn = new DN( nameAndUid.substring( 0, sharpPos ), schemaManager );
                 
                 return new StringValue( dn.getNormName() + '#' + uid );
             }
@@ -127,9 +125,7 @@ public class UniqueMemberNormalizer exte
             
             if ( sharpPos > 0 )
             {
-                DN dn = new DN( value.substring( 0, sharpPos ) );
-                
-                dn.normalize( schemaManager.getNormalizerMapping() );
+                DN dn = new DN( value.substring( 0, sharpPos ), schemaManager );
                 
                 return dn.getNormName() + '#' + uid;
             }
@@ -142,7 +138,7 @@ public class UniqueMemberNormalizer exte
         {
             // No UID, the strValue is a DN
             // Return the normalized DN
-            return new DN( value ).normalize( schemaManager.getNormalizerMapping() ).getNormName();
+            return new DN( value, schemaManager ).getNormName();
         }
     }
 



Mime
View raw message