directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1745847 - in /directory/shared/branches/shared-value/ldap/model/src/main: antlr/ java/org/apache/directory/api/ldap/model/name/
Date Sat, 28 May 2016 08:04:04 GMT
Author: elecharny
Date: Sat May 28 08:04:04 2016
New Revision: 1745847

URL: http://svn.apache.org/viewvc?rev=1745847&view=rev
Log:
Added the computation of a Normalized value for the Ava, Rdn and Dn class

Modified:
    directory/shared/branches/shared-value/ldap/model/src/main/antlr/distinguishedName.g
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/ComplexDnParser.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java

Modified: directory/shared/branches/shared-value/ldap/model/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/antlr/distinguishedName.g?rev=1745847&r1=1745846&r2=1745847&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/antlr/distinguishedName.g Sat
May 28 08:04:04 2016
@@ -163,6 +163,9 @@ options    {
         // The user provided value
         StringBuilder upValue = new StringBuilder();
 
+        // The normalized value
+        StringBuilder normValue = new StringBuilder();
+
         // A flag set to false if we have a binary value
         boolean isHR = true;
     }
@@ -201,7 +204,8 @@ distinguishedName [SchemaManager schemaM
         { 
             try
             { 
-                dn.add( rdn ); 
+                dn.add( rdn );
+                
             }
             catch ( LdapInvalidDnException lide )
             {
@@ -251,16 +255,18 @@ distinguishedName [SchemaManager schemaM
  * <optional-space> ::= ( <CR> ) *( " " )
  *
  */
-relativeDistinguishedNames [SchemaManager schemaManager, List<Rdn> rdns]
+relativeDistinguishedNames [SchemaManager schemaManager, List<Rdn> rdns] returns [String
normNameStr]
     {
         matchedProduction( "relativeDistinguishedNames()" );
         Rdn rdn = new Rdn( schemaManager );
+        StringBuilder dnNormSb = new StringBuilder();
     }
     :
     (
         relativeDistinguishedName[ schemaManager, rdn] 
         { 
             rdns.add( rdn );
+            dnNormSb.append( rdn.getNormName() );
             rdn = new Rdn( schemaManager );
         }
         (
@@ -268,11 +274,16 @@ relativeDistinguishedNames [SchemaManage
             relativeDistinguishedName[schemaManager, rdn] 
             { 
                 rdns.add( rdn ); 
+	            dnNormSb.append( ',' );
+	            dnNormSb.append( rdn.getNormName() );
                 rdn = new Rdn( schemaManager );
-            }
+				}
         )*
         EOF
     )?
+    {
+        normNameStr = dnNormSb.toString();
+    }
     ;
 
 /**
@@ -299,25 +310,77 @@ relativeDistinguishedName [SchemaManager
         // The rdnStr variable is used to gather the full RDN string
         // as provided
         StringBuilder rdnStr = new StringBuilder();
+        StringBuilder rdnNormStr = new StringBuilder();
+        int avaPos = 0;
+        Ava currentAva;
+        AttributeType attributeType;
+        Value val;
     }
     :
     (
         tmp = attributeTypeAndValue[schemaManager, rdn] 
         {
             rdnStr.append( tmp );
+            currentAva = rdn.getAva( avaPos );
+            
+            attributeType = currentAva.getAttributeType();
+            
+            if ( attributeType != null )
+            {
+                rdnNormStr.append( attributeType.getOid() );
+            }
+            else
+            {
+                rdnNormStr.append( tmp );
+            }
+            
+            rdnNormStr.append( '=' );
+            
+            val = currentAva.getValue();
+            
+            if ( ( val != null ) && ( val.getNormalized() != null ) )
+            {
+                rdnNormStr.append( val.getNormalized() );
+            }
         }
         (
-            PLUS { rdnStr.append( '+' ); }
+            PLUS 
+            { 
+                rdnStr.append( '+' ); 
+                rdnNormStr.append( '+' );
+                avaPos++;
+            }
 
             tmp = attributeTypeAndValue[schemaManager, rdn] 
             {
                 rdnStr.append( tmp );
+                currentAva = rdn.getAva( avaPos );
+                attributeType = currentAva.getAttributeType();
+            
+                if ( attributeType != null )
+                {
+                    rdnNormStr.append( attributeType.getOid() );
+                }
+                else
+                {
+                    rdnNormStr.append( tmp );
+                }
+            
+                rdnNormStr.append( '=' );
+            
+                val = currentAva.getValue();
+            
+                if ( ( val != null ) && ( val.getNormalized() != null ) )
+                {
+                    rdnNormStr.append( val.getNormalized() );
+                }
             }
         )*
     )
     {
         rdn.hashCode();
         rdn.setUpName( rdnStr.toString() );
+        rdn.setNormName( rdnNormStr.toString() );
     }
     ;
     

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java?rev=1745847&r1=1745846&r2=1745847&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
Sat May 28 08:04:04 2016
@@ -119,7 +119,7 @@ public class Ava implements Externalizab
         value = null;
         upName = "";
         this.schemaManager = schemaManager;
-        this.attributeType = null;
+        attributeType = null;
     }
 
 
@@ -170,7 +170,15 @@ public class Ava implements Externalizab
             }
         }
         
-        upName = this.upType + '=' + ( this.value == null ? "" : this.value.getValue() );
+        StringBuilder sb = new StringBuilder( upType );
+        sb.append( '=' );
+        
+        if ( ( value != null ) && ( value.getValue() != null ) )
+        {
+            sb.append( value.getValue() );
+        }
+        
+        upName = sb.toString();
 
         hashCode();
     }
@@ -509,10 +517,21 @@ public class Ava implements Externalizab
     /* Unspecified protection */Ava( SchemaManager schemaManager, String upType, String normType,
Value value )
         throws LdapInvalidDnException
     {
+        StringBuilder sb = new StringBuilder();
+
         this.upType = upType;
         this.normType = normType;
         this.value = value;
-        upName = this.upType + '=' + ( this.value == null ? "" : this.value.getValue() );
+        
+        sb.append( upType );
+        sb.append( '=' );
+        
+        if ( ( value != null ) && ( value.getValue() != null ) )
+        {
+            sb.append( value.getValue() );
+        }
+        
+        upName = sb.toString();
 
         if ( schemaManager != null )
         {
@@ -539,10 +558,22 @@ public class Ava implements Externalizab
     private void createAva( SchemaManager schemaManager, String upType, Value value )
         throws LdapInvalidDnException
     {
+        StringBuilder sb = new StringBuilder();
+
         normType = attributeType.getOid();
         this.upType = upType;
         this.value = value;
-        upName = this.upType + '=' + ( value == null ? "" : Rdn.escapeValue( value.getValue()
) );
+        
+        sb.append( upType );
+        sb.append( '=' );
+        
+        if ( value != null )
+        {
+            sb.append( Rdn.escapeValue( value.getValue() ) );
+        }
+        
+        upName = sb.toString();
+
         hashCode();
     }
 
@@ -596,6 +627,7 @@ public class Ava implements Externalizab
         value = upValue;
 
         upName = getEscaped();
+        
         hashCode();
     }
 
@@ -1602,13 +1634,14 @@ public class Ava implements Externalizab
         }
 
         // The normType
-        byte[] normTypeBytes = null;
+        /*byte[] normTypeBytes = null;
 
         if ( normType != null )
         {
             normTypeBytes = Strings.getBytesUtf8( normType );
             length += 1 + 4 + normTypeBytes.length;
         }
+        */
 
         // Is HR
         length++;
@@ -1645,6 +1678,7 @@ public class Ava implements Externalizab
         }
 
         // Write the normType
+        /*
         if ( normType != null )
         {
             buffer[pos++] = Serialize.TRUE;
@@ -1654,6 +1688,7 @@ public class Ava implements Externalizab
         {
             buffer[pos++] = Serialize.FALSE;
         }
+        */
 
         // Write the isHR flag
         if ( value.isHumanReadable() )
@@ -1717,6 +1752,7 @@ public class Ava implements Externalizab
         }
 
         // Read the normType value, if it's not null
+        /*
         boolean hasNormType = Serialize.deserializeBoolean( buffer, pos );
         pos++;
 
@@ -1726,6 +1762,7 @@ public class Ava implements Externalizab
             pos += 4 + normTypeBytes.length;
             normType = Strings.utf8ToString( normTypeBytes );
         }
+        */
 
         // Update the AtributeType
         if ( schemaManager != null )
@@ -1740,6 +1777,15 @@ public class Ava implements Externalizab
             }
         }
 
