directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1079453 [1/2] - in /directory: apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ shared/trunk/integ/src/test/java/org/apac...
Date Tue, 08 Mar 2011 17:56:55 GMT
Author: elecharny
Date: Tue Mar  8 17:56:54 2011
New Revision: 1079453

URL: http://svn.apache.org/viewvc?rev=1079453&view=rev
Log:
Reworked the Serialization to remove the duplicated code, and to have the Externalizable interface implemented correctly.
Done for Values, Ava, Rdn, Dn.

Added:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareDnSerializerTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareRdnSerializerTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnSerializerTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnSerializerTest.java
Modified:
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ModificationTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ValueSerializerTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java (original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java Tue Mar  8 17:56:54 2011
@@ -42,8 +42,6 @@ import java.util.Set;
 import javax.naming.directory.InvalidAttributeValueException;
 
 import org.apache.commons.io.FileUtils;
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.model.entry.BinaryValue;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntryAttribute;
 import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
@@ -57,13 +55,16 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
 import org.apache.directory.shared.util.StringConstants;
 import org.apache.directory.shared.util.Strings;
+import org.apache.directory.shared.util.exception.Exceptions;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Tests for the DefaultEntryAttribute class
@@ -161,7 +162,7 @@ public class SchemaAwareEntryAttributeTe
         try
         {
             oOut = new ObjectOutputStream( out );
-            value.serialize( oOut );
+            value.writeExternal( oOut );
         }
         catch ( IOException ioe )
         {
@@ -201,7 +202,7 @@ public class SchemaAwareEntryAttributeTe
             oIn = new ObjectInputStream( in );
 
             DefaultEntryAttribute value = new DefaultEntryAttribute( at );
-            value.deserialize( oIn );
+            value.readExternal( oIn );
 
             return value;
         }

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java (original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java Tue Mar  8 17:56:54 2011
@@ -34,13 +34,11 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.List;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
 import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.model.entry.Modification;
 import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.model.entry.DefaultModification;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
@@ -53,6 +51,9 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the DefaultModification class
@@ -82,7 +83,7 @@ public class SchemaAwareModificationTest
         try
         {
             oOut = new ObjectOutputStream( out );
-            value.serialize( oOut );
+            value.writeExternal( oOut );
             oOut.flush();
         }
         catch ( IOException ioe )
@@ -123,7 +124,7 @@ public class SchemaAwareModificationTest
             oIn = new ObjectInputStream( in );
 
             DefaultModification value = new DefaultModification();
-            value.deserialize( oIn, schemaManager );
+            value.readExternal( oIn );
 
             return value;
         }
@@ -269,6 +270,7 @@ public class SchemaAwareModificationTest
         DefaultModification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
 
         Modification modSer = deserializeValue( serializeValue( mod ) );
+        modSer.setAttribute( attribute );
 
         assertEquals( mod, modSer );
     }
@@ -283,6 +285,7 @@ public class SchemaAwareModificationTest
         DefaultModification mod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
 
         Modification modSer = deserializeValue( serializeValue( mod ) );
+        modSer.setAttribute( attribute );
 
         assertEquals( mod, modSer );
     }
@@ -297,6 +300,7 @@ public class SchemaAwareModificationTest
         DefaultModification mod = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attribute );
 
         Modification modSer = deserializeValue( serializeValue( mod ) );
+        modSer.setAttribute( attribute );
 
         assertEquals( mod, modSer );
     }
@@ -309,14 +313,8 @@ public class SchemaAwareModificationTest
 
         mod.setOperation( ModificationOperation.ADD_ATTRIBUTE );
 
-        try
-        {
-            deserializeValue( serializeValue( ( DefaultModification ) mod ) );
-            fail();
-        }
-        catch ( IOException ioe )
-        {
-            assertTrue( true );
-        }
+        Modification modSer = deserializeValue( serializeValue( ( DefaultModification ) mod ) );
+
+        assertEquals( mod, modSer );
     }
 }

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java Tue Mar  8 17:56:54 2011
@@ -42,7 +42,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.name.DnSerializer;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
-import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -117,22 +116,22 @@ public class ReplicaEventMessage impleme
             modDnControl = new SyncModifyDnDecorator( codec );
             modDnControl.setModDnType( modDnType );
             
-            modDnControl.setEntryDn( Unicode.readUTF(in) );
+            modDnControl.setEntryDn( in.readUTF() );
             
             switch( modDnType )
             {
                 case MOVE:
-                    modDnControl.setNewSuperiorDn( Unicode.readUTF(in) );
+                    modDnControl.setNewSuperiorDn( in.readUTF() );
                     break;
                    
                 case RENAME:
-                    modDnControl.setNewRdn( Unicode.readUTF(in) );
+                    modDnControl.setNewRdn( in.readUTF() );
                     modDnControl.setDeleteOldRdn( in.readBoolean() );
                     break;
                     
                 case MOVEANDRENAME:
-                    modDnControl.setNewSuperiorDn( Unicode.readUTF(in) );
-                    modDnControl.setNewRdn( Unicode.readUTF(in) );
+                    modDnControl.setNewSuperiorDn( in.readUTF() );
+                    modDnControl.setNewRdn( in.readUTF() );
                     modDnControl.setDeleteOldRdn( in.readBoolean() );
             }
         }
