directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r534497 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name: AttributeTypeAndValue.java LdapDN.java Rdn.java RdnParser.java
Date Wed, 02 May 2007 14:54:27 GMT
Author: elecharny
Date: Wed May  2 07:54:26 2007
New Revision: 534497

URL: http://svn.apache.org/viewvc?view=rev&rev=534497
Log:
Fixed a big problem we had with RDN : when trying to get the UP form
from a RDN, we get the normalized form instead.
This was because the UP form was never stored into each RDN

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.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/name/RdnParser.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?view=diff&rev=534497&r1=534496&r2=534497
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
Wed May  2 07:54:26 2007
@@ -69,6 +69,9 @@
     /** The name value. It can be a String or a byte array */
     private Object value;
 
+    /** The name user provided value. It can be a String or a byte array */
+    private Object upValue;
+
     /** The user provided atav */
     private String upName;
 
@@ -93,6 +96,7 @@
         normType = null;
         upType = null;
         value = null;
+        upValue = null;
         upName = "";
         start = -1;
         length = 0;
@@ -109,7 +113,7 @@
      * @param value
      *            the value
      */
-    public AttributeTypeAndValue( String type, Object value ) throws InvalidNameException
+    public AttributeTypeAndValue( String upType, String type, Object upValue, Object value
) throws InvalidNameException
     {
         if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
         {
@@ -118,7 +122,8 @@
         }
 
         normType = type.trim().toLowerCase();
-        upType = type;
+        this.upType = upType;
+        this.upValue = upValue;
 
         if ( value instanceof String )
         {
@@ -129,7 +134,7 @@
             this.value = value;
         }
 
-        upName = type + '=' + value;
+        upName = upType + '=' + upValue;
         start = 0;
         length = upName.length();
     }
@@ -162,7 +167,7 @@
      * @param type
      *            The AttributeTypeAndValue type
      */
-    public void setType( String type ) throws InvalidNameException
+    public void setType( String upType, String type ) throws InvalidNameException
     {
         if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
         {
@@ -171,8 +176,8 @@
         }
 
         normType = type.trim().toLowerCase();
-        upType = type;
-        upName = type + upName.substring( upName.indexOf( '=' ) );
+        this.upType = upType;
+        upName = upType + upName.substring( upName.indexOf( '=' ) );
         start = -1;
         length = upName.length();
     }
@@ -211,6 +216,16 @@
     }
 
     /**
+     * Get the User Provided Value of a AttributeTypeAndValue
+     *
+     * @return The value
+     */
+    public Object getUpValue()
+    {
+        return upValue;
+    }
+
+    /**
      * Get the normalized Value of a AttributeTypeAndValue
      *
      * @return The value
@@ -227,7 +242,7 @@
      * @param value
      *            The value of the AttributeTypeAndValue
      */
-    public void setValue( Object value )
+    public void setValue( Object upValue, Object value )
     {
         if ( value instanceof String )
         {
@@ -238,7 +253,8 @@
             this.value = value;
         }
 
-        upName = upName.substring( 0, upName.indexOf( '=' ) + 1 ) + value;
+        this.upValue = upValue;
+        upName = upName.substring( 0, upName.indexOf( '=' ) + 1 ) + upValue;
         start = -1;
         length = upName.length();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?view=diff&rev=534497&r1=534496&r2=534497
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
Wed May  2 07:54:26 2007
@@ -1321,8 +1321,9 @@
 
                 if ( oidNormalizer != null )
                 {
-                    return new AttributeTypeAndValue( oidNormalizer.getAttributeTypeOid(),
oidNormalizer
-                        .getNormalizer().normalize( atav.getValue() ) );
+                    return new AttributeTypeAndValue( atav.getUpType(), oidNormalizer.getAttributeTypeOid(),

+                    		atav.getUpValue(),
+                    		oidNormalizer.getNormalizer().normalize( atav.getValue() ) );
 
                 }
                 else
@@ -1368,9 +1369,9 @@
 
             while ( atavs.hasNext() )
             {
-                Object val = atavs.next();
-                AttributeTypeAndValue newAtav = atavOidToName( ( AttributeTypeAndValue )
val, oidsMap );
-                rdn.addAttributeTypeAndValue( newAtav.getUpType(), newAtav.getValue() );
+            	AttributeTypeAndValue val = (AttributeTypeAndValue)atavs.next();
+                AttributeTypeAndValue newAtav = atavOidToName( val, oidsMap );
+                rdn.addAttributeTypeAndValue( val.getUpType(), newAtav.getNormType(), val.getUpValue(),
newAtav.getValue() );
             }
 
         }
