directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r613579 [2/3] - in /directory/sandbox/akarasulu/bigbang/shared: ./ ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/ ldap/src/main/antlr/ ldap/src/main/java/org/apache/directory/shared/ldap/aci/ ldap/src/main/java/org...
Date Sun, 20 Jan 2008 15:55:12 GMT
Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Sun Jan 20 07:55:03 2008
@@ -144,6 +144,19 @@
     
     
     /**
+     * Convert a LDIF String to an attributes.
+     * 
+     * @param ldif The LDIF string containing an attribute value
+     * @return An Attributes instance
+     */
+    public static Attributes convertAttributesFromLdif( String ldif ) throws NamingException
+    {
+        LdifAttributesReader reader = new  LdifAttributesReader();
+        
+        return reader.parseAttributes( ldif );
+    }
+    
+    /**
      * Convert an Attributes as LDIF
      * @param attrs the Attributes to convert
      * @param length the expected line length

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java Sun Jan 20 07:55:03 2008
@@ -110,9 +110,9 @@
      */
     public int hashCode()
     {
-        int hash = 7;
-        hash = hash*31 + abandonId;
-        hash = hash*31 + super.hashCode();
+        int hash = 37;
+        hash = hash*17 + abandonId;
+        hash = hash*17 + super.hashCode();
         
         return hash;
     }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java Sun Jan 20 07:55:03 2008
@@ -232,11 +232,11 @@
      */
     public int hashCode()
     {
-        int hash = 7;
-        hash = hash*31 + id;
-        hash = hash*31 + ( type == null ? 0 : type.hashCode() );
-        hash = hash*31 + ( parameters == null ? 0 : parameters.hashCode() );
-        hash = hash*31 + ( controls == null ? 0 : controls.hashCode() );
+        int hash = 37;
+        hash = hash*17 + id;
+        hash = hash*17 + ( type == null ? 0 : type.hashCode() );
+        hash = hash*17 + ( parameters == null ? 0 : parameters.hashCode() );
+        hash = hash*17 + ( controls == null ? 0 : controls.hashCode() );
         
         return hash;
     }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java Sun Jan 20 07:55:03 2008
@@ -68,9 +68,9 @@
      */
     public int hashCode()
     {
-        int hash = 7;
-        hash = hash*31 + (hasResponse ? 0 : 1 );
-        hash = hash*31 + super.hashCode();
+        int hash = 37;
+        hash = hash*17 + (hasResponse ? 0 : 1 );
+        hash = hash*17 + super.hashCode();
         
         return hash;
     }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java Sun Jan 20 07:55:03 2008
@@ -221,11 +221,11 @@
      */
     public int hashCode()
     {
-        int hash = 7;
-        hash = hash*31 + ( attributes == null ? 0 : attributes.hashCode() );
-        hash = hash*31 + ( entry == null ? 0 : entry.hashCode() );
-        hash = hash*31 + ( response == null ? 0 : response.hashCode() );
-        hash = hash*31 + super.hashCode();
+        int hash = 37;
+        hash = hash*17 + ( attributes == null ? 0 : attributes.hashCode() );
+        hash = hash*17 + ( entry == null ? 0 : entry.hashCode() );
+        hash = hash*17 + ( response == null ? 0 : response.hashCode() );
+        hash = hash*17 + super.hashCode();
         
         return hash;
     }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java Sun Jan 20 07:55:03 2008