@@ -165,7 +164,7 @@ public class ReplicaEventMessage impleme
         for ( int i = 0; i < nbAttributes; i++ )
         {
             // Read the attribute's OID
-            String oid = Unicode.readUTF(in);
+            String oid = in.readUTF();
 
             try
             {
@@ -175,7 +174,7 @@ public class ReplicaEventMessage impleme
                 DefaultEntryAttribute attribute = new DefaultEntryAttribute( attributeType );
 
                 // Read the attribute
-                attribute.deserialize( in );
+                attribute.readExternal( in );
 
                 entry.add( attribute );
             }
@@ -197,22 +196,22 @@ public class ReplicaEventMessage impleme
             
             SyncModifyDnType modDnType = modDnControl.getModDnType();
             out.writeShort( modDnType.getValue() );
-            Unicode.writeUTF(out, modDnControl.getEntryDn());
+            out.writeUTF( modDnControl.getEntryDn() );
             
             switch( modDnType )
             {
                 case MOVE:
-                    Unicode.writeUTF(out, modDnControl.getNewSuperiorDn());
+                    out.writeUTF( modDnControl.getNewSuperiorDn() );
                     break;
                    
                 case RENAME:
-                    Unicode.writeUTF(out, modDnControl.getNewRdn());
+                    out.writeUTF( modDnControl.getNewRdn() );
                     out.writeBoolean( modDnControl.isDeleteOldRdn() );
                     break;
                     
                 case MOVEANDRENAME:
-                    Unicode.writeUTF(out, modDnControl.getNewSuperiorDn());
-                    Unicode.writeUTF(out, modDnControl.getNewRdn());
+                    out.writeUTF( modDnControl.getNewSuperiorDn() );
+                    out.writeUTF( modDnControl.getNewRdn() );
                     out.writeBoolean( modDnControl.isDeleteOldRdn() );
             }
         }
@@ -223,7 +222,7 @@ public class ReplicaEventMessage impleme
         }
 
         // then Dn
-        DnSerializer.serialize( entry.getDn(), out );
+        entry.getDn().writeExternal( out );
 
         // Then the attributes.
         out.writeInt( entry.size() );
@@ -233,15 +232,16 @@ public class ReplicaEventMessage impleme
         // we need access to the registries, which are not available
         // in the ServerAttribute class.
         Iterator<EntryAttribute> attrItr = entry.iterator();
