directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r612325 [1/2] - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/entry/ main/java/org/apache/directory/shared/ldap/entry/client/ main/java/org/apache/directory/shared/ldap/name/ test/java/org/apache...
Date Wed, 16 Jan 2008 00:33:12 GMT
Author: elecharny
Date: Tue Jan 15 16:33:09 2008
New Revision: 612325

URL: http://svn.apache.org/viewvc?rev=612325&view=rev
Log:
Modified the Add request to ma,ipulate ServerEntry instead of Attributes

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStreamedValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStringValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractBinaryValue.java Tue Jan 15 16:33:09 2008
@@ -37,7 +37,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public abstract class AbstractBinaryValue implements Value<byte[]>, Cloneable
+public abstract class AbstractBinaryValue implements Value<byte[]>
 {
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( AbstractBinaryValue.class );

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStreamedValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStreamedValue.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStreamedValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStreamedValue.java Tue Jan 15 16:33:09 2008
@@ -33,7 +33,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public abstract class AbstractStreamedValue implements Value<URI>, Cloneable
+public abstract class AbstractStreamedValue implements Value<URI>
 {
     /** The URI pointing to the stored data */
     private URI wrapped;

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStringValue.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractStringValue.java Tue Jan 15 16:33:09 2008
@@ -32,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public abstract class AbstractStringValue implements Value<String>, Cloneable
+public abstract class AbstractStringValue implements Value<String>
 {
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( AbstractStringValue.class );

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java Tue Jan 15 16:33:09 2008
@@ -22,6 +22,8 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 import javax.naming.NamingException;
+
+import java.io.Serializable;
 import java.util.Iterator;
 import java.util.List;
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java Tue Jan 15 16:33:09 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.directory.shared.ldap.entry;
 
+import java.io.Serializable;
 import java.util.Iterator;
 
 import javax.naming.NamingException;
@@ -31,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface EntryAttribute<T extends Value<?>>
+public interface EntryAttribute<T extends Value<?>> extends Iterable<T>, Serializable, Cloneable
 {
     /**
      * Adds some values to this attribute. If the new values are already present in

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java Tue Jan 15 16:33:09 2008
@@ -19,6 +19,10 @@
  */
 package org.apache.directory.shared.ldap.entry;
 
+import java.io.Serializable;
+
+import javax.naming.NamingException;
+
 
 /**
  * A interface for wrapping attribute values stored into an EntryAttribute. These
@@ -27,7 +31,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface Value<T>
+public interface Value<T> extends Cloneable, Serializable
 {
     /**
      * Sets the wrapped value.

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/AbstractClientAttribute.java Tue Jan 15 16:33:09 2008
@@ -41,7 +41,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public abstract class AbstractClientAttribute implements ClientAttribute, Cloneable
+public abstract class AbstractClientAttribute implements ClientAttribute
 {
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( AbstractClientAttribute.class );

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientAttribute.java Tue Jan 15 16:33:09 2008
@@ -32,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ClientAttribute extends EntryAttribute<ClientValue<?>>, Iterable<ClientValue<?>>, Cloneable
+public interface ClientAttribute extends EntryAttribute<ClientValue<?>>
 {
     /**
      * Get's the user provided identifier for this entry.  This is the value

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java Tue Jan 15 16:33:09 2008
@@ -41,8 +41,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ClientBinaryValue extends AbstractBinaryValue implements ClientValue<byte[]>, Cloneable
+public class ClientBinaryValue extends AbstractBinaryValue implements ClientValue<byte[]>
 {
+    /** Used for serialization */
+    public static final long serialVersionUID = 2L;
+    
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ClientBinaryValue.class );
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java Tue Jan 15 16:33:09 2008
@@ -40,8 +40,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ClientStringValue extends AbstractStringValue implements ClientValue<String>, Cloneable
+public class ClientStringValue extends AbstractStringValue implements ClientValue<String>
 {
+    /** Used for serialization */
+    public static final long serialVersionUID = 2L;
+    
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ClientStringValue.class );
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java Tue Jan 15 16:33:09 2008
@@ -41,6 +41,9 @@
  */
 public final class DefaultClientAttribute extends AbstractClientAttribute
 {
+    /** Used for serialization */
+    public static final long serialVersionUID = 2L;
+    
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( DefaultClientAttribute.class );
     

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java Tue Jan 15 16:33:09 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 " );
         }
 
@@ -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/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Tue Jan 15 16:33:09 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 );
         }
 
@@ -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/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Tue Jan 15 16:33:09 2008
@@ -20,7 +20,12 @@
 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.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -35,6 +40,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 +110,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
@@ -1268,5 +1278,121 @@
        }
 
        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/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java Tue Jan 15 16:33:09 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/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java Tue Jan 15 16:33:09 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/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java?rev=612325&r1=612324&r2=612325&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValueTest.java Tue Jan 15 16:33:09 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