You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/03/17 11:56:20 UTC

svn commit: r1082445 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ shared/trunk/ldap/model/src/main/java/org/apache...

Author: elecharny
Date: Thu Mar 17 10:56:19 2011
New Revision: 1082445

URL: http://svn.apache.org/viewvc?rev=1082445&view=rev
Log:
o Using the readExternal/writeExternal methods instead of the Serializers for entries
o Refactored the LdifEntry serialization

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.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/ldif/LdifEntry.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java?rev=1082445&r1=1082444&r2=1082445&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java Thu Mar 17 10:56:19 2011
@@ -81,6 +81,8 @@ public final class ChangeLogEventSeriali
         {
             LdifEntrySerializer.serialize( reverseLdif, out );
         }
+        
+        out.flush();
     }
     
     

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=1082445&r1=1082444&r2=1082445&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 Thu Mar 17 10:56:19 2011
@@ -34,9 +34,7 @@ import java.util.Set;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 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.name.Dn;
-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.Strings;
@@ -2561,12 +2559,12 @@ public final class DefaultEntry implemen
         if ( dn == null )
         {
             // Write an empty Dn
-            DnSerializer.serialize( Dn.EMPTY_DN, out );
+            Dn.EMPTY_DN.writeExternal( out );
         }
         else
         {
             // Write the Dn
-            DnSerializer.serialize( dn, out );
+            dn.writeExternal( out );
         }
 
         // Then the attributes.
@@ -2577,7 +2575,7 @@ public final class DefaultEntry implemen
         for ( EntryAttribute attribute : attributes.values() )
         {
             // Store the attribute
-            out.writeObject( attribute );
+            attribute.writeExternal( out );
         }
 
         out.flush();
@@ -2590,14 +2588,8 @@ public final class DefaultEntry implemen
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         // Read the Dn
-        try
-        {
-            dn = DnSerializer.deserialize( schemaManager, in );
-        }
-        catch( LdapInvalidDnException lide )
-        {
-            throw new IOException( lide.getMessage() );
-        }
+        dn = new Dn( schemaManager );
+        dn.readExternal( in );
             
 
         // Read the number of attributes