+        
         while ( attrItr.hasNext() )
         {
             DefaultEntryAttribute attribute = ( DefaultEntryAttribute ) attrItr.next();
             // Write the oid to be able to restore the AttributeType when deserializing
             // the attribute
-            Unicode.writeUTF(out, attribute.getAttributeType().getOid());
+            out.writeUTF( attribute.getAttributeType().getOid() );
 
             // Write the attribute
-            attribute.serialize( out );
+            attribute.writeExternal( out );
         }
     }
 

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java (original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java Tue Mar  8 17:56:54 2011
@@ -64,8 +64,9 @@ public class SchemaAwareValueSerializerT
     private static StringValue sv2n;
     private static StringValue sv3n;
     
-    
     private static SchemaManager schemaManager;
+    private static AttributeType cn = null;
+    private static AttributeType userCertificate = null;
 
     /**
      * Initialize OIDs maps for normalization
@@ -74,8 +75,8 @@ public class SchemaAwareValueSerializerT
     public static void setup() throws Exception
     {
         schemaManager = new DefaultSchemaManager();
-        AttributeType cn = schemaManager.getAttributeType( "cn" );
-        AttributeType userCertificate = schemaManager.getAttributeType( "userCertificate" );
+        cn = schemaManager.getAttributeType( "cn" );
+        userCertificate = schemaManager.getAttributeType( "userCertificate" );
         
         bv1 = new BinaryValue( userCertificate, data );
         bv2 = new BinaryValue( userCertificate, StringConstants.EMPTY_BYTES );
@@ -93,234 +94,246 @@ public class SchemaAwareValueSerializerT
 
     
     @Test
-    public void testBinaryValueWithDataSerialization() throws IOException
+    public void testBinaryValueWithDataSerialization() throws IOException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        BinaryValue.serialize( bv1, out );
+        bv1.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+        BinaryValue bvDeser = new BinaryValue( (AttributeType)null );
+        bvDeser.readExternal( in );
 
         assertEquals( bv1, bvDeser );
     }
     
     
     @Test
-    public void testBinaryValueWithEmptyDataSerialization() throws IOException
+    public void testBinaryValueWithEmptyDataSerialization() throws IOException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        BinaryValue.serialize( bv2, out );
+        bv2.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+        BinaryValue bvDeser = new BinaryValue( (AttributeType)null );
+        bvDeser.readExternal( in );
 
         assertEquals( bv2, bvDeser );
     }
     
     
     @Test
-    public void testBinaryValueNoDataSerialization() throws IOException
+    public void testBinaryValueNoDataSerialization() throws IOException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        BinaryValue.serialize( bv3, out );
+        bv3.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+        BinaryValue bvDeser = new BinaryValue( (AttributeType)null );
+        bvDeser.readExternal( in );
 
         assertEquals( bv3, bvDeser );
     }
     
     
     @Test
-    public void testStringValueWithDataSerialization() throws IOException
+    public void testStringValueWithDataSerialization() throws IOException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        StringValue.serialize( sv1, out );
+        sv1.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+        StringValue svDeser = new StringValue( (AttributeType)null );
+        svDeser.readExternal( in );
 
         assertEquals( sv1, svDeser );
     }
     
     
     @Test
-    public void testStringValueWithEmptyDataSerialization() throws IOException
+    public void testStringValueWithEmptyDataSerialization() throws IOException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        StringValue.serialize( sv2, out );
+        sv2.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+        StringValue svDeser = new StringValue( (AttributeType)null );
+        svDeser.readExternal( in );
 
         assertEquals( sv2, svDeser );
     }
     
     
     @Test
-    public void testStringValueNoDataSerialization() throws IOException
+    public void testStringValueNoDataSerialization() throws IOException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        StringValue.serialize( sv3, out );
+        sv3.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+        StringValue svDeser = new StringValue( (AttributeType)null );
+        svDeser.readExternal( in );
 
         assertEquals( sv3, svDeser );
     }
     
     
     @Test
-    public void testBinaryValueWithDataNormalizedSerialization() throws IOException, LdapException
+    public void testBinaryValueWithDataNormalizedSerialization() throws IOException, LdapException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
         bv1n.normalize();
 
-        BinaryValue.serialize( bv1n, out );
+        bv1n.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+        BinaryValue bvDeser = new BinaryValue( userCertificate );
+        bvDeser.readExternal( in );
 
         assertEquals( bv1n, bvDeser );
     }
     
     
     @Test
-    public void testBinaryValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException
+    public void testBinaryValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
         bv2n.normalize();
 
-        BinaryValue.serialize( bv2n, out );
+        bv2n.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+        BinaryValue bvDeser = new BinaryValue( userCertificate );
+        bvDeser.readExternal( in );
 
         assertEquals( bv2n, bvDeser );
     }
     
     
     @Test
-    public void testBinaryValueNoDataNormalizedSerialization() throws IOException, LdapException
+    public void testBinaryValueNoDataNormalizedSerialization() throws IOException, LdapException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
         bv3n.normalize();
 
-        BinaryValue.serialize( bv3n, out );
+        bv3n.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+        BinaryValue bvDeser = new BinaryValue( userCertificate );
+        bvDeser.readExternal( in );
 
         assertEquals( bv3n, bvDeser );
     }
     
     
     @Test
-    public void testStringValueWithDataNormalizedSerialization() throws IOException, LdapException
+    public void testStringValueWithDataNormalizedSerialization() throws IOException, LdapException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
         sv1n.normalize();
 
-        StringValue.serialize( sv1n, out );
+        sv1n.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+        StringValue svDeser = new StringValue( cn );
+        svDeser.readExternal( in );
 
         assertEquals( sv1n, svDeser );
     }
     
     
     @Test
-    public void testStringValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException
+    public void testStringValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
         sv2n.normalize();
 
-        StringValue.serialize( sv2n, out );
+        sv2n.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+        StringValue svDeser = new StringValue( cn );
+        svDeser.readExternal( in );
 
         assertEquals( sv2n, svDeser );
     }
     
     
     @Test
-    public void testStringValueNoDataNormalizedSerialization() throws IOException, LdapException
+    public void testStringValueNoDataNormalizedSerialization() throws IOException, LdapException, ClassNotFoundException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
         sv3n.normalize();
 
-        StringValue.serialize( sv3n, out );
+        sv3n.writeExternal( out );
         
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+        StringValue svDeser = new StringValue( cn );
+        svDeser.readExternal( in );
 
         assertEquals( sv3n, svDeser );
     }

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java (original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java Tue Mar  8 17:56:54 2011
@@ -230,14 +230,15 @@ public class AvaTest
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
 
-        out.writeObject( atav );
+        atav.writeExternal( out );
 
         ObjectInputStream in = null;
 
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Ava atav2 = (Ava)in.readObject();
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
 
         assertEquals( atav, atav2 );
     }

Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareDnSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareDnSerializerTest.java?rev=1079453&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareDnSerializerTest.java (added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareDnSerializerTest.java Tue Mar  8 17:56:54 2011
@@ -0,0 +1,128 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.name;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the Dn Serialization
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareDnSerializerTest
+{
+    private static SchemaManager schemaManager;
+
+    /**
+     * Initialize OIDs maps for normalization
+     */
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+    
+    @Test
+    public void testDnFullSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Dn dn1 = new Dn( schemaManager, "gn=john + cn=doe, dc=example, dc=com" );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn1.writeExternal( out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn1, dn2 );
+    }
+
+
+    @Test
+    public void testDnEmptySerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Dn dn1 = new Dn( schemaManager );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn1.writeExternal( out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn1, dn2 );
+    }
+
+
+    @Test
+    public void testDnSimpleSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Dn dn1 = new Dn( schemaManager, "Cn = Doe" );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn1.writeExternal( out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn1, dn2 );
+        assertEquals( "Cn = Doe", dn2.getName() );
+        assertEquals( "2.5.4.3=doe", dn2.getNormName() );
+    }
+}

Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareRdnSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareRdnSerializerTest.java?rev=1079453&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareRdnSerializerTest.java (added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/SchemaAwareRdnSerializerTest.java Tue Mar  8 17:56:54 2011
@@ -0,0 +1,128 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.name;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the Rdn Serialization
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareRdnSerializerTest
+{
+    private static SchemaManager schemaManager;
+
+    /**
+     * Initialize OIDs maps for normalization
+     */
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+    
+    @Test
+    public void testRdnFullSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "gn=john + cn=doe" );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn1.writeExternal( out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn1, rdn2 );
+    }
+
+
+    @Test
+    public void testRdnEmptySerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Rdn rdn1 = new Rdn( schemaManager );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn1.writeExternal( out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn1, rdn2 );
+    }
+
+
+    @Test
+    public void testRdnSimpleSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "cn=Doe" );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn1.writeExternal( out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn1, rdn2 );
+        assertEquals( "doe", rdn2.getValue( "cn" ) );
+        assertEquals( "Doe", rdn2.getUpValue().getString() );
+    }
+}

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java Tue Mar  8 17:56:54 2011
@@ -19,19 +19,13 @@
  */
 package org.apache.directory.shared.ldap.model.entry;
 
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.Normalizer;
-import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
-import org.apache.directory.shared.util.StringConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,7 +38,7 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractValue<T> implements Value<T>
 {
     /** logger for reporting errors that might not be handled properly upstream */
-    private static final Logger LOG = LoggerFactory.getLogger( AbstractValue.class );
+    protected static final Logger LOG = LoggerFactory.getLogger( AbstractValue.class );
 
     /** reference to the attributeType zssociated with the value */
     protected transient AttributeType attributeType;
@@ -66,7 +60,7 @@ public abstract class AbstractValue<T> i
     
     /** The computed hashcode. We don't want to compute it each time the hashcode() method is called */
     protected volatile int h;
-
+    
     /**
      * {@inheritDoc}
      */
@@ -384,7 +378,7 @@ public abstract class AbstractValue<T> i
      * @param value The Value instance to serialize
      * @param out The stream into which we will write the serialized instance
      * @throws IOException If the stream can't be written
-     */
+     *
     @SuppressWarnings("unchecked")
     public static void serialize( Value<?> value, ObjectOutput out ) throws IOException
     {
@@ -490,7 +484,7 @@ public abstract class AbstractValue<T> i
      * @param in The input stream from which the Value is read
      * @return a deserialized Value
      * @throws IOException If the stream can't be read
-     */
+     *
     @SuppressWarnings("unchecked")
     public static Value<?> deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
     {
@@ -588,4 +582,5 @@ public abstract class AbstractValue<T> i
         
         return value;
     }
+    */
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java Tue Mar  8 17:56:54 2011
@@ -30,13 +30,10 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
 import org.apache.directory.shared.ldap.model.schema.Normalizer;
-import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.model.schema.comparators.ByteArrayComparator;
 import org.apache.directory.shared.util.StringConstants;
 import org.apache.directory.shared.util.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -52,10 +49,6 @@ public class BinaryValue extends Abstrac
     /** 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( BinaryValue.class );
-
-
     /**
      * Creates a BinaryValue without an initial wrapped value.
      */
@@ -75,24 +68,20 @@ public class BinaryValue extends Abstrac
      */
     public BinaryValue( AttributeType attributeType )
     {
-        if ( attributeType == null )
-        {
-            String message = I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED );
-            LOG.error( message );
-            throw new IllegalArgumentException( message );
-        }
-
-        if ( attributeType.getSyntax() == null )
-        {
-            throw new IllegalArgumentException( I18n.err( I18n.ERR_04445 ) );
-        }
-
-        if ( attributeType.getSyntax().isHumanReadable() )
+        if ( attributeType != null )
         {
-            LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
+            if ( attributeType.getSyntax() == null )
+            {
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04445 ) );
+            }
+    
+            if ( attributeType.getSyntax().isHumanReadable() )
+            {
+                LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
+            }
+    
+            this.attributeType = attributeType;
         }