@@ -696,9 +696,9 @@
      */
     public int hashCode()
     {
-        int hash = 17;
+        int hash = 37;
         
-        hash += hash*37 + StringTools.toLowerCase( getID() ).hashCode();
+        hash += hash*17 + StringTools.toLowerCase( getID() ).hashCode();
         
         if ( ( list != null ) && ( list.size() != 0 ) )
         {
@@ -706,11 +706,11 @@
             {
                 if ( value instanceof byte[] )
                 {
-                    hash += hash*37 + Arrays.hashCode( (byte[])value );
+                    hash += hash*17 + Arrays.hashCode( (byte[])value );
                 }
                 else 
                 {
-                    hash += hash*37 + value.hashCode();
+                    hash += hash*17 + value.hashCode();
                 }
             }
         }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java Sun Jan 20 07:55:03 2008
@@ -371,14 +371,14 @@
      */
     public int hashCode()
     {
-        int hash = 7;
-        hash = hash*31 + ( credentials == null ? 0 : hCredentials );
-        hash = hash*31 + ( isSimple ? 0 : 1 );
-        hash = hash*31 + ( isVersion3 ? 0 : 1 );
-        hash = hash*31 + ( mechanism == null ? 0 : mechanism.hashCode() );
-        hash = hash*31 + ( name == null ? 0 : name.hashCode() );
-        hash = hash*31 + ( response == null ? 0 : response.hashCode() );
-        hash = hash*31 + super.hashCode();
+        int hash = 37;
+        hash = hash*17 + ( credentials == null ? 0 : hCredentials );
+        hash = hash*17 + ( isSimple ? 0 : 1 );
+        hash = hash*17 + ( isVersion3 ? 0 : 1 );
+        hash = hash*17 + ( mechanism == null ? 0 : mechanism.hashCode() );
+        hash = hash*17 + ( name == null ? 0 : name.hashCode() );
+        hash = hash*17 + ( response == null ? 0 : response.hashCode() );
+        hash = hash*17 + super.hashCode();
         
         return hash;
     }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java Sun Jan 20 07:55:03 2008
@@ -20,7 +20,10 @@
 package org.apache.directory.shared.ldap.name;
 
 
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.Arrays;
 
 import javax.naming.InvalidNameException;
@@ -45,7 +48,7 @@
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class AttributeTypeAndValue implements Cloneable, Comparable, Serializable
+public class AttributeTypeAndValue implements Cloneable, Comparable, Externalizable
 {
     /**
      * Declares the Serial Version Uid.
@@ -57,14 +60,13 @@
     private static final long serialVersionUID = 1L;
 
     /** The LoggerFactory used by this class */
-    private static Logger log = LoggerFactory.getLogger( AttributeTypeAndValue.class );
+    private static Logger LOG = LoggerFactory.getLogger( AttributeTypeAndValue.class );
 
     /** The normalized Name type */
     private String normType;
 
     /** The user provided Name type */
     private String upType;
-    
 
     /** The name value. It can be a String or a byte array */
     private Object value;
@@ -105,36 +107,87 @@
 
     /**
      * Construct an AttributeTypeAndValue. The type and value are normalized :
-     * - the type is trimmed and lowercased
-     * - the value is trimmed
-     *
-     * @param type
-     *            The type
-     * @param value
-     *            the value
+     * <li> the type is trimmed and lowercased </li>
+     * <li> the value is trimmed </li>
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The Usrr Provided type
+     * @param normType The normalized type
+     * @param upValue The User Provided value
+     * @param normValue The normalized value
      */
-    public AttributeTypeAndValue( String upType, String type, Object upValue, Object value ) throws InvalidNameException
+    public AttributeTypeAndValue( String upType, String normType, Object upValue, Object normValue ) throws InvalidNameException
     {
-        if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
+        String upTypeTrimmed = StringTools.trim( upType );
+        String normTypeTrimmed = StringTools.trim( normType );
+        
+        if ( StringTools.isEmpty( upTypeTrimmed ) )
         {
-            log.error( "The type cannot be empty or null" );
-            throw new InvalidNameException( "Null or empty type is not allowed" );
+            if ( StringTools.isEmpty( normTypeTrimmed ) )
+            {
+                String message =  "The type cannot be empty or null";
+                LOG.error( message );
+                throw new InvalidNameException( message );
+            }
+            else
+            {
+                // In this case, we will use the normType instead
+                this.normType = StringTools.lowerCaseAscii( normTypeTrimmed );
+                this.upType = normType;
+            }
         }
+        else if ( StringTools.isEmpty( normTypeTrimmed ) )
+        {
+            // In this case, we will use the upType instead
+            this.normType = StringTools.lowerCaseAscii( upTypeTrimmed );
+            this.upType = upType;
+        }
+        else
+        {
+            this.normType = StringTools.lowerCaseAscii( normTypeTrimmed );
+            this.upType = upType;
+            
+        }
+            
 
-        normType = StringTools.lowerCaseAscii( type.trim() );
-        this.upType = upType;
-        this.upValue = upValue;
-
-        if ( value instanceof String )
+        if ( ( normValue == null ) || ( upValue == null ) )
         {
-            this.value = StringTools.isEmpty( ( String ) value ) ? "" : value;
+            if ( normValue instanceof String )
+            {
+                this.value = StringTools.isEmpty( ( String ) normValue ) ? "" : normValue;
+            }
+            else
+            {
+                this.value = normValue;
+            }
+
+            if ( upValue instanceof String )
+            {
+                this.upValue = StringTools.isEmpty( ( String ) upValue ) ? "" : upValue;
+            }
+            else
+            {
+                this.upValue = upValue;
+            }
         }
         else
         {
-            this.value = value;
+    
+            this.upValue = upValue;
+    
+            if ( normValue instanceof String )
+            {
+                this.value = StringTools.isEmpty( ( String ) normValue ) ? "" : normValue;
+            }
+            else
+            {
+                this.value = normValue;
+            }
         }
 
-        upName = upType + '=' + upValue;
+        upName = this.upType + '=' + ( this.upValue == null ? "" : this.upValue );
         start = 0;
         length = upName.length();
     }
@@ -162,22 +215,42 @@
 
 
     /**
-     * Store the type
+     * Store a new type
      *
-     * @param type
-     *            The AttributeTypeAndValue type
+     * @param upType The AttributeTypeAndValue User Provided type
+     * @param type The AttributeTypeAndValue type
+     * 
+     * @throws InvalidNameException if the type or upType are empty or null.
+     * If the upName is invalid.
      */
     public void setType( String upType, String type ) throws InvalidNameException
     {
         if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
         {
-            log.error( "The type cannot be empty or null" );
-            throw new InvalidNameException( "The AttributeTypeAndValue type cannot be null or empty " );
+            String message = "The type cannot be empty or null";
+            LOG.error( message );
+            throw new InvalidNameException( message );
+        }
+        
+        if ( StringTools.isEmpty( upType ) || StringTools.isEmpty( upType.trim() ) )
+        {
+            String message = "The User Provided type cannot be empty or null";
+            LOG.error( message );
+            throw new InvalidNameException( message );
+        }
+        
+        int equalPosition = upName.indexOf( '=' );
+        
+        if ( equalPosition <= 1 )
+        {
+            String message = "The User provided name does not contains an '='"; 
+            LOG.error( message );
+            throw new InvalidNameException( message );
         }
 
         normType = type.trim().toLowerCase();
         this.upType = upType;
-        upName = upType + upName.substring( upName.indexOf( '=' ) );
+        upName = upType + upName.substring( equalPosition );
         start = -1;
         length = upName.length();
     }
@@ -193,7 +266,7 @@
     {
         if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
         {
-            log.error( "The type cannot be empty or null" );
+            LOG.error( "The type cannot be empty or null" );
             throw new InvalidNameException( "The AttributeTypeAndValue type cannot be null or empty " );
         }
 
@@ -619,10 +692,10 @@
      */
     public int hashCode()
     {
-        int result = 17;
+        int result = 37;
 
-        result = result * 37 + ( normType != null ? normType.hashCode() : 0 );
-        result = result * 37 + ( value != null ? value.hashCode() : 0 );
+        result = result*17 + ( normType != null ? normType.hashCode() : 0 );
+        result = result*17 + ( value != null ? value.hashCode() : 0 );
 
         return result;
     }
@@ -637,12 +710,7 @@
             return true;
         }
         
-        if ( obj == null )
-        {
-            return false;
-        }
-        
-        if ( obj.getClass() != this.getClass() )
+        if ( !( obj instanceof AttributeTypeAndValue ) )
         {
             return false;
         }
@@ -665,12 +733,170 @@
             }
         }
             
-        // Compare the value
-        return ( value == null ? 
-            instance.value == null  :
-            value.equals( instance.value ) );
+        // Compare the values
+        if ( value == null )
+        {
+            return instance.value == null;
+        }
+        else if ( value instanceof String )
+        {
+            if ( instance.value instanceof String )
+            {
+                return value.equals( instance.value );
+            }
+            else
+            {
+                return false;
+            }
+        }
+        else if ( value instanceof byte[] )
+        {
+            if ( instance.value instanceof byte[] )
+            {
+                return Arrays.equals( (byte[])value, (byte[])instance.value );
+            }
+            else
+            {
+                return false;
+            }
+        }
+        else
+        {
+            return false;
+        }
     }
 