@@ -2607,13 +2599,15 @@ public final class DefaultEntry implemen
         for ( int i = 0; i < nbAttributes; i++ )
         {
             // Read each attribute
-            EntryAttribute attribute = ( DefaultEntryAttribute ) in.readObject();
+            EntryAttribute attribute = new DefaultEntryAttribute();
+            attribute.readExternal( in );
 
             if ( schemaManager != null )
             {
                 try
                 {
                     AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
+                    attribute.setAttributeType( attributeType );
 
                     attributes.put( attributeType.getOid(), attribute );
                 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java?rev=1082445&r1=1082444&r2=1082445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java Thu Mar 17 10:56:19 2011
@@ -49,7 +49,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.util.Base64;
 import org.apache.directory.shared.util.Strings;
-import org.apache.directory.shared.util.Unicode;
 
 
 /**
@@ -1141,73 +1140,78 @@ public class LdifEntry implements Clonea
         int type = in.readInt();
         changeType = ChangeType.getChangeType( type );
         
-        // Read the entry
-        Entry entry = new DefaultEntry();
-        
-        entry.readExternal( in );
-
         // Read the modification
         switch ( changeType )
         {
             case Add:
+            case None:
+                // Read the entry
+                entry.readExternal( in );
+                entryDn = entry.getDn();
+                
+                break;
+                
             case Delete:
-                // we don't have anything to read, but the control
+                // Read the Dn
+                entryDn = new Dn();
+                entryDn.readExternal( in );
+                
                 break;
 
             case ModDn:
                 // Fallback
             case ModRdn:
+                // Read the Dn
+                entryDn = new Dn();
+                entryDn.readExternal( in );
+                
                 deleteOldRdn = in.readBoolean();
-
+                
                 if ( in.readBoolean() )
                 {
-                    newRdn = Unicode.readUTF(in);
+                    newRdn = in.readUTF();
                 }
 
                 if ( in.readBoolean() )
                 {
-                    newSuperior = Unicode.readUTF(in);
+                    newSuperior = in.readUTF();
                 }
 
                 break;
 
             case Modify:
-                // Read the modification
+                // Read the Dn
+                entryDn = new Dn();
+                entryDn.readExternal( in );
+
+                // Read the modifications
                 int nbModifs = in.readInt();
 
                 for ( int i = 0; i < nbModifs; i++ )
                 {
-                    int operation = in.readInt();
-                    String modStr = Unicode.readUTF(in);
-                    DefaultEntryAttribute value = ( DefaultEntryAttribute ) in.readObject();
-
-                    addModificationItem( ModificationOperation.getOperation( operation ), modStr, value );
+                    Modification modification = new DefaultModification();
+                    modification.readExternal( in );
+                    
+                    addModificationItem( modification );
                 }
 
                 break;
-
-            case None:
-                // Nothing to do 
-                break;
         }
 
-        if ( in.available() > 0 )
+        int nbControls = in.readInt();
+
+        // We have at least a control
+        if ( nbControls > 0 )
         {
-            // We have at least a control
-            int nbControls = in.readInt();
+            controls = new ConcurrentHashMap<String, LdifControl>( nbControls );
 
-            if ( nbControls > 0 )
+            for ( int i = 0; i < nbControls; i++ )
             {
-                controls = new ConcurrentHashMap<String, LdifControl>( nbControls );
-
-                for ( int i = 0; i < nbControls; i++ )
-                {
-                    LdifControl control = new LdifControl();
-                    
-                    control.readExternal( in );
+                LdifControl control = new LdifControl();
+                
+                control.readExternal( in );
 
-                    controls.put( control.getOid(), control );
-                }
+                controls.put( control.getOid(), control );
             }
         }
     }
@@ -1223,37 +1227,42 @@ public class LdifEntry implements Clonea
         // Write the changeType
         out.writeInt( changeType.getChangeType() );
 
-        // Write the entry
-        entry.writeExternal( out );
-
         // Write the data
         switch ( changeType )
         {
             case Add:
+            case None :
+                entry.writeExternal( out );
+                break;
+                
                 // Fallback
             case Delete:
-                // we don't have anything to write, but the control
+                // we write the Dn
+                entryDn.writeExternal( out );
                 break;
 
             case ModDn:
                 // Fallback
             case ModRdn:
+                // Write the Dn
+                entryDn.writeExternal( out );
+                
                 out.writeBoolean( deleteOldRdn );
-
-                if ( newRdn != null )
+                
+                if ( newRdn == null )
                 {
-                    out.writeBoolean( true );
-                    Unicode.writeUTF( out, newRdn );
+                    out.writeBoolean( false );
                 }
                 else
                 {
-                    out.writeBoolean( false );
+                    out.writeBoolean( true );
+                    out.writeUTF( newRdn );
                 }
 
                 if ( newSuperior != null )
                 {
                     out.writeBoolean( true );
-                    Unicode.writeUTF( out, newSuperior );
+                    out.writeUTF( newSuperior );
                 }
                 else
                 {
@@ -1262,23 +1271,18 @@ public class LdifEntry implements Clonea
                 break;
 
             case Modify:
-                // Read the modification
+                // Write the Dn
+                entryDn.writeExternal( out );
+                
+                // Write the modifications
                 out.writeInt( modificationList.size() );
 
                 for ( Modification modification : modificationList )
                 {
-                    out.writeInt( modification.getOperation().getValue() );
-                    Unicode.writeUTF( out, modification.getAttribute().getId() );
-
-                    EntryAttribute attribute = modification.getAttribute();
-                    out.writeObject( attribute );
+                    modification.writeExternal( out );
                 }
 
                 break;
-
-            case None:
-                // Nothing to do
-                break;
         }
 
         // The controls
@@ -1292,6 +1296,11 @@ public class LdifEntry implements Clonea
                 control.writeExternal( out );
             }
         }
+        else
+        {
+            // No control, write -1
+            out.writeInt( -1 );
+        }
 
         // and flush the result
         out.flush();

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=1082445&r1=1082444&r2=1082445&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 Thu Mar 17 10:56:19 2011
@@ -23,16 +23,8 @@ 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;
-import org.apache.directory.shared.ldap.model.entry.ModificationSerializer;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
-import org.apache.directory.shared.ldap.model.name.Dn;
-import org.apache.directory.shared.ldap.model.name.DnSerializer;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
-import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -64,78 +56,7 @@ public class LdifEntrySerializer
     public static void serialize( LdifEntry ldifEntry, ObjectOutput out ) throws IOException
     {
         // The changeType
-        out.writeInt( ldifEntry.getChangeType().getChangeType() );
-
-        switch ( ldifEntry.getChangeType() )
-        {
-            case Add :
-                // We write the entry
-                EntrySerializer.serialize( ldifEntry.getEntry(), out );
-                
-                break;
-                
-            case Delete :
-                // We just have to store the deleted DN
-                DnSerializer.serialize( ldifEntry.getDn(), out );
-                
-                break;
-                
-            case ModDn :
-            case ModRdn :
-                DnSerializer.serialize( ldifEntry.getDn(), out );
-                out.writeBoolean( ldifEntry.isDeleteOldRdn() );
-
-                if ( ldifEntry.getNewRdn() != null )
-                {
-                    out.writeBoolean( true );
-                    Unicode.writeUTF( out, ldifEntry.getNewRdn() );
-                }
-                else
-                {
-                    out.writeBoolean( false );
-                }
-
-                if ( ldifEntry.getNewSuperior() != null )
-                {
-                    out.writeBoolean( true );
-                    Unicode.writeUTF( out, ldifEntry.getNewSuperior() );
-                }
-                else
-                {
-                    out.writeBoolean( false );
-                }
-
-                break;
-                
-            case Modify :
-                DnSerializer.serialize( ldifEntry.getDn(), out );
-                // Read the modification
-                out.writeInt( ldifEntry.getModificationItems().size() );
-
-                for ( Modification modification : ldifEntry.getModificationItems() )
-                {
-                    ModificationSerializer.serialize( modification, out );
-                }
-                
-                break;
-        }
-
-        
-        // The controls
-        if ( ldifEntry.hasControls() )
-        {
-            // Write the controls
-            out.writeInt( ldifEntry.getControls().size() );
-
-            for ( LdifControl ldifControl : ldifEntry.getControls().values() )
-            {
-                LdifControlSerializer.serialize( ldifControl, out );
-            }
-        }
-        else
-        {
-            out.writeInt( 0 );
-        }
+        ldifEntry.writeExternal( out );
         
         out.flush();
     }
@@ -152,93 +73,15 @@ public class LdifEntrySerializer
     public static LdifEntry deserialize( SchemaManager schemaManager, ObjectInput in )
         throws IOException, LdapInvalidDnException
     {
-        // The ChangeType 
-        ChangeType changeType = ChangeType.getChangeType( in.readInt() );
-        
-        LdifEntry ldifEntry = null;
+        LdifEntry ldifEntry = new LdifEntry();
         
-        switch ( changeType )
+        try
         {
-            case Add :
-                Entry entry = EntrySerializer.deserialize( schemaManager, in );
-                ldifEntry = new LdifEntry( entry );
-                ldifEntry.setChangeType( changeType );
-                
-                break;
-                
-            case Delete :
-                Dn dn = DnSerializer.deserialize( schemaManager, in );
-                ldifEntry = new LdifEntry();
-                ldifEntry.setChangeType( changeType );
-                ldifEntry.setDn( dn );
-                
-                break;
-                
-            case ModDn :
-            case ModRdn :
-                ldifEntry = new LdifEntry();
-
-                dn = DnSerializer.deserialize( schemaManager, in );
-                ldifEntry.setDn( dn );
-                boolean deleteOldRdn = in.readBoolean();
-                ldifEntry.setChangeType( changeType );
-                ldifEntry.setDeleteOldRdn( deleteOldRdn );
-
-                // The newRDN
-                if ( in.readBoolean() )
-                {
-                    String newRdn = Unicode.readUTF(in);
-                    ldifEntry.setNewRdn( newRdn );
-                }
-
-                // The newSuperior
-                if ( in.readBoolean() )
-                {
-                    String newSuperior = Unicode.readUTF(in);
-                    ldifEntry.setNewSuperior( newSuperior );
-                }
-                
-                break;
-                
-            case Modify :
-                ldifEntry = new LdifEntry();
-                dn = DnSerializer.deserialize( schemaManager, in );
-                ldifEntry.setDn( dn );
-
-                // Read the modification
-                int nbModifs = in.readInt();
-                ldifEntry.setChangeType( changeType );
-
-                for ( int i = 0; i < nbModifs; i++ )
-                {
-                    Modification modification = new DefaultModification();
-                    
-                    try
-                    {
-                        modification.readExternal( in );
-                    }
-                    catch ( ClassNotFoundException cnfe )
-                    {
-                        throw new IOException( cnfe.getMessage() );
-                    }
-
-                    ldifEntry.addModificationItem( modification );
-                }
-                
-                break;
+            ldifEntry.readExternal( in );
         }
-        
-        // The controls
-        int nbControls = in.readInt();
-        
-        if ( nbControls > 0 )
+        catch ( ClassNotFoundException cnfe )
         {
-            for ( int i = 0; i < nbControls; i++ )
-            {
-                LdifControl ldifControl = LdifControlSerializer.deserialize( in );
-                
-                ldifEntry.addControl( ldifControl );
-            }
+            throw new IOException( cnfe.getMessage() );
         }
 
         return ldifEntry;