-
-        this.attributeType = attributeType;
     }
 
 
@@ -128,21 +117,29 @@ public class BinaryValue extends Abstrac
     public BinaryValue( AttributeType attributeType, byte[] value )
     {
         this( attributeType );
-        SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker();
-
-        if ( syntaxChecker != null )
+        
+        if ( attributeType != null )
         {
-            if ( syntaxChecker.isValidSyntax( value ) )
-            {
-                this.wrappedValue = value;
-            }
-            else
+            SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker();
+    
+            if ( syntaxChecker != null )
             {
-                String msg = I18n.err( I18n.ERR_04479_INVALID_SYNTAX_VALUE, value, attributeType.getName() );
-                LOG.info( msg );
-                throw new IllegalArgumentException( msg );
+                if ( syntaxChecker.isValidSyntax( value ) )
+                {
+                    this.wrappedValue = value;
+                }
+                else
+                {
+                    String msg = I18n.err( I18n.ERR_04479_INVALID_SYNTAX_VALUE, value, attributeType.getName() );
+                    LOG.info( msg );
+                    throw new IllegalArgumentException( msg );
+                }
             }
         }
+        else
+        {
+            this.wrappedValue = value;
+        }
     }
 
 
@@ -554,6 +551,13 @@ public class BinaryValue extends Abstrac
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
+        // Read the BINARY flag
+        boolean isHR = in.readBoolean();
+        
+        if ( isHR )
+        {
+            throw new IOException( "The serialized value is not a Binary value" );
+        }
         // Read the wrapped value, if it's not null
         int wrappedLength = in.readInt();
 
@@ -584,8 +588,19 @@ public class BinaryValue extends Abstrac
                 }
             }
         }
+        else
+        {
+            // Copy the wrappedValue into the normalizedValue
+            if ( wrappedLength >= 0 )
+            {
+                normalizedValue = new byte[wrappedLength];
+                
+                System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength );
+            }
+        }
 
-        h = 0;
+        // The hashCoe
+        h = in.readInt();
     }
 
 
@@ -594,6 +609,9 @@ public class BinaryValue extends Abstrac
      */
     public void writeExternal( ObjectOutput out ) throws IOException
     {
+        // Write the BINARY flag
+        out.writeBoolean( BINARY );
+        
         // Write the wrapped value, if it's not null
         if ( wrappedValue != null )
         {
@@ -633,19 +651,15 @@ public class BinaryValue extends Abstrac
         {
             out.writeBoolean( false );
         }
+        
+        // The hashCode
+        out.writeInt( h );
+        
+        out.flush();
     }
 
     
     /**
-     * {@inheritDoc}
-     */
-    public static BinaryValue deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
-    {
-        return (BinaryValue)AbstractValue.deserialize( schemaManager, in );
-    }
-
-
-    /**
      * Dumps binary in hex with label.
      *
      * @see Object#toString()

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java Tue Mar  8 17:56:54 2011
@@ -2629,7 +2629,7 @@ public class DefaultEntry implements Ent
                 DefaultEntryAttribute attribute = ( DefaultEntryAttribute ) attributes.get( attributeType.getOid() );
 
                 // Write the attribute
-                attribute.serialize( out );
+                attribute.writeExternal( out );
             }
         }
         else
@@ -2645,7 +2645,7 @@ public class DefaultEntry implements Ent
                 DefaultEntryAttribute attribute = ( DefaultEntryAttribute ) attributes.get( id );
 
                 // Write the attribute
-                attribute.serialize( out );
+                attribute.writeExternal( out );
             }
         }
     }
@@ -2690,7 +2690,7 @@ public class DefaultEntry implements Ent
                     EntryAttribute attribute = new DefaultEntryAttribute( attributeType );
 
                     // Read the attribute
-                    attribute.deserialize( in );
+                    attribute.readExternal( in );
 
                     attributes.put( attributeType.getOid(), attribute );
                 }
@@ -2714,7 +2714,7 @@ public class DefaultEntry implements Ent
                 EntryAttribute attribute = new DefaultEntryAttribute( id );
 
                 // Read the attribute
-                attribute.deserialize( in );
+                attribute.readExternal( in );
 
                 attributes.put( id, attribute );
             }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java Tue Mar  8 17:56:54 2011
@@ -34,7 +34,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
 import org.apache.directory.shared.util.Strings;
-import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -186,14 +185,10 @@ public class DefaultEntryAttribute imple
      */
     public DefaultEntryAttribute( AttributeType attributeType )
     {
-        if ( attributeType == null )
+        if ( attributeType != null )
         {
-            String message = I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED );
-            LOG.error( message );
-            throw new IllegalArgumentException( message );
+            setAttributeType( attributeType );
         }
-        
-        setAttributeType( attributeType );
     }
 
 