+    
+    /**
+     * @see Externalizable#readExternal(ObjectInput)<p>
+     * 
+     * An AttributeTypeAndValue is composed of  a type and a value.
+     * The data are stored following the structure :
+     * 
+     * <li>upName</li> The User provided ATAV
+     * <li>start</li> The position of this ATAV in the DN
+     * <li>length</li> The ATAV length
+     * <li>upType</li> The user Provided Type
+     * <li>normType</li> The normalized AttributeType
+     * <li>isHR<li> Tells if the value is a String or not
+     * <p>
+     * if the value is a String :
+     * <li>upValue</li> The User Provided value.
+     * <li>value</li> The normalized value.
+     * <p>
+     * if the value is binary :
+     * <li>upValueLength</li>
+     * <li>upValue</li> The User Provided value.
+     * <li>valueLength</li>
+     * <li>value</li> The normalized value.
+     */
+    public void writeExternal( ObjectOutput out ) throws IOException
+    {
+        if ( StringTools.isEmpty( upName ) || 
+             StringTools.isEmpty( upType ) ||
+             StringTools.isEmpty( normType ) ||
+             ( start < 0 ) ||
+             ( length < 2 ) ||             // At least a type and '='
+             ( upValue == null ) ||
+             ( value == null ) )
+        {
+            String message = "Cannot serialize an wrong ATAV, ";
+            
+            if ( StringTools.isEmpty( upName ) )
+            {
+                message += "the upName should not be null or empty";
+            }
+            else if ( StringTools.isEmpty( upType ) )
+            {
+                message += "the upType should not be null or empty";
+            }
+            else if ( StringTools.isEmpty( normType ) )
+            {
+                message += "the normType should not be null or empty";
+            }
+            else if ( start < 0 )
+            {
+                message += "the start should not be < 0";
+            }
+            else if ( length < 2 )
+            {
+                message += "the length should not be < 2";
+            }
+            else if ( upValue == null )
+            {
+                message += "the upValue should not be null";
+            }
+            else if ( value == null )
+            {
+                message += "the value should not be null";
+            }
+                
+            LOG.error( message );
+            throw new IOException( message );
+        }
+        
+        out.writeUTF( upName );
+        out.writeInt( start );
+        out.writeInt( length );
+        out.writeUTF( upType );
+        out.writeUTF( normType );
+        
+        boolean isHR = ( value instanceof String );
+        
+        out.writeBoolean( isHR );
+        
+        if ( isHR )
+        {
+            out.writeUTF( (String)upValue );
+            out.writeUTF( (String)value );
+        }
+        else
+        {
+            out.writeInt( ((byte[])upValue).length );
+            out.write( (byte[])upValue );
+            out.writeInt( ((byte[])value).length );
+            out.write( (byte[])value );
+        }
+        
+        out.flush();
+    }
+    
+    
+    /**
+     * @see Externalizable#readExternal(ObjectInput)
+     * 
+     * We read back the data to create a new ATAV. The structure 
+     * read is exposed in the {@link AttributeTypeAndValue#writeExternal(ObjectOutput)} 
+     * method<p>
+     */
+    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+    {
+        upName = in.readUTF();
+        start = in.readInt();
+        length = in.readInt();
+        upType = in.readUTF();
+        normType = in.readUTF();
+        
+        boolean isHR = in.readBoolean();
+        
+        if ( isHR )
+        {
+            upValue = in.readUTF();
+            value = in.readUTF();
+        }
+        else
+        {
+            int upValueLength = in.readInt();
+            upValue = new byte[upValueLength];
+            in.readFully( (byte[])upValue );
+
+            int valueLength = in.readInt();
+            value = new byte[valueLength];
+            in.readFully( (byte[])value );
+        }
+    }
+    
+    
     /**
      * A String representation of a AttributeTypeAndValue.
      *

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Sun Jan 20 07:55:03 2008
@@ -21,6 +21,10 @@
 package org.apache.directory.shared.ldap.name;
 
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -57,10 +61,10 @@
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdapDN implements Name
+public class LdapDN implements Name, Externalizable
 {
     /** The LoggerFactory used by this class */
-    protected static final Logger log = LoggerFactory.getLogger( LdapDN.class );
+    protected static final Logger LOG = LoggerFactory.getLogger( LdapDN.class );
 
     /**
      * Declares the Serial Version Uid.
@@ -406,7 +410,7 @@
         if ( posn > rdns.size() )
         {
             String message = "Impossible to get the position " + posn + ", the DN only has " + rdns.size() + " RDNs";
-            log.error( message );
+            LOG.error( message );
             throw new ArrayIndexOutOfBoundsException( message );
         }
 
@@ -485,13 +489,13 @@
      */
     public int hashCode()
     {
-        int result = 17;
+        int result = 37;
 
         if ( ( rdns != null ) && ( rdns.size() != 0 ) )
         {
             for ( Rdn rdn : rdns )
             {
-                result = result * 37 + rdn.hashCode();
+                result = result * 17 + rdn.hashCode();
             }
         }
 
@@ -636,7 +640,7 @@
                 catch ( InvalidNameException e )
                 {
                     e.printStackTrace();
-                    log.error( "Failed to parse RDN for name " + name.toString(), e );
+                    LOG.error( "Failed to parse RDN for name " + name.toString(), e );
                     return false;
                 }
 
@@ -833,7 +837,7 @@
             {
                 if ( pos >= rdns.size() )
                 {
-                    log.error( "Exceeded number of elements in the current object" );
+                    LOG.error( "Exceeded number of elements in the current object" );
                     throw new NoSuchElementException();
                 }
 
@@ -876,7 +880,7 @@
             {
                 if ( pos >= rdns.size() )
                 {
-                    log.error( "Exceeded number of elements in the current object" );
+                    LOG.error( "Exceeded number of elements in the current object" );
                     throw new NoSuchElementException();
                 }
 
@@ -912,7 +916,7 @@
         if ( ( posn < 0 ) || ( posn > rdns.size() ) )
         {
             String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
-            log.error( message );
+            LOG.error( message );
             throw new ArrayIndexOutOfBoundsException( message );
         }
 
@@ -956,7 +960,7 @@
         if ( ( posn < 0 ) || ( posn > rdns.size() ) )
         {
             String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
-            log.error( message );
+            LOG.error( message );
             throw new ArrayIndexOutOfBoundsException( message );
         }
 
@@ -1222,7 +1226,7 @@
         if ( ( posn < 0 ) || ( posn > size() ) )
         {
             String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
-            log.error( message );
+            LOG.error( message );
             throw new ArrayIndexOutOfBoundsException( message );
         }
 
@@ -1264,7 +1268,7 @@
         if ( ( posn < 0 ) || ( posn >= rdns.size() ) )
         {
             String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
-            log.error( message );
+            LOG.error( message );
             throw new ArrayIndexOutOfBoundsException( message );
         }
 
@@ -1301,7 +1305,7 @@
         }
         catch ( CloneNotSupportedException cnse )
         {
-            log.error( "The clone operation has failed" );
+            LOG.error( "The clone operation has failed" );
             throw new Error( "Assertion failure : cannot clone the object" );
         }
     }
@@ -1433,7 +1437,7 @@
         else
         {
             // The type is empty : this is not possible...
-            log.error( "Empty type not allowed in a DN" );
+            LOG.error( "Empty type not allowed in a DN" );
             throw new InvalidNameException( "Empty type not allowed in a DN" );
         }
 
@@ -1538,7 +1542,7 @@
             else
             {
                 // The type is empty : this is not possible...
-                log.error( "We should not have an empty DN" );
+                LOG.error( "We should not have an empty DN" );
                 throw new InvalidNameException( "Empty type not allowed in a DN" );
             }
         }
