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/16 00:12:13 UTC

svn commit: r1081991 - in /directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif: LdifControl.java LdifEntry.java

Author: elecharny
Date: Tue Mar 15 23:12:13 2011
New Revision: 1081991

URL: http://svn.apache.org/viewvc?rev=1081991&view=rev
Log:
o Made the LdifControl class externalizable
o Used the readExternal/writeExternal methods in LdifEntry

Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControl.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControl.java?rev=1081991&r1=1081990&r2=1081991&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControl.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControl.java Tue Mar 15 23:12:13 2011
@@ -20,6 +20,11 @@
 package org.apache.directory.shared.ldap.model.ldif;
 
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
 import org.apache.directory.shared.ldap.model.message.Control;
 import org.apache.directory.shared.util.Strings;
 
@@ -30,7 +35,7 @@ import org.apache.directory.shared.util.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdifControl implements Control
+public class LdifControl implements Control, Externalizable
 {
     /** The control type */
     private String oid;
@@ -44,6 +49,14 @@ public class LdifControl implements Cont
 
     /**
      * Create a new Control
+     */
+    public LdifControl()
+    {
+    }
+
+
+    /**
+     * Create a new Control
      * 
      * @param oid OID of the created control
      */
@@ -117,6 +130,52 @@ public class LdifControl implements Cont
 
 
     /**
+     * {@inheritDoc}
+     */
+    public void writeExternal( ObjectOutput out ) throws IOException
+    {
+        out.writeUTF( oid );
+        out.writeBoolean( criticality );
+
+        if ( hasValue() )
+        {
+            out.writeBoolean( true );
+            out.writeInt( value.length );
+
+            if ( value.length > 0 )
+            {
+                out.write( value );
+            }
+        }
+        else
+        {
+            out.writeBoolean( false );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+    {
+        oid = in.readUTF();
+        criticality = in.readBoolean();
+        
+        if ( in.readBoolean() )
+        {
+            int valueLength = in.readInt();
+
+            if ( valueLength > 0 )
+            {
+                value = new byte[valueLength];
+                in.read( value );
+            }
+        }
+    }
+
+    
+    /**
      * @see Object#hashCode()
      */
     public int hashCode()

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=1081991&r1=1081990&r2=1081991&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 Tue Mar 15 23:12:13 2011
@@ -989,10 +989,13 @@ public class LdifEntry implements Clonea
         // Read the changeType
         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:
@@ -1048,26 +1051,11 @@ public class LdifEntry implements Clonea
 
                 for ( int i = 0; i < nbControls; i++ )
                 {
-                    String controlOid = in.readUTF();
-                    boolean isCritical = in.readBoolean();
-                    boolean hasValue = in.readBoolean();
-                    LdifControl control = new LdifControl( controlOid );
-                    control.setCritical( isCritical );
-
-                    if ( hasValue )
-                    {
-                        int valueLength = in.readInt();
-                        byte[] value = new byte[valueLength];
-
-                        if ( valueLength > 0 )
-                        {
-                            in.read( value );
-                        }
-
-                        control.setValue( value );
-                    }
+                    LdifControl control = new LdifControl();
+                    
+                    control.readExternal( in );
 
-                    controls.put( controlOid, control );
+                    controls.put( control.getOid(), control );
                 }
             }
         }
@@ -1085,7 +1073,7 @@ public class LdifEntry implements Clonea
         out.writeInt( changeType.getChangeType() );
 
         // Write the entry
-        out.writeObject( entry );
+        entry.writeExternal( out );
 
         // Write the data
         switch ( changeType )
@@ -1104,7 +1092,7 @@ public class LdifEntry implements Clonea
                 if ( newRdn != null )
                 {
                     out.writeBoolean( true );
-                    Unicode.writeUTF(out, newRdn);
+                    Unicode.writeUTF( out, newRdn );
                 }
                 else
                 {
@@ -1114,7 +1102,7 @@ public class LdifEntry implements Clonea
                 if ( newSuperior != null )
                 {
                     out.writeBoolean( true );
-                    Unicode.writeUTF(out, newSuperior);
+                    Unicode.writeUTF( out, newSuperior );
                 }
                 else
                 {
@@ -1129,7 +1117,7 @@ public class LdifEntry implements Clonea
                 for ( Modification modification : modificationList )
                 {
                     out.writeInt( modification.getOperation().getValue() );
-                    Unicode.writeUTF(out, modification.getAttribute().getId());
+                    Unicode.writeUTF( out, modification.getAttribute().getId() );
 
                     EntryAttribute attribute = modification.getAttribute();
                     out.writeObject( attribute );
@@ -1150,19 +1138,7 @@ public class LdifEntry implements Clonea
 
             for ( LdifControl control : controls.values() )
             {
-                Unicode.writeUTF(out, control.getOid());
-                out.writeBoolean( control.isCritical() );
-                out.writeBoolean( control.hasValue() );
-
-                if ( control.hasValue() )
-                {
-                    out.writeInt( control.getValue().length );
-
-                    if ( control.getValue().length > 0 )
-                    {
-                        out.write( control.getValue() );
-                    }
-                }
+                control.writeExternal( out );
             }
         }