@@ -2414,7 +2409,7 @@ public class DefaultEntryAttribute imple
      * 
      * The inner structure is the same as the client attribute, but we can't call
      * it as we won't be able to serialize the serverValues
-     */
+     *
     public void serialize( ObjectOutput out ) throws IOException
     {
         // Write the UPId (the id will be deduced from the upID)
@@ -2439,15 +2434,8 @@ public class DefaultEntryAttribute imple
             // Write each value
             for ( Value<?> value:values )
             {
-                // Write the value, using the correct method
-                if ( value instanceof StringValue)
-                {
-                    StringValue.serialize( value, out );
-                }
-                else
-                {
-                    BinaryValue.serialize( value, out );
-                }
+                // Write the value
+                value.writeExternal( out );
             }
         }
     }
@@ -2455,7 +2443,7 @@ public class DefaultEntryAttribute imple
     
     /**
      * {@inheritDoc}
-     */
+     *
     // This will suppress PMD.EmptyCatchBlock warnings in this method
     @SuppressWarnings("PMD.EmptyCatchBlock")
     public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
@@ -2483,13 +2471,15 @@ public class DefaultEntryAttribute imple
                 
                 if ( isHR )
                 {
-                    value = StringValue.deserialize( null, in );
+                    value = new StringValue( (AttributeType)null );
                 }
                 else
                 {
-                    value  = BinaryValue.deserialize( null, in );
+                    value = new BinaryValue( (AttributeType)null );
                 }
                 
+                value.readExternal( in );
+
                 try
                 {
                     value.normalize();
@@ -2516,7 +2506,7 @@ public class DefaultEntryAttribute imple
     public void writeExternal( ObjectOutput out ) throws IOException
     {
         // Write the UPId (the id will be deduced from the upID)
-        Unicode.writeUTF(out, upId);
+        out.writeUTF( upId );
         
         // Write the HR flag, if not null
         if ( isHR != null )
@@ -2538,7 +2528,7 @@ public class DefaultEntryAttribute imple
             for ( Value<?> value:values )
             {
                 // Write the value
-                out.writeObject( value );
+                value.writeExternal( out );
             }
         }
         
@@ -2552,7 +2542,7 @@ public class DefaultEntryAttribute imple
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         // Read the ID and the UPId
-        upId = Unicode.readUTF(in);
+        upId = in.readUTF();
         
         // Compute the id
         setUpId( upId );
@@ -2570,7 +2560,20 @@ public class DefaultEntryAttribute imple
         {
             for ( int i = 0; i < nbValues; i++ )
             {
-                values.add( (Value<?>)in.readObject() );
+                Value<?> value = null;
+                
+                if ( isHR )
+                {
+                    value = new StringValue( attributeType );
+                }
+                else
+                {
+                    value = new BinaryValue( attributeType );
+                }
+                
+                value.readExternal( in );
+                
+                values.add( value );
             }
         }
     }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultModification.java Tue Mar  8 17:56:54 2011
@@ -27,7 +27,6 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
-import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,25 +39,59 @@ import org.slf4j.LoggerFactory;
 public class DefaultModification implements Modification
 {
     /** The modification operation */
-    protected ModificationOperation operation;
+    private ModificationOperation operation;
     
     /** The attribute which contains the modification */
-    protected EntryAttribute attribute;
+    private EntryAttribute attribute;
+    
+    /** The schemaManager */
+    private AttributeType attributeType;
  
     /** logger for reporting errors that might not be handled properly upstream */
     protected static final Logger LOG = LoggerFactory.getLogger( Modification.class );
 
+    
+    /**
+     * Creates a new instance of DefaultModification.
+     */
+    public DefaultModification()
+    {
+    }
+
+    
+    /**
+     * Creates a new instance of DefaultModification.
+     */
+    public DefaultModification( AttributeType attributeType )
+    {
+        this.attributeType = attributeType;
+    }
+
     /**
      * Creates a new instance of DefaultModification.
      *
      * @param operation The modification operation
-     * @param attribute The asociated attribute 
+     * @param attribute The associated attribute 
      */
     public DefaultModification( ModificationOperation operation, EntryAttribute attribute )
     {
         this.operation = operation;
         this.attribute = attribute;
     }
+
+    /**
+     * Creates a new instance of DefaultModification.
+     *
+     * @param attributeType The attributeType 
+     * @param operation The modification operation
+     * @param attribute The associated attribute 
+     */
+    public DefaultModification( AttributeType attributeType, ModificationOperation operation, EntryAttribute attribute )
+    {
+        this.attributeType = attributeType;
+        this.operation = operation;
+        this.attribute = attribute;
+    }
     
     
     /**
@@ -90,12 +123,6 @@ public class DefaultModification impleme
             LOG.error( I18n.err( I18n.ERR_04472, modAttribute.getId() ) );
         }
     }
-    /**
-     * Creates a new instance of DefaultModification.
-     */
-    public DefaultModification()
-    {
-    }
     
     
     /**
@@ -202,13 +229,17 @@ public class DefaultModification impleme
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
-        // Read the operation
-        int op = in.readInt();
-        
-        operation = ModificationOperation.getOperation( op );
+        // The operation
+        operation = ModificationOperation.getOperation( in.readInt() );
+
+        // The EntryAttribute if we have some
+        boolean hasAttribute = in.readBoolean();
         
-        // Read the attribute
-        attribute = (EntryAttribute)in.readObject();
+        if ( hasAttribute )
+        {
+            attribute = new DefaultEntryAttribute( attributeType );
+            attribute.readExternal( in );
+        }
     }
     
     
@@ -217,69 +248,25 @@ public class DefaultModification impleme
      */
     public void writeExternal( ObjectOutput out ) throws IOException
     {
-        // Write the operation
+        // The operation
         out.writeInt( operation.getValue() );
         
-        // Write the attribute
-        out.writeObject( attribute );
-        
-        out.flush();
-    }
-    
-    
-    /**
-     * Serialize a DefaultModification.
-     */
-    public void serialize( ObjectOutput out ) throws IOException
-    {
-        if ( attribute == null )
+        // The EntryAttribute if not null
+        if ( attribute != null )
         {
-            throw new IOException( I18n.err( I18n.ERR_04471 ) );
+            out.writeBoolean( true );
+            attribute.writeExternal( out );
+        }
+        else
+        {
+            out.writeBoolean( false );
         }
         
-        // Write the operation
-        out.writeInt( operation.getValue() );
-        
-        AttributeType at = attribute.getAttributeType();
-        
-        // Write the attribute's oid
-        Unicode.writeUTF(out, at.getOid());
-        
-        // Write the attribute
-        ((DefaultEntryAttribute)attribute).serialize( out );
+        out.flush();
     }
     
     
     /**
-     * Deserialize a ServerModification
-     * 
-     * @param in The buffer containing the serialized value
-     * @param schemaManager The schema manager to use
-     * @throws IOException If we weren't able to deserialize the data
-     * @throws ClassNotFoundException if we weren't able to construct a Modification instance
-     * @throws LdapException If we didn't found the AttributeType in the registries
-     */
-    public void deserialize( ObjectInput in, SchemaManager schemaManager ) throws IOException, ClassNotFoundException, LdapException
-    {
-        // Read the operation
-        int op = in.readInt();
-        
-        operation = ModificationOperation.getOperation( op );
-        
-        // Read the attribute OID
-        String oid = Unicode.readUTF(in);
-        
-        // Lookup for tha associated AttributeType
-        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
-        
-        attribute = new DefaultEntryAttribute( attributeType );
-        
-        // Read the attribute
-        ((DefaultEntryAttribute)attribute).deserialize( in );
-    }
-
-    
-    /**
      * Clone a modification
      * 
      * @return  a copied instance of the current modification

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttribute.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttribute.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttribute.java Tue Mar  8 17:56:54 2011
@@ -249,7 +249,7 @@ public interface EntryAttribute extends 
      * @exception IOException if I/O errors occur
      * @exception ClassNotFoundException if the class for an object being restored cannot be found.
      * @see Externalizable#readExternal(ObjectInput)
-     */
+     *
     void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException;
 
     

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java Tue Mar  8 17:56:54 2011
@@ -25,6 +25,7 @@ import java.io.ObjectOutput;
 
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,7 +76,7 @@ public class EntryAttributeSerializer
         {
             for ( Value<?> value : attribute )
             {
-                AbstractValue.serialize( value, out );
+                value.writeExternal( out );
             }
         }
         
@@ -111,9 +112,40 @@ public class EntryAttributeSerializer
         
         if ( nbValues > 0 )
         {
+            AttributeType attributeType = null;
+            
+            if ( schemaManager != null )
+            {
+                if ( !Strings.isEmpty( upId ) )
+                { 
+                    attributeType = schemaManager.getAttributeType( upId );
+                }
+                else
+                {
+                    attributeType = schemaManager.getAttributeType( normId );
+                }
+            }
             for ( int i = 0; i < nbValues; i++ )
             {
-                Value<?> value = AbstractValue.deserialize( schemaManager, in );
+                Value<?> value = null;
+                
+                if ( isHR )
+                {
+                    value = new StringValue( attributeType );
+                }
+                else
+                {
+                    value = new BinaryValue( attributeType );
+                }
+                
+                try
+                {
+                    value.readExternal( in );
+                }
+                catch ( ClassNotFoundException cfne )
+                {
+                    throw new IOException( cfne.getMessage() );
+                }
                 values[i] = value;
             }
         }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java Tue Mar  8 17:56:54 2011
@@ -23,7 +23,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
-import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,13 +54,7 @@ public class ModificationSerializer
      */
     public static void serialize( Modification modification, ObjectOutput out ) throws IOException
     {
-        // The operation
-        out.writeInt( modification.getOperation().getValue() );
-        
-        // The EntryAttribute
-        EntryAttributeSerializer.serialize( modification.getAttribute(), out );
-        
-        out.flush();
+        modification.writeExternal( out );
     }
     
     
@@ -72,15 +66,18 @@ public class ModificationSerializer
      * @return a deserialized Modification
      * @throws IOException If the stream can't be read
      */
-    public static Modification deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
+    public static Modification deserialize( AttributeType attributeType, ObjectInput in ) throws IOException
     {
-        // The operation
-        ModificationOperation operation = ModificationOperation.getOperation( in.readInt() );
-
-        // The EntryAttribute
-        EntryAttribute attribute = EntryAttributeSerializer.deserialize( schemaManager, in );
-
-        Modification modification = new DefaultModification( operation, attribute );
+        Modification modification = new DefaultModification( attributeType );
+        
+        try
+        {
+            modification.readExternal( in );
+        }
+        catch ( ClassNotFoundException cfne )
+        {
+            throw new IOException( cfne.getMessage() );
+        }
 
         return modification;
     }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java Tue Mar  8 17:56:54 2011
@@ -28,12 +28,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
 import org.apache.directory.shared.ldap.model.schema.Normalizer;
-import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Strings;
-import org.apache.directory.shared.util.Unicode;
 import org.apache.directory.shared.util.exception.NotImplementedException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -49,9 +45,6 @@ public class StringValue extends Abstrac
     /** Used for serialization */
     private static final long serialVersionUID = 2L;
     
-    /** logger for reporting errors that might not be handled properly upstream */
-    private static final Logger LOG = LoggerFactory.getLogger( StringValue.class );
-
     // -----------------------------------------------------------------------
     // Constructors
     // -----------------------------------------------------------------------
@@ -72,25 +65,21 @@ public class StringValue extends Abstrac
      */
     public StringValue( AttributeType attributeType )
     {
-        if ( attributeType == null )
-        {
-            String message = I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED );
-            LOG.error( message );
-            throw new IllegalArgumentException( message );
-        }
-
-        if ( attributeType.getSyntax() == null )
-        {
-            throw new IllegalArgumentException( I18n.err( I18n.ERR_04445 ) );
-        }
-
-        if ( ! attributeType.getSyntax().isHumanReadable() )
+        if ( attributeType != null )
         {
-            LOG.warn( "Treating a value of a binary attribute {} as a String: "
-                + "\nthis could cause data corruption!", attributeType.getName() );
+            if ( attributeType.getSyntax() == null )
+            {
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04445 ) );
+            }
+    
+            if ( ! attributeType.getSyntax().isHumanReadable() )
+            {
+                LOG.warn( "Treating a value of a binary attribute {} as a String: "
+                    + "\nthis could cause data corruption!", attributeType.getName() );
+            }
+    
+            this.attributeType = attributeType;
         }
-
-        this.attributeType = attributeType;
     }
 
 
@@ -373,6 +362,19 @@ public class StringValue extends Abstrac
             return other.isNull();
         }
        
+        // First check the upValue. If they are equal, the Values are equal
+        if ( wrappedValue == other.wrappedValue )
+        {
+            return true;
+        }
+        else if ( wrappedValue != null )
+        {
+            if ( wrappedValue.equals( other.wrappedValue ) )
+            {
+                return true;
+            }
+        }
+
         // If we have an attributeType, it must be equal
         // We should also use the comparator if we have an AT
         if ( attributeType != null )
@@ -485,22 +487,38 @@ public class StringValue extends Abstrac
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
+        // Read the STRING flag
+        boolean isHR = in.readBoolean();
+        
+        if ( ! isHR )
+        {
+            throw new IOException( "The serialized value is not a String value" );
+        }
+        
         // Read the wrapped value, if it's not null
         if ( in.readBoolean() )
         {
-            wrappedValue = Unicode.readUTF(in);
+            wrappedValue = in.readUTF();
         }
         
         // Read the isNormalized flag
         normalized = in.readBoolean();
         
-        if ( ( normalized ) && ( in.readBoolean() ) )
+        if ( normalized ) 
         {
             // Read the normalized value, if not null
-            normalizedValue = Unicode.readUTF(in);
+            if ( in.readBoolean() )
+            {
+                normalizedValue = in.readUTF();
+            }
+        }
+        else
+        {
+            normalizedValue = wrappedValue;
         }
         
-        h = 0;
+        // The hashCoe
+        h = in.readInt();
     }
 
     
@@ -509,11 +527,14 @@ public class StringValue extends Abstrac
      */
     public void writeExternal( ObjectOutput out ) throws IOException
     {
+        // Write a boolean for the HR flag
+        out.writeBoolean( STRING );
+        
         // Write the wrapped value, if it's not null
         if ( wrappedValue != null )
         {
             out.writeBoolean( true );
-            Unicode.writeUTF(out, wrappedValue);
+            out.writeUTF( wrappedValue );
         }
         else
         {
@@ -523,13 +544,15 @@ public class StringValue extends Abstrac
         // Write the isNormalized flag
         if ( normalized )
         {
+            // This flag is present to tell that we have a normalized value different 
+            // from the upValue
             out.writeBoolean( true );
             
             // Write the normalized value, if not null
             if ( normalizedValue != null )
             {
                 out.writeBoolean( true );
-                Unicode.writeUTF(out, normalizedValue);
+                out.writeUTF( normalizedValue );
             }
             else
             {
@@ -538,24 +561,19 @@ public class StringValue extends Abstrac
         }
         else
         {
+            // No normalized value
             out.writeBoolean( false );
         }
         
+        // Write the hashCode
+        out.writeInt( h );
+        
         // and flush the data
         out.flush();
     }
 
     
     /**
-     * {@inheritDoc}
-     */
-    public static StringValue deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
-    {
-        return (StringValue)AbstractValue.deserialize( schemaManager, in );
-    }
-
-    
-    /**
      * @see Object#toString()
      */
     public String toString()

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java Tue Mar  8 17:56:54 2011
@@ -36,6 +36,10 @@ import org.apache.directory.shared.ldap.
  */
 public interface Value<T> extends Cloneable, Externalizable, Comparable<Value<T>>
 {
+    /** Two flags used to tll if the value is HR or not in serialization */
+    public static final boolean STRING = true;
+    public static final boolean BINARY = false;
+
     /**
      * Apply an AttributeType to the current Value, normalizing it.
      *

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java Tue Mar  8 17:56:54 2011
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.EntrySerializer;
 import org.apache.directory.shared.ldap.model.entry.Modification;
@@ -210,7 +211,16 @@ public class LdifEntrySerializer
 
                 for ( int i = 0; i < nbModifs; i++ )
                 {
-                    Modification modification = ModificationSerializer.deserialize( schemaManager, in );
+                    Modification modification = new DefaultModification();
+                    
+                    try
+                    {
+                        modification.readExternal( in );
+                    }
+                    catch ( ClassNotFoundException cnfe )
+                    {
+                        throw new IOException( cnfe.getMessage() );
+                    }
 
                     ldifEntry.addModificationItem( modification );
                 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java Tue Mar  8 17:56:54 2011
@@ -815,16 +815,10 @@ public final class Ava implements Extern
         
         out.writeBoolean( isHR );
         
-        if ( isHR )
-        {
-            StringValue.serialize( upValue, out );
-            StringValue.serialize( normValue, out );
-        }
-        else
-        {
-            BinaryValue.serialize( upValue, out );
-            BinaryValue.serialize( normValue, out );
-        }
+        upValue.writeExternal( out );
+        normValue.writeExternal( out );
+        
+        out.flush();
     }
     
     
@@ -858,19 +852,34 @@ public final class Ava implements Extern
             normType = in.readUTF();
         }
         
-        boolean isHR = in.readBoolean();
+        if ( schemaManager != null )
+        {
+            if ( !Strings.isEmpty( upType ) )
+            {
+                attributeType = schemaManager.getAttributeType( upType );
+            }
+            else
+            {
+                attributeType = schemaManager.getAttributeType( normType );
+            }
+        }
         
+        boolean isHR = in.readBoolean();
+
         if ( isHR )
         {
-            upValue = StringValue.deserialize( schemaManager, in );
-            normValue = StringValue.deserialize( schemaManager, in );
+            upValue = new StringValue( attributeType );
+            normValue = new StringValue( attributeType );
         }
         else
         {
-            upValue = BinaryValue.deserialize( schemaManager, in );
-            normValue = BinaryValue.deserialize( schemaManager, in );
+            upValue = new BinaryValue( attributeType );
+            normValue = new BinaryValue( attributeType );
         }
-        
+
+        upValue.readExternal( in );
+        normValue.readExternal( in );
+
         if ( schemaManager != null )
         {
             attributeType = schemaManager.getAttributeType( upType );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java Tue Mar  8 17:56:54 2011
@@ -37,6 +37,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.util.Chars;
@@ -679,7 +680,17 @@ public final class Rdn implements Clonea
     public Object getValue( String type ) throws LdapInvalidDnException
     {
         // First, let's normalize the type
-        String normalizedType = Strings.lowerCaseAscii(Strings.trim(type));
+        String normalizedType = Strings.lowerCaseAscii( Strings.trim( type ) );
+        
+        if ( schemaManager != null )
+        {
+             AttributeType attributeType = schemaManager.getAttributeType( normalizedType );
+             
+             if ( attributeType != null )
+             {
+                normalizedType = attributeType.getOid();
+             }
+        }
 
         switch ( nbAtavs )
         {
@@ -687,7 +698,7 @@ public final class Rdn implements Clonea
                 return "";
 
             case 1:
-                if ( Strings.equals(atav.getNormType(), normalizedType) )
+                if ( Strings.equals( atav.getNormType(), normalizedType ) )
                 {
                     return atav.getNormValue().get();
                 }
@@ -1513,6 +1524,8 @@ public final class Rdn implements Clonea
 
                 break;
         }
+        
+        out.flush();
     }
 
 

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java Tue Mar  8 17:56:54 2011
@@ -134,7 +134,7 @@ public class BinaryValueAttributeTypeTes
         try
         {
             oOut = new ObjectOutputStream( out );
-            BinaryValue.serialize( value, oOut );
+            value.writeExternal( oOut );
         }
         catch ( IOException ioe )
         {
@@ -172,7 +172,8 @@ public class BinaryValueAttributeTypeTes
         {
             oIn = new ObjectInputStream( in );
 
-            BinaryValue value = BinaryValue.deserialize( null, oIn );
+            BinaryValue value = new BinaryValue( (AttributeType)null );
+            value.readExternal( oIn );
 
             return value;
         }
@@ -202,17 +203,7 @@ public class BinaryValueAttributeTypeTes
      */
     @Test public void testBadConstructor()
     {
-        try
-        {
-            new BinaryValue( null, null );
-            fail();
-        }
-        catch ( IllegalArgumentException iae )
-        {
-            // Expected...
-        }
-        
-        // create a AT without any syntax
+        // create a AT without no syntax
         AttributeType attribute = new AttributeType( "1.1.3.1" );
         
         try

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueTest.java Tue Mar  8 17:56:54 2011
@@ -136,7 +136,7 @@ public class BinaryValueTest
         try
         {
             oOut = new ObjectOutputStream( out );
-            oOut.writeObject( value );
+            value.writeExternal( oOut );
         }
         catch ( IOException ioe )
         {
@@ -174,8 +174,9 @@ public class BinaryValueTest
         {
             oIn = new ObjectInputStream( in );
 
-            BinaryValue value = ( BinaryValue ) oIn.readObject();
-
+            BinaryValue value = new BinaryValue();
+            value.readExternal( oIn );
+            
             return value;
         }
         catch ( IOException ioe )
@@ -716,11 +717,11 @@ public class BinaryValueTest
         bv.isValid( BINARY_CHECKER );
 
         BinaryValue cbvSer = deserializeValue( serializeValue( bv ) );
-         assertNotSame( bv, cbvSer );
-         assertTrue( Arrays.equals( bv.getReference(), cbvSer.getReference() ) );
-         assertTrue( Arrays.equals( bv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference() ) );
-         assertTrue( cbvSer.isNormalized() );
-         assertFalse( cbvSer.isValid() );
+        assertNotSame( bv, cbvSer );
+        assertTrue( Arrays.equals( bv.getReference(), cbvSer.getReference() ) );
+        assertTrue( Arrays.equals( bv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference() ) );
+        assertTrue( cbvSer.isNormalized() );
+        assertFalse( cbvSer.isValid() );
     }
     
     

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ModificationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ModificationTest.java?rev=1079453&r1=1079452&r2=1079453&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ModificationTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ModificationTest.java Tue Mar  8 17:56:54 2011
@@ -19,26 +19,21 @@
  */
 package org.apache.directory.shared.ldap.model.entry;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-import org.apache.directory.shared.ldap.model.entry.DefaultModification;
-import org.apache.directory.shared.ldap.model.entry.DefaultEntryAttribute;
-import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.model.entry.Modification;
-import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the DefaultModification class
@@ -52,7 +47,7 @@ public class ModificationTest
     /**
      * Serialize a DefaultModification
      */
-    private ByteArrayOutputStream serializeValue( DefaultModification value ) throws IOException
+    private ByteArrayOutputStream serializeValue( Modification modification ) throws IOException
     {
         ObjectOutputStream oOut = null;
         ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -60,7 +55,7 @@ public class ModificationTest
         try
         {
             oOut = new ObjectOutputStream( out );
-            oOut.writeObject( value );
+            modification.writeExternal( oOut );
         }
         catch ( IOException ioe )
         {
@@ -89,18 +84,20 @@ public class ModificationTest
     /**
      * Deserialize a DefaultModification
      */
-    private DefaultModification deserializeValue( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
+    private Modification deserializeValue( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
     {
         ObjectInputStream oIn = null;
         ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
 
         try
         {
+            Modification modification = new DefaultModification();
+            
             oIn = new ObjectInputStream( in );
 
-            DefaultModification value = ( DefaultModification ) oIn.readObject();
+            modification.readExternal( oIn );
 
-            return value;
+            return modification;
         }
         catch ( IOException ioe )
         {



Mime
View raw message