+        if ( attributeType != null )
+        {
+            normType = attributeType.getOid();
+        }
+        else
+        {
+            normType = upType;
+        }
+
         // Read the isHR flag
         boolean isHR = Serialize.deserializeBoolean( buffer, pos );
         pos++;
@@ -1937,11 +1983,6 @@ public class Ava implements Externalizab
         }
 
         h = in.readInt();
-
-        if ( schemaManager != null )
-        {
-            attributeType = schemaManager.getAttributeType( upType );
-        }
     }
 
 

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/ComplexDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/ComplexDnParser.java?rev=1745847&r1=1745846&r2=1745847&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/ComplexDnParser.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/ComplexDnParser.java
Sat May 28 08:04:04 2016
@@ -44,13 +44,13 @@ import org.apache.directory.api.ldap.mod
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    /* No protection*/void parseDn( SchemaManager schemaManager, String name, List<Rdn>
rdns ) throws LdapInvalidDnException
+    /* No protection*/String parseDn( SchemaManager schemaManager, String name, List<Rdn>
rdns ) throws LdapInvalidDnException
     {
         AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name
) ) );
 
         try
         {
-            dnParser.relativeDistinguishedNames( schemaManager, rdns );
+            return dnParser.relativeDistinguishedNames( schemaManager, rdns );
         }
         catch ( Exception e )
         {
@@ -62,8 +62,8 @@ import org.apache.directory.api.ldap.mod
     /**
      * Parses an Rdn.
      * 
-     * @param name the string representationof the relative distinguished name
-     * @param rdn the (empty) Rdn where parsed ATAVs are put to
+     * @param name the string representation of the relative distinguished name
+     * @param rdn the (empty) Rdn where parsed ATAVs are put into
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java?rev=1745847&r1=1745846&r2=1745847&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
Sat May 28 08:04:04 2016
@@ -96,6 +96,9 @@ public class Dn implements Iterable<Rdn>
     /** The user provided name */
     private String upName;
 
+    /** The normalized name */
+    private String normName;
+
     /** A null Dn */
     public static final Dn EMPTY_DN = new Dn();
 
@@ -169,6 +172,7 @@ public class Dn implements Iterable<Rdn>
     {
         this.schemaManager = schemaManager;
         upName = "";
+        normName = "";
     }
 
 
@@ -249,7 +253,7 @@ public class Dn implements Iterable<Rdn>
      */
     public Dn( SchemaManager schemaManager, String... upRdns ) throws LdapInvalidDnException
     {
-        StringBuilder sb = new StringBuilder();
+        StringBuilder sbUpName = new StringBuilder();
         boolean valueExpected = false;
         boolean isFirst = true;
         this.schemaManager = schemaManager;
@@ -267,12 +271,12 @@ public class Dn implements Iterable<Rdn>
             }
             else if ( !valueExpected )
             {
-                sb.append( ',' );
+                sbUpName.append( ',' );
             }
 
             if ( !valueExpected )
             {
-                sb.append( upRdn );
+                sbUpName.append( upRdn );
 
                 if ( upRdn.indexOf( '=' ) == -1 )
                 {
@@ -281,7 +285,7 @@ public class Dn implements Iterable<Rdn>
             }
             else
             {
-                sb.append( "=" ).append( upRdn );
+                sbUpName.append( "=" ).append( upRdn );
 
                 valueExpected = false;
             }
@@ -294,11 +298,11 @@ public class Dn implements Iterable<Rdn>
 
         // Stores the representations of a Dn : internal (as a string and as a
         // byte[]) and external.
-        upName = sb.toString();
+        upName = sbUpName.toString();
         
         try
         {
-            parseInternal( schemaManager, upName, rdns );
+            normName = parseInternal( schemaManager, upName, rdns );
         }
         catch ( LdapInvalidDnException e )
         {
@@ -414,10 +418,12 @@ public class Dn implements Iterable<Rdn>
         if ( rdns.isEmpty() )
         {
             upName = "";
+            normName = "";
         }
         else
         {
-            StringBuilder sb = new StringBuilder();
+            StringBuilder sbUpName = new StringBuilder();
+            StringBuilder sbNormName = new StringBuilder();
             boolean isFirst = true;
 
             for ( Rdn rdn : rdns )
@@ -428,13 +434,16 @@ public class Dn implements Iterable<Rdn>
                 }
                 else
                 {
-                    sb.append( ',' );
+                    sbUpName.append( ',' );
+                    sbNormName.append( ',' );
                 }
 
-                sb.append( rdn.getName() );
+                sbUpName.append( rdn.getName() );
+                sbNormName.append( rdn.getNormName() );
             }
 
-            upName = sb.toString();
+            upName = sbUpName.toString();
+            normName = sbNormName.toString();
         }
 
         return upName;
@@ -470,6 +479,17 @@ public class Dn implements Iterable<Rdn>
     {
         return upName == null ? "" : upName;
     }
+
+
+    /**
+     * Get the normalized Dn
+     *
+     * @return The normalized Dn as a String
+     */
+    public String getNormName()
+    {
+        return normName == null ? "" : normName;
+    }
     
     
     /**
@@ -513,6 +533,19 @@ public class Dn implements Iterable<Rdn>
 
 
     /**
+     * Sets the normalized name.
+     *
+     * Package private because Dn is immutable, only used by the Dn parser.
+     *
+     * @param normName the new normalized name
+     */
+    /* No qualifier */void setNormName( String normName )
+    {
+        this.normName = normName;
+    }
+
+
+    /**
      * Get the number of RDNs present in the DN
      * @return The umber of RDNs in the DN
      */
@@ -1131,16 +1164,16 @@ public class Dn implements Iterable<Rdn>
      * @param rdns The list that will contain the RDNs
      * @throws LdapInvalidDnException If the Dn is invalid
      */
-    private static void parseInternal( SchemaManager schemaManager, String name, List<Rdn>
rdns ) throws LdapInvalidDnException
+    private static String parseInternal( SchemaManager schemaManager, String name, List<Rdn>
rdns ) throws LdapInvalidDnException
     {
         try
         {
-            FastDnParser.parseDn( schemaManager, name, rdns );
+            return FastDnParser.parseDn( schemaManager, name, rdns );
         }
         catch ( TooComplexDnException e )
         {
             rdns.clear();
-            new ComplexDnParser().parseDn( schemaManager, name, rdns );
+            return new ComplexDnParser().parseDn( schemaManager, name, rdns );
         }
     }
 
@@ -1165,6 +1198,8 @@ public class Dn implements Iterable<Rdn>
             rdn.readExternal( in );
             rdns.add( rdn );
         }