@@ -1395,12 +1396,13 @@
 
                     if ( oidNormalizer != null )
                     {
-                        Object value = rdn.getValue();
+                        Object upValue = rdn.getUpValue();
+                        String upType = rdn.getUpType();
                         rdn.clear();
-                        Object normValue = DefaultStringNormalizer.normalizeString( ( String
) value );
+                        Object normValue = DefaultStringNormalizer.normalizeString( ( String
) upValue );
 
-                        rdn.addAttributeTypeAndValue( oidNormalizer.getAttributeTypeOid(),
oidNormalizer
-                            .getNormalizer().normalize( normValue ) );
+                        rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(),
upValue, 
+                        		oidNormalizer.getNormalizer().normalize( normValue ) );
 
                     }
                     else

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?view=diff&rev=534497&r1=534496&r2=534497
==============================================================================
--- 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 May  2 07:54:26 2007
@@ -226,11 +226,11 @@
     * @throws InvalidNameException
     *             If the RDN is invalid
     */
-   public Rdn( String type, String value ) throws InvalidNameException
+   public Rdn( String upType, String type, String upValue, String value ) throws InvalidNameException
    {
        super();
 
-       addAttributeTypeAndValue( type, value );
+       addAttributeTypeAndValue( upType, type, upValue, value );
 
        upName = type + '=' + value;
        start = 0;
@@ -354,7 +354,7 @@
    // We need this method to be visible from the DnParser class, but not
    // from outside this package.
    @SuppressWarnings({"unchecked"})
-   /* Unspecified protection */void addAttributeTypeAndValue( String type, Object value )
throws InvalidNameException
+   /* Unspecified protection */void addAttributeTypeAndValue( String upType, String type,
Object upValue, Object value ) throws InvalidNameException
    {
        // First, let's normalize the type
        String normalizedType = type.toLowerCase();
@@ -364,7 +364,7 @@
        {
            case 0:
                // This is the first AttributeTypeAndValue. Just stores it.
-               atav = new AttributeTypeAndValue( type, normalizedValue );
+               atav = new AttributeTypeAndValue( upType, type, upValue, normalizedValue );
                nbAtavs = 1;
                atavType = normalizedType;
                return;
@@ -387,7 +387,7 @@
 
            default:
                // add a new AttributeTypeAndValue
-               AttributeTypeAndValue newAtav = new AttributeTypeAndValue( type, normalizedValue
);
+               AttributeTypeAndValue newAtav = new AttributeTypeAndValue( upType, type, upValue,
normalizedValue );
                atavs.add( newAtav );
                atavTypes.put( normalizedType, newAtav );
 
@@ -852,6 +852,26 @@
    }
 
 
+   /**
+    * Return the User Provided value
+    * 
+    * @return The first User provided value of this RDN
+    */
+   public Object getUpValue()
+   {
+       switch ( nbAtavs )
+       {
+           case 0:
+               return null;
+
+           case 1:
+               return atav.getUpValue();
+
+           default:
+               return ( ( AttributeTypeAndValue )((TreeSet)atavs).first() ).getUpValue();
+       }
+   }
+   
    /**
     * Compares the specified Object with this Rdn for equality. Returns true if
     * the given object is also a Rdn and the two Rdns represent the same

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?view=diff&rev=534497&r1=534496&r2=534497
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
Wed May  2 07:54:26 2007
@@ -791,7 +791,7 @@
             {
                 if ( rdn != null )
                 {
-                    rdn.addAttributeTypeAndValue( type, value );
+                    rdn.addAttributeTypeAndValue( type, type, value, value );
                 }
             }
 
@@ -953,7 +953,7 @@
 
         if ( rdn != null )
         {
-            rdn.addAttributeTypeAndValue( type, value );
+            rdn.addAttributeTypeAndValue( type, type, value, value );
             rdn.normalize();
 
             pos.start = pos.end;



Mime
View raw message