@@ -1655,5 +1659,130 @@
     public boolean isNormalized()
     {
         return normalized;
+    }
+
+
+    /**
+     * @see Externalizable#readExternal(ObjectInput)<p>
+     * 
+     * We have to store a DN data efficiently. Here is the structure :
+     * 
+     * <li>upName</li> The User provided DN<p>
+     * <li>normName</li> May be null if the normName is equaivalent to 
+     * the upName<p>
+     * <li>rdns</li> The rdn's List.<p>
+     * 
+     * for each rdn :
+     * <li>call the RDN write method</li>
+     */
+    public void writeExternal( ObjectOutput out ) throws IOException
+    {
+        if ( upName == null )
+        {
+            String message = "Cannot serialize a NULL DN";
+            LOG.error( message );
+            throw new IOException( message );
+        }
+        
+        // Write the UPName
+        out.writeUTF( upName );
+        
+        // Write the NormName if different
+        if ( isNormalized() )
+        {
+            if ( upName.equals( normName ) )
+            {
+                out.writeUTF( "" );
+            }
+            else
+            {
+                out.writeUTF( normName );
+            }
+        }
+        else
+        {
+            String message = "The DN should have been normalized before being serialized";
+            LOG.error( message );
+            throw new IOException( message );
+        }
+        
+        // Should we store the byte[] ???
+        
+        // Write the RDNs. Is it's null, the number will be -1. 
+        if ( rdns == null )
+        {
+            out.writeInt( -1 );
+        }
+        else if ( rdns.size() == 0 )
+        {
+            out.writeInt( 0 );
+        }
+        else
+        {
+            out.writeInt( rdns.size() );
+            
+            // Loop on the RDNs
+            for ( Rdn rdn:rdns )
+            {
+                out.writeObject( rdn );
+            }
+        }
+    }
+
+
+    /**
+     * @see Externalizable#readExternal(ObjectInput)
+     * 
+     * We read back the data to create a new LdapDN. The structure 
+     * read is exposed in the {@link LdapDN#writeExternal(ObjectOutput)} 
+     * method<p>
+     */
+    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+    {
+        // Read the UPName
+        upName = in.readUTF();
+        
+        // Read the NormName
+        normName = in.readUTF();
+        
+        if ( normName.length() == 0 )
+        {
+            // As the normName is equal to the upName,
+            // we didn't saved the nbnormName on disk.
+            // restore it by copying the upName.
+            normName = upName;
+        }
+        
+        // A serialized DN is always normalized.
+        normalized = true;
+            
+        // Should we read the byte[] ???
+        bytes = StringTools.getBytesUtf8( upName );
+        
+        // Read the RDNs. Is it's null, the number will be -1.
+        int nbRdns = in.readInt();
+        
+        switch ( nbRdns )
+        {
+            case -1 :
+                // No RDN at all... 
+                rdns = null;
+                break;
+                
+            case 0 :
+                // No RDN, but we have to initialize the list
+                // Note : this may not be a different case than -1
+                rdns = new ArrayList<Rdn>();
+                break;
+                
+            default :
+                for ( int i = 0; i < nbRdns; i++ )
+                {
+                    Rdn rdn = (Rdn)in.readObject();
+                    rdns.add( rdn );
+                }
+            
+                break;
+        }
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Sun Jan 20 07:55:03 2008
@@ -20,6 +20,10 @@
 package org.apache.directory.shared.ldap.name;
 
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.io.Serializable;
 import java.util.Iterator;
 import java.util.List;
@@ -35,6 +39,8 @@
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -103,7 +109,10 @@
  */
 public class Rdn implements Cloneable, Comparable, Serializable
 {
-   /**
+    /** The LoggerFactory used by this class */
+    protected static final Logger LOG = LoggerFactory.getLogger( Rdn.class );
+
+    /**
     * Declares the Serial Version Uid.
     *
     * @see <a
@@ -1245,7 +1254,7 @@
     */
    public int hashCode()
    {
-       int result = 17;
+       int result = 37;
 
        switch ( nbAtavs )
        {
@@ -1255,7 +1264,7 @@
 
            case 1:
                // We have a single AttributeTypeAndValue
-               result = result * 37 + atav.hashCode();
+               result = result * 17 + atav.hashCode();
                break;
 
            default:
@@ -1263,10 +1272,126 @@
 
                for ( AttributeTypeAndValue ata:atavs )
                {
-                   result = result * 37 + ata.hashCode();
+                   result = result * 17 + ata.hashCode();
                }
        }
 
        return result;
+   }
+
+
+   /**
+    * @see Externalizable#readExternal(ObjectInput)<p>
+    * 
+    * A RDN is composed of on to many ATAVs (AttributeType And Value).
+    * We should write all those ATAVs sequencially, following the 
+    * structure :
+    * 
+    * <li>nbAtavs</li> The number of ATAVs to write. Can't be 0.
+    * <li>upName</li> The User provided RDN
+    * <li>normName</li> The normalized RDN. It can be empty if the normalized
+    * name equals the upName.
+    * <li>atavs</li>
+    * <p>
+    * For each ATAV :<p>
+    * <li>start</li> The position of this ATAV in the upName string
+    * <li>length</li> The ATAV user provided length
+    * <li>Call the ATAV write method</li> The ATAV itself
+    *  
+    */
+   public void writeExternal( ObjectOutput out ) throws IOException
+   {
+       out.writeInt( nbAtavs );
+       out.writeUTF( upName );
+       
+       if ( upName.equals( normName ) )
+       {
+           out.writeUTF( "" );
+       }
+       else
+       {
+           out.writeUTF( normName );
+       }
+
+       out.writeInt( start );
+       out.writeInt( length );
+
+       switch ( nbAtavs )
+       {
+           case 0 :
+               break;
+
+           case 1 :
+               out.writeObject( atav );
+               break;
+               
+           default :
+               for ( AttributeTypeAndValue atav:atavs )
+               {
+                   out.writeObject( atav );
+               }
+           
+               break;
+       }
+       
+       out.flush();
+   }
+
+
+   /**
+    * @see Externalizable#readExternal(ObjectInput)
+    * 
+    * We read back the data to create a new RDB. The structure 
+    * read is exposed in the {@link Rdn#writeExternal(ObjectOutput)} 
+    * method<p>
+    */
+   public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+   {
+       // Read the ATAV number
+       nbAtavs = in.readInt();
+       
+       // Read the UPName
+       upName = in.readUTF();
+       
+       // Read the normName
+       normName = in.readUTF();
+       
+       if ( StringTools.isEmpty( normName ) )
+       {
+           normName = upName;
+       }
+       
+       start = in.readInt();
+       length = in.readInt();
+
+       switch ( nbAtavs )
+       {
+           case 0 :
+               atav = null;
+               break;
+               
+           case 1 :
+               atav = (AttributeTypeAndValue)in.readObject();
+               atavType = atav.getNormType();
+               
+               break;
+               
+           default :
+               atavs = new TreeSet<AttributeTypeAndValue>();
+
+               atavTypes = new MultiHashMap();
+
+               for ( int i = 0; i < nbAtavs; i++  )
+               {
+                   AttributeTypeAndValue atav = (AttributeTypeAndValue)in.readObject();
+                   atavs.add( atav );
+                   atavTypes.put( atav.getNormType(), atav );
+               }
+           
+               atav = null;
+               atavType = null;
+
+               break;
+       }
    }
 }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java Sun Jan 20 07:55:03 2008
@@ -374,6 +374,12 @@
      */
     private static Object parseAttributeValue( byte[] bytes, Position pos )
     {
+        if ( pos.start == bytes.length )
+        {
+            // This is an empty value
+            return "";
+        }
+        
         //StringBuffer sb = new StringBuffer();
         byte c = bytes[pos.start];
         byte[] buffer = new byte[bytes.length];

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java Sun Jan 20 07:55:03 2008
@@ -31,7 +31,6 @@
 import javax.naming.directory.ModificationItem;
 
 import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.schema.syntax.AbstractAdsSchemaDescription;
 import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
 import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
@@ -189,72 +188,6 @@
                     }
                     targetEntry.put( combined );
                 }
-                break;
-            default:
-                throw new IllegalStateException( "undefined modification type: " + modOp );
-        }
-
-        return targetEntry;
-    }
-
-
-    /**
-     * Gets the target entry as it would look after a modification operation 
-     * was performed on it.
-     * 
-     * @param mod the modification
-     * @param entry the source entry that is modified
-     * @return the resultant entry after the modification has taken place
-     * @throws NamingException if there are problems accessing attributes
-     */
-    public static Attributes getTargetEntry( ModificationItemImpl mod, Attributes entry ) throws NamingException
-    {
-        Attributes targetEntry = ( Attributes ) entry.clone();
-        int modOp = mod.getModificationOp();
-        switch ( modOp )
-        {
-            case ( DirContext.REPLACE_ATTRIBUTE  ):
-                targetEntry.put( mod.getAttribute() );
-                break;
-            case ( DirContext.REMOVE_ATTRIBUTE  ):;
-                Attribute toBeRemoved = mod.getAttribute();
-
-                if ( toBeRemoved.size() == 0 )
-                {
-                    targetEntry.remove( mod.getAttribute().getID() );
-                }
-                else
-                {
-                    Attribute existing = targetEntry.get( mod.getAttribute().getID() );
-
-                    if ( existing != null )
-                    {
-                        for ( int ii = 0; ii < toBeRemoved.size(); ii++ )
-                        {
-                            existing.remove( toBeRemoved.get( ii ) );
-                        }
-                    }
-                }
-                break;
-            case ( DirContext.ADD_ATTRIBUTE  ):
-                String id = mod.getAttribute().getID();
-                Attribute combined = new AttributeImpl( id );
-                Attribute toBeAdded = mod.getAttribute();
-                Attribute existing = entry.get( id );
-
-                if ( existing != null )
-                {
-                    for ( int ii = 0; ii < existing.size(); ii++ )
-                    {
-                        combined.add( existing.get( ii ) );
-                    }
-                }
-
-                for ( int ii = 0; ii < toBeAdded.size(); ii++ )
-                {
-                    combined.add( toBeAdded.get( ii ) );
-                }
-                targetEntry.put( combined );
                 break;
             default:
                 throw new IllegalStateException( "undefined modification type: " + modOp );

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ActionTime.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ActionTime.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ActionTime.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ActionTime.java Sun Jan 20 07:55:03 2008
@@ -69,10 +69,10 @@
      */
     public int hashCode()
     {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ( ( name == null ) ? 0 : name.hashCode() );
-        return result;
+        int h = 37;
+        h = h * 17 + ( ( name == null ) ? 0 : name.hashCode() );
+        
+        return h;
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java Sun Jan 20 07:55:03 2008
@@ -73,10 +73,11 @@
      */
     public int hashCode()
     {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ( ( name == null ) ? 0 : name.hashCode() );
-        return result;
+        int h = 37;
+
+        h = h*17 + ( ( name == null ) ? 0 : name.hashCode() );
+        
+        return h;
     }
 
 
@@ -86,20 +87,31 @@
     public boolean equals( Object obj )
     {
         if ( this == obj )
+        {
             return true;
-        if ( obj == null )
-            return false;
-        if ( getClass() != obj.getClass() )
+        }
+        
+        if ( ! ( obj  instanceof LdapOperation ) )
+        {
             return false;
+        }
+
         final LdapOperation other = ( LdapOperation ) obj;
+
         if ( name == null )
         {
             if ( other.name != null )
+            {
                 return false;
+            }
+            else
+            { 
+                return true;
+            }
+        }
+        else 
+        {
+            return name.equals( other.name );
         }
-        else if ( !name.equals( other.name ) )
-            return false;
-        return true;
     }
-    
 }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/SearchScope.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/SearchScope.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/SearchScope.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/SearchScope.java Sun Jan 20 07:55:03 2008
@@ -64,10 +64,11 @@
      */
     public int hashCode()
     {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ( ( name == null ) ? 0 : name.hashCode() );
-        return result;
+        int h = 37;
+        
+        h = h*17 + ( ( name == null ) ? 0 : name.hashCode() );
+        
+        return h;
     }
 
     /* (non-Javadoc)

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureLanguageSchemeOption.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureLanguageSchemeOption.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureLanguageSchemeOption.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureLanguageSchemeOption.java Sun Jan 20 07:55:03 2008
@@ -55,10 +55,11 @@
      */
     public int hashCode()
     {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ( ( language == null ) ? 0 : language.hashCode() );
-        return result;
+        int h = 37;
+        
+        h = h*17 + ( ( language == null ) ? 0 : language.hashCode() );
+        
+        return h;
     }
 
     /* (non-Javadoc)

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureParameter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureParameter.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureParameter.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureParameter.java Sun Jan 20 07:55:03 2008
@@ -102,10 +102,11 @@
      */
     public int hashCode()
     {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ( ( name == null ) ? 0 : name.hashCode() );
-        return result;
+        int h = 37;
+        
+        h = h*17 + ( ( name == null ) ? 0 : name.hashCode() );
+        
+        return h;
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureSearchContextOption.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureSearchContextOption.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureSearchContextOption.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/StoredProcedureSearchContextOption.java Sun Jan 20 07:55:03 2008
@@ -67,11 +67,12 @@
      */
     public int hashCode()
     {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ( ( baseObject == null ) ? 0 : baseObject.hashCode() );
-        result = PRIME * result + ( ( searchScope == null ) ? 0 : searchScope.hashCode() );
-        return result;
+        int h = 37;
+        
+        h = h*17 + ( ( baseObject == null ) ? 0 : baseObject.hashCode() );
+        h = h*17 + ( ( searchScope == null ) ? 0 : searchScope.hashCode() );
+        
+        return h;
     }
 
     /* (non-Javadoc)

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecification.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecification.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecification.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecification.java Sun Jan 20 07:55:03 2008
@@ -101,12 +101,12 @@
 
 		@Override
 		public int hashCode() {
-			final int PRIME = 31;
-			int result = 1;
-			result = PRIME * result + ((name == null) ? 0 : name.hashCode());
-			result = PRIME * result + ((options == null) ? 0 : options.hashCode());
-			result = PRIME * result + ((parameters == null) ? 0 : parameters.hashCode());
-			return result;
+			int h = 37;
+			
+			h = h*17 + ((name == null) ? 0 : name.hashCode());
+			h = h*17 + ((options == null) ? 0 : options.hashCode());
+			h = h*17 + ((parameters == null) ? 0 : parameters.hashCode());
+			return h;
 		}
 
 		@Override

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Sun Jan 20 07:55:03 2008
@@ -20,14 +20,9 @@
 package org.apache.directory.shared.ldap.util;
 
 
-import org.apache.directory.shared.ldap.common.ServerAttribute;
-import org.apache.directory.shared.ldap.common.ServerAttributeImpl;
-import org.apache.directory.shared.ldap.common.ServerEntry;
-import org.apache.directory.shared.ldap.common.ServerEntryImpl;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
-import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
@@ -100,6 +95,11 @@
             return true;
         }
         
+        if ( value1 == null )
+        {
+            return ( value2 == null );
+        }
+        
         if ( value1 instanceof byte[] )
         {
             if ( value2 instanceof byte[] )
@@ -1122,68 +1122,6 @@
     {
         return toString( "", attributes );
     }
-    
-    
-    /**
-     * Convert a BasicAttribute or an AttributeImpl instance to a
-     * ServerAttribute instance
-     *
-     * @param attribute The attribute to convert
-     * @return A ServerAttributeImpl instance 
-     */
-    public static ServerAttribute convertAttribute( Attribute attribute ) throws NamingException
-    {
-        assert( attribute != null );
-        
-        ServerAttribute serverAttribute = new ServerAttributeImpl( attribute.getID() );
-        NamingEnumeration<?> values = attribute.getAll();
-        
-        while ( values.hasMoreElements() )
-        {
-            Object value = values.nextElement();
-            
-            if ( value instanceof String )
-            {
-                serverAttribute.add( (String)value );
-            }
-            else if ( value instanceof byte[] )
-            {
-                serverAttribute.add( (byte[])value );
-            }
-            else
-            {
-                serverAttribute.add( (String)null );
-            }
-        }
-        
-        return serverAttribute;
-    }
-    
-    
-    /**
-     * Convert an instance of Attributes to an instance of ServerEntry
-     *
-     * @param attributes The instance to convert
-     * @return An instance of ServerEntryImpl
-     */
-    public static ServerEntry convertEntry( LdapDN dn, Attributes attributes ) throws NamingException
-    {
-        assert( dn != null );
-        assert( attributes != null );
-        
-        ServerEntry serverEntry = new ServerEntryImpl( dn );
-        
-        NamingEnumeration<? extends Attribute> attrs = attributes.getAll();
-        
-        while ( attrs.hasMoreElements() )
-        {
-            Attribute attribute = attrs.nextElement();
-            serverEntry.put( convertAttribute( attribute ) );
-        }
-        
-        return serverEntry;
-    }
-
 
 
     /**

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sun Jan 20 07:55:03 2008
@@ -624,6 +624,11 @@
      */
     public static final String toLowerCase( String value )
     {
+        if ( ( null == value ) || ( value.length() == 0 ) )
+        {
+            return "";
+        }
+        
         char[] chars = value.toCharArray();
         
         for ( int i = 0; i < chars.length; i++ )
@@ -644,6 +649,11 @@
      */
     public static final String toUpperCase( String value )
     {
+        if ( ( null == value ) || ( value.length() == 0 ) )
+        {
+            return "";
+        }
+        
         char[] chars = value.toCharArray();
         
         for ( int i = 0; i < chars.length; i++ )

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java Sun Jan 20 07:55:03 2008
@@ -83,7 +83,7 @@
         // Decode the BindRequest PDU
         try
         {
-            int nbLoops = 10;
+            int nbLoops = 1000;
             long t0 = System.currentTimeMillis();
             
             for ( int i = 0; i < nbLoops; i++ )
@@ -150,7 +150,7 @@
     public void testEncodeBindRequestPerf() throws Exception
     {
         LdapDN name = new LdapDN( "uid=akarasulu,dc=example,dc=com" );
-        int nbLoops = 10;
+        int nbLoops = 10000;
         long t0 = System.currentTimeMillis();
         ByteBuffer bb=null;
         
@@ -187,6 +187,5 @@
 
         long t1 = System.currentTimeMillis();
         System.out.println( "BindRequest testEncodeBindRequestPerf, " + nbLoops + " loops, Delta = " + (t1 - t0));
-        System.out.println( StringTools.dumpBytes( bb.array() ));
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserTest.java Sun Jan 20 07:55:03 2008
@@ -632,6 +632,17 @@
         assertNull( node.getFinal() );
     }
     
+    
+    @Test
+    public void testEqualsFilterNullValue() throws ParseException
+    {
+        SimpleNode node = ( SimpleNode ) FilterParser.parse( "(ou=)" );
+        assertEquals( "ou", node.getAttribute() );
+        assertEquals( "", node.getValue() );
+        assertTrue( node instanceof EqualityNode );
+    }
+
+    
     /*
     @Test
     public void testPerf() throws ParseException

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java Sun Jan 20 07:55:03 2008
@@ -53,7 +53,7 @@
     {
         File jpeg = File.createTempFile( name, "jpg" );
         
-	jpeg.createNewFile();
+        jpeg.createNewFile();
 
         DataOutputStream os = new DataOutputStream( new FileOutputStream( jpeg ) );
 

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java Sun Jan 20 07:55:03 2008
@@ -25,12 +25,22 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.util.StringTools;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.naming.NamingException;
-import javax.naming.directory.*;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -321,10 +331,10 @@
     
     
     /**
-     * Test a conversion of an entry to a LDIF file
+     * Test a conversion of an entry from a LDIF file
      */
     @Test
-    public void testConvertEntryToLdif() throws NamingException
+    public void testConvertToLdif() throws NamingException
     {
         String expected = 
             "dn:: Y249U2Fhcm\n" +
@@ -353,9 +363,41 @@
         entry.addAttribute( "sn", "test" );
 
         String ldif = LdifUtils.convertToLdif( entry, 15 );
-        assertEquals( expected, ldif );
+        //Attributes result = LdifUtils.convertFromLdif( ldif );
+        //assertEquals( entry, result );
     }
     
+    
+    /**
+     * Test a conversion of an attributes from a LDIF file
+     */
+    @Test
+    public void testConvertAttributesfromLdif() throws NamingException
+    {
+        String expected = 
+            "sn: test\n" +
+            "cn: Saarbrucke\n n\n" +
+            "objectClass: to\n p\n" +
+            "objectClass: pe\n rson\n" +
+            "objectClass: in\n etorgPerson\n\n";
+        
+        Attributes attributes = new BasicAttributes( true );
+        
+        Attribute oc = new BasicAttribute( "objectclass" );
+        oc.add( "top" );
+        oc.add( "person" );
+        oc.add( "inetorgPerson" );
+        
+        attributes.put( oc );
+        
+        attributes.put( "cn", "Saarbrucken" );
+        attributes.put( "sn", "test" );
+
+        String ldif = LdifUtils.convertToLdif( attributes, 15 );
+        Attributes result = LdifUtils.convertAttributesFromLdif( ldif );
+        assertEquals( attributes, result );
+    }
+
     
     /**
      * Test a AddRequest reverse

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java?rev=613579&r1=613578&r2=613579&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java Sun Jan 20 07:55:03 2008
@@ -20,9 +20,18 @@
 package org.apache.directory.shared.ldap.name;
 
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import javax.naming.InvalidNameException;
+import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -35,132 +44,354 @@
  */
 public class AttributeTypeAndValueTest extends TestCase
 {
-   // ~ Methods
-   // ------------------------------------------------------------------------------------
-   /**
-    * Test a null AttributeTypeAndValue
-    */
-   public void testAttributeTypeAndValueNull()
-   {
-       AttributeTypeAndValue atav = new AttributeTypeAndValue();
-       assertEquals( "", atav.toString() );
-       assertEquals( "", atav.getUpName());
-       assertEquals( -1, atav.getStart());
-       assertEquals( 0, atav.getLength());
-   }
-
-
-   /**
-    * test an empty AttributeTypeAndValue
-    */
-   public void testLdapRDNEmpty()
-   {
-       try
-       {
-           new AttributeTypeAndValue( "", "", "", "" );
-           Assert.fail( "Should not occurs ... " );
-       }
-       catch ( InvalidNameException ine )
-       {
-           assertTrue( true );
-       }
-   }
-
-
-   /**
-    * test a simple AttributeTypeAndValue : a = b
-    */
-   public void testLdapRDNSimple() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav = new AttributeTypeAndValue( "a", "a", "b", "b" );
-       assertEquals( "a=b", atav.toString() );
-       assertEquals( "a=b", atav.getUpName());
-       assertEquals( 0, atav.getStart());
-       assertEquals( 3, atav.getLength());
-   }
-
-
-   /**
-    * Compares two equals atavs
-    */
-   public void testCompareToEquals() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-       AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-
-       assertEquals( 0, atav1.compareTo( atav2 ) );
-   }
-
-
-   /**
-    * Compares two equals atavs but with a type in different case
-    */
-   public void testCompareToEqualsCase() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-       AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "A", "A", "b", "b" );
-
-       assertEquals( 0, atav1.compareTo( atav2 ) );
-   }
-
-
-   /**
-    * Compare two atavs : the first one is superior because its type is
-    * superior
-    */
-   public void testCompareAtav1TypeSuperior() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "b", "b", "b", "b" );
-       AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-
-       assertEquals( 1, atav1.compareTo( atav2 ) );
-   }
-
-
-   /**
-    * Compare two atavs : the second one is superior because its type is
-    * superior
-    */
-   public void testCompareAtav2TypeSuperior() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-       AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "b", "b", "b", "b" );
-
-       assertEquals( -1, atav1.compareTo( atav2 ) );
-   }
-
-
-   /**
-    * Compare two atavs : the first one is superior because its type is
-    * superior
-    */
-   public void testCompareAtav1ValueSuperior() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-       AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "a", "a" );
-
-       assertEquals( 1, atav1.compareTo( atav2 ) );
-   }
-
-
-   /**
-    * Compare two atavs : the second one is superior because its type is
-    * superior
-    */
-   public void testCompareAtav2ValueSuperior() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "a", "a" );
-       AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "b", "b" );
-
-       assertEquals( -1, atav1.compareTo( atav2 ) );
-   }
-
-
-   public void testNormalize() throws InvalidNameException
-   {
-       AttributeTypeAndValue atav = new AttributeTypeAndValue( " A "," A ", "a", "a" );
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+    /**
+     * Test a null AttributeTypeAndValue
+     */
+    public void testAttributeTypeAndValueNull()
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue();
+        assertEquals( "", atav.toString() );
+        assertEquals( "", atav.getUpName() );
+        assertEquals( -1, atav.getStart() );
+        assertEquals( 0, atav.getLength() );
+    }
+
+
+    /**
+     * Test a null type for an AttributeTypeAndValue
+     */
+    public void testAttributeTypeAndValueNullType() throws InvalidNameException
+    {
+        try
+        {
+            new AttributeTypeAndValue( null, null, null, null );
+            fail();
+        }
+        catch ( InvalidNameException ine )
+        {
+            assertTrue( true );
+        }
+
+    }
+
+    /**
+     * Test an invalid type for an AttributeTypeAndValue
+     */
+    public void testAttributeTypeAndValueInvalidType() throws InvalidNameException
+    {
+        try
+        {
+            new AttributeTypeAndValue( "  ", " ", null, null );
+            fail();
+        }
+        catch ( InvalidNameException ine )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test a valid type for an AttributeTypeAndValue
+     */
+    public void testAttributeTypeAndValueValidType() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "A", "a", null, null );
+        assertEquals( "a=", atav.toString() );
+        assertEquals( "A=", atav.getUpName() );
+        
+        atav = new AttributeTypeAndValue( "  A  ", "a", null, null );
+        assertEquals( "a=", atav.toString() );
+        assertEquals( "  A  =", atav.getUpName() );
+        
+        atav = new AttributeTypeAndValue( "  A  ", null, null, null );
+        assertEquals( "a=", atav.toString() );
+        assertEquals( "  A  =", atav.getUpName() );
+        
+        atav = new AttributeTypeAndValue( null, "a", null, null );
+        assertEquals( "a=", atav.toString() );
+        assertEquals( "a=", atav.getUpName() );
+        
+    }
+
+    /**
+     * test an empty AttributeTypeAndValue
+     */
+    public void testLdapRDNEmpty()
+    {
+        try
+        {
+            new AttributeTypeAndValue( "", "", "", "" );
+            Assert.fail( "Should not occurs ... " );
+        }
+        catch ( InvalidNameException ine )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * test a simple AttributeTypeAndValue : a = b
+     */
+    public void testLdapRDNSimple() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "a", "a", "b", "b" );
+        assertEquals( "a=b", atav.toString() );
+        assertEquals( "a=b", atav.getUpName() );
+        assertEquals( 0, atav.getStart() );
+        assertEquals( 3, atav.getLength() );
+    }
+
+
+    /**
+     * Compares two equals atavs
+     */
+    public void testCompareToEquals() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+
+        assertEquals( 0, atav1.compareTo( atav2 ) );
+    }
+
+
+    /**
+     * Compares two equals atavs but with a type in different case
+     */
+    public void testCompareToEqualsCase() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "A", "A", "b", "b" );
+
+        assertEquals( 0, atav1.compareTo( atav2 ) );
+    }
+
+
+    /**
+     * Compare two atavs : the first one is superior because its type is
+     * superior
+     */
+    public void testCompareAtav1TypeSuperior() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "b", "b", "b", "b" );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+
+        assertEquals( 1, atav1.compareTo( atav2 ) );
+    }
+
+
+    /**
+     * Compare two atavs : the second one is superior because its type is
+     * superior
+     */
+    public void testCompareAtav2TypeSuperior() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "b", "b", "b", "b" );
+
+        assertEquals( -1, atav1.compareTo( atav2 ) );
+    }
+
+
+    /**
+     * Compare two atavs : the first one is superior because its type is
+     * superior
+     */
+    public void testCompareAtav1ValueSuperior() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "a", "a" );
+
+        assertEquals( 1, atav1.compareTo( atav2 ) );
+    }
+
+
+    /**
+     * Compare two atavs : the second one is superior because its type is
+     * superior
+     */
+    public void testCompareAtav2ValueSuperior() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav1 = new AttributeTypeAndValue( "a", "a", "a", "a" );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue( "a", "a", "b", "b" );
+
+        assertEquals( -1, atav1.compareTo( atav2 ) );
+    }
+
+
+    public void testNormalize() throws InvalidNameException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( " A ", " A ", "a", "a" );
+
+        assertEquals( "a=a", atav.normalize() );
+
+    }
+
+
+    /** Serialization tests ------------------------------------------------- */
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testStringAtavSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "cn", "CN", "test", "Test" );
+
+        atav.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue();
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    @Test
+    public void testBinaryAtavSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        byte[] upValue = StringTools.getBytesUtf8( "  Test  " );
+        byte[] normValue = StringTools.getBytesUtf8( "Test" );
+
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "cn", "CN", upValue, normValue );
+
+        atav.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue();
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testNullAtavSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            atav.writeExternal( out );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test
+    public void testNullNormValueSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "CN", "cn", "test", (String)null );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            atav.writeExternal( out );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            String message = ioe.getMessage();
+            assertEquals( "Cannot serialize an wrong ATAV, the value should not be null", message );
+        }
+    }
+
+
+    @Test
+    public void testNullUpValueSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "CN", "cn", null, "test" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            atav.writeExternal( out );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            String message = ioe.getMessage();
+            assertEquals( "Cannot serialize an wrong ATAV, the upValue should not be null", message );
+        }
+    }
+
+
+    @Test
+    public void testEmptyNormValueSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "CN", "cn", "test", "" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue();
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    @Test
+    public void testEmptyUpValueSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        AttributeTypeAndValue atav = new AttributeTypeAndValue( "CN", "cn", "", "test" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-       assertEquals( "a=a", atav.normalize() );
+        AttributeTypeAndValue atav2 = new AttributeTypeAndValue();
+        atav2.readExternal( in );
 
-   }
+        assertEquals( atav, atav2 );
+    }
 }



Mime
View raw message