+        
+        toUpName();
     }
 
 

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java?rev=1745847&r1=1745846&r2=1745847&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
Sat May 28 08:04:04 2016
@@ -26,8 +26,10 @@ import org.apache.directory.api.i18n.I18
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.api.util.Position;
+import org.apache.directory.api.util.Strings;
 
 
 /**
@@ -82,17 +84,18 @@ import org.apache.directory.api.util.Pos
      */
     /* No protection*/static void parseDn( SchemaManager schemaManager, String name, Dn dn
) throws LdapInvalidDnException
     {
-        parseDn( schemaManager, name, dn.rdns );
+        String normName = parseDn( schemaManager, name, dn.rdns );
         dn.setUpName( name );
+        dn.setNormName( normName );
     }
 
 
-    /* No protection*/static void parseDn( SchemaManager schemaManager, String name, List<Rdn>
rdns ) throws LdapInvalidDnException
+    /* No protection*/static String parseDn( SchemaManager schemaManager, String name, List<Rdn>
rdns ) throws LdapInvalidDnException
     {
         if ( ( name == null ) || ( name.trim().length() == 0 ) )
         {
             // We have an empty Dn, just get out of the function.
-            return;
+            return "";
         }
 
         Position pos = new Position();
@@ -100,11 +103,13 @@ import org.apache.directory.api.util.Pos
 
         pos.start = 0;
         pos.length = chars.length;
+        StringBuilder sb = new StringBuilder();
 
         while ( true )
         {
             Rdn rdn = new Rdn( schemaManager );
             parseRdnInternal( schemaManager, name, pos, rdn );
+            sb.append( rdn.getNormName() );
             rdns.add( rdn );
 
             if ( !hasMoreChars( pos ) )
@@ -120,6 +125,7 @@ import org.apache.directory.api.util.Pos
                 case ',':
                 case ';':
                     // another Rdn to parse
+                    sb.append( ',' );
                     break;
 
                 default:
@@ -127,6 +133,8 @@ import org.apache.directory.api.util.Pos
                         pos.start ) );
             }
         }
+        
+        return sb.toString();
     }
 
 
@@ -140,7 +148,7 @@ import org.apache.directory.api.util.Pos
      */
     /* No protection*/static void parseRdn( SchemaManager schemaManager, String name, Rdn
rdn ) throws LdapInvalidDnException
     {
-        if ( name == null || name.length() == 0 )
+        if ( Strings.isEmpty( name ) )
         {
             throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err(
I18n.ERR_04193 ) );
         }
@@ -153,13 +161,17 @@ import org.apache.directory.api.util.Pos
         Position pos = new Position();
         pos.start = 0;
         pos.length = name.length();
+        StringBuilder sb = new StringBuilder();
 
         parseRdnInternal( schemaManager, name, pos, rdn );
+        
+        sb.append( rdn.getNormName() );
     }
 
 
     private static void parseRdnInternal( SchemaManager schemaManager, String name, Position
pos, Rdn rdn ) throws LdapInvalidDnException
     {
+        StringBuilder sbNormName = new StringBuilder();
         int rdnStart = pos.start;
         char[] chars = name.toCharArray();
 
@@ -181,17 +193,41 @@ import org.apache.directory.api.util.Pos
         // here we only match "simple" values
         // stops at \ + # " -> Too Complex Exception
         String upValue = matchValue( chars, pos );
-        // TODO: trim, normalize, etc
 
         // SPACE*
         matchSpaces( chars, pos );
 
         String upName = name.substring( rdnStart, pos.start );
-
+        
         Ava ava = new Ava( schemaManager, type, upValue );
         rdn.addAVA( schemaManager, ava );
 
+        if ( schemaManager != null )
+        {
+            AttributeType attributeType = ava.getAttributeType();
+            
+            if ( attributeType != null )
+            {
+                sbNormName.append( ava.getNormType() );
+                sbNormName.append( '=' );
+                sbNormName.append( ava.getValue().getNormalized() );
+            }
+            else
+            {
+                sbNormName.append( type );
+                sbNormName.append( '=' );
+                sbNormName.append( upValue );
+            }
+        }
+        else
+        {
+            sbNormName.append( type );
+            sbNormName.append( '=' );
+            sbNormName.append( upValue );
+        }
+
         rdn.setUpName( upName );
+        rdn.setNormName( sbNormName.toString() );
         rdn.hashCode();
     }
 

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java?rev=1745847&r1=1745846&r2=1745847&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
Sat May 28 08:04:04 2016
@@ -131,6 +131,9 @@ public class Rdn implements Cloneable, E
 
     /** The User Provided Rdn */
     private String upName = null;
+    
+    /** The normalized Rdn */
+    private String normName;
 
     /**
      * Stores all couple type = value. We may have more than one type, if the
@@ -208,7 +211,8 @@ public class Rdn implements Cloneable, E
         // treeSet.
         this.schemaManager = schemaManager;
         upName = "";
-        normalized = false;
+        normName = "";
+        normalized = true;
         h = 0;
     }
 
@@ -237,7 +241,8 @@ public class Rdn implements Cloneable, E
         else
         {
             upName = "";
-            normalized = false;
+            normName = "";
+            normalized = true;
         }
 
         hashCode();
@@ -350,7 +355,8 @@ public class Rdn implements Cloneable, E
     public Rdn( Rdn rdn )
     {
         nbAvas = rdn.size();
-        this.upName = rdn.getName();
+        upName = rdn.getName();
+        normName = rdn.getName();
         normalized = rdn.normalized;
         schemaManager = rdn.schemaManager;
 
@@ -423,7 +429,21 @@ public class Rdn implements Cloneable, E
                 return;
 
             case 1:
-                this.ava = new Ava( schemaManager, rdn.ava );
+                ava = new Ava( schemaManager, rdn.ava );
+                
+                StringBuilder sb = new StringBuilder();
+                
+                sb.append( ava.getNormType() );
+                sb.append( '=' );
+                
+                if ( ( ava.getValue() != null ) && ( ava.getValue().getNormalized()
!= null ) )
+                {
+                    sb.append( ava.getValue().getNormalized() );
+                }
+                
+                normName = sb.toString();
+                normalized = true;
+                
                 hashCode();
 
                 return;
@@ -432,7 +452,9 @@ public class Rdn implements Cloneable, E
                 // We must duplicate the treeSet and the hashMap
                 avas = new ArrayList<>();
                 avaTypes = new HashMap<>();
-
+                sb = new StringBuilder();
+                boolean isFirst = true;
+                
                 for ( Ava currentAva : rdn.avas )
                 {
                     Ava tmpAva = currentAva;
@@ -451,16 +473,33 @@ public class Rdn implements Cloneable, E
                         avaTypes.put( tmpAva.getNormType(), avaList );
                         avas.add( tmpAva );
                     }
+                    else if ( !avaList.contains( tmpAva ) )
+                    {
+                        avaList.add( tmpAva );
+                        avas.add( tmpAva );
+                    }
+                    
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
                     else
                     {
-                        if ( !avaList.contains( tmpAva ) )
-                        {
-                            avaList.add( tmpAva );
-                            avas.add( tmpAva );
-                        }
+                        sb.append( ',' );
+                    }
+                    
+                    sb.append( currentAva.getNormType() );
+                    sb.append( '=' );
+                    
+                    if ( ( currentAva.getValue() != null ) && ( currentAva.getValue().getNormalized()
!= null ) )
+                    {
+                        sb.append( currentAva.getValue().getNormalized() );
                     }
                 }
 
+                normName = sb.toString();
+                normalized = true;
+
                 hashCode();
 
                 return;
@@ -916,6 +955,29 @@ public class Rdn implements Cloneable, E
 
 
     /**
+     * @return the normalized name
+     */
+    public String getNormName()
+    {
+        return normName;
+    }
+
+
+    /**
+     * Set the normalized Name.
+     *
+     * Package private because Rdn is immutable, only used by the Dn parser.
+     *
+     * @param normName the Normalized dame
+     */
+    void setNormName( String normName )
+    {
+        this.normName = normName;
+        normalized = true;
+    }
+
+
+    /**
      * Return the unique Ava, or the first one of we have more
      * than one
      *
@@ -938,6 +1000,38 @@ public class Rdn implements Cloneable, E
 
 
     /**
+     * Return the Nth Ava
+     * 
+     * @param pos The Ava we are looking for
+     *
+     * @return The Ava at the given position in this Rdn
+     */
+    public Ava getAva( int pos )
+    {
+        if ( pos > nbAvas )
+        {
+            return null;
+        }
+        
+        if ( pos == 0 )
+        {
+            if ( nbAvas == 1 )
+            {
+                return ava;
+            }
+            else
+            {
+                    return avas.get( 0 );
+            }
+        }
+        else
+        {
+            return avas.get( pos );
+        }
+    }
+
+
+    /**
      * Return the user provided type, or the first one of we have more than one (the lowest)
      *
      * @return The first user provided type of this Rdn
@@ -1780,6 +1874,8 @@ public class Rdn implements Cloneable, E
     @Override
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
+        StringBuilder sb = new StringBuilder();
+        
         // Read the Ava number
         nbAvas = in.readInt();
 
@@ -1790,18 +1886,23 @@ public class Rdn implements Cloneable, E
         {
             case 0:
                 ava = null;
+                normName = "";
                 break;
 
             case 1:
                 ava = new Ava( schemaManager );
                 ava.readExternal( in );
                 avaType = ava.getNormType();
+                
+                buildNormRdn( sb, ava );
+                normName = sb.toString();
 
                 break;
 
             default:
                 avas = new ArrayList<>();
                 avaTypes = new HashMap<>();
+                boolean isFirst = true;
 
                 for ( int i = 0; i < nbAvas; i++ )
                 {
@@ -1816,12 +1917,24 @@ public class Rdn implements Cloneable, E
                         avaList = new ArrayList<>();
                         avaTypes.put( newAva.getNormType(), avaList );
                     }
+
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
+                    else
+                    {
+                        sb.append( '+' );
+                    }
                     
+                    buildNormRdn( sb, newAva );
+
                     avaList.add( newAva );
                 }
 
                 ava = null;
                 avaType = null;
+                normName = sb.toString();
 
                 break;
         }
@@ -1830,6 +1943,21 @@ public class Rdn implements Cloneable, E
     }
 
 
+    private void buildNormRdn( StringBuilder sb, Ava ava )
+    {
+        sb.append( ava.getNormType() );
+        
+        sb.append( '=' );
+        
+        Value val = ava.getValue();
+        
+        if ( ( val != null ) && ( val.getNormalized() != null ) ) 
+        {
+            sb.append( ava.getValue().getNormalized() );
+        }
+    }
+    
+
     /**
      * Compare the current RDN with the provided one. 
      * 



Mime
View raw message