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 2010/04/27 18:05:27 UTC
svn commit: r938536 - in
/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry:
DefaultServerEntry.java client/DefaultClientEntry.java
Author: elecharny
Date: Tue Apr 27 16:05:26 2010
New Revision: 938536
URL: http://svn.apache.org/viewvc?rev=938536&view=rev
Log:
Moved the serialization/deserialization methods fro server to client Entry
Modified:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java?rev=938536&r1=938535&r2=938536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultServerEntry.java Tue Apr 27 16:05:26 2010
@@ -19,9 +19,6 @@
package org.apache.directory.shared.ldap.entry;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.HashMap;
import java.util.Map;
@@ -30,8 +27,6 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.exception.LdapException;
import org.apache.directory.shared.ldap.name.DN;
-import org.apache.directory.shared.ldap.name.RDN;
-import org.apache.directory.shared.ldap.name.RdnSerializer;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
@@ -434,107 +429,4 @@ public final class DefaultServerEntry ex
// We are done !
return clone;
}
-
-
- /**
- * Serialize a server entry.
- *
- * The structure is the following :
- * <b>[a byte] : if the DN is empty 0 will be written else 1
- * <b>[RDN]</b> : The entry's RDN.
- * <b>[numberAttr]</b> : the bumber of attributes. Can be 0
- * <b>[attribute's oid]*</b> : The attribute's OID to get back
- * the attributeType on deserialization
- * <b>[Attribute]*</b> The attribute
- *
- * @param out the buffer in which the data will be serialized
- * @throws IOException if the serialization failed
- */
- public void serialize( ObjectOutput out ) throws IOException
- {
- // First, the DN
- // Write the RDN of the DN
-
- if( dn.getRdn() == null )
- {
- out.writeByte( 0 );
- }
- else
- {
- out.writeByte( 1 );
- RdnSerializer.serialize( dn.getRdn(), out );
- }
-
- // Then the attributes.
- out.writeInt( attributes.size() );
-
- // Iterate through the keys. We store the Attribute
- // here, to be able to restore it in the readExternal :
- // we need access to the registries, which are not available
- // in the ServerAttribute class.
- for ( AttributeType attributeType:getAttributeTypes() )
- {
- // Write the oid to be able to restore the AttributeType when deserializing
- // the attribute
- String oid = attributeType.getOid();
-
- out.writeUTF( oid );
-
- // Get the attribute
- DefaultEntryAttribute attribute = (DefaultEntryAttribute)attributes.get( attributeType.getOid() );
-
- // Write the attribute
- attribute.serialize( out );
- }
- }
-
-
- /**
- * Deserialize a server entry.
- *
- * @param in The buffer containing the serialized serverEntry
- * @throws IOException if there was a problem when deserializing
- * @throws ClassNotFoundException if we can't deserialize an expected object
- */
- public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
- {
- // Read the DN
- dn = new DN();
-
- byte b = in.readByte();
- if( b == 1 )
- {
- RDN rdn = RdnSerializer.deserialize( in );
- dn.add( rdn );
- }
-
- // Read the number of attributes
- int nbAttributes = in.readInt();
-
- // Read the attributes
- for ( int i = 0; i < nbAttributes; i++ )
- {
- // Read the attribute's OID
- String oid = in.readUTF();
-
- try
- {
- AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
-
- // Create the attribute we will read
- EntryAttribute attribute = new DefaultEntryAttribute( attributeType );
-
- // Read the attribute
- attribute.deserialize( in );
-
- attributes.put( attributeType.getOid(), attribute );
- }
- catch ( LdapException ne )
- {
- // We weren't able to find the OID. The attribute will not be added
- LOG.warn( I18n.err( I18n.ERR_04470, oid ) );
-
- }
- }
- }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java?rev=938536&r1=938535&r2=938536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java Tue Apr 27 16:05:26 2010
@@ -40,6 +40,8 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
+import org.apache.directory.shared.ldap.name.RdnSerializer;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -2268,6 +2270,153 @@ public class DefaultClientEntry implemen
}
+
+
+ /**
+ * Serialize an Entry.
+ *
+ * The structure is the following :
+ * <b>[a byte] : if the DN is empty 0 will be written else 1
+ * <b>[RDN]</b> : The entry's RDN.
+ * <b>[numberAttr]</b> : the bumber of attributes. Can be 0
+ * <b>[attribute's oid]*</b> : The attribute's OID to get back
+ * the attributeType on deserialization
+ * <b>[Attribute]*</b> The attribute
+ *
+ * @param out the buffer in which the data will be serialized
+ * @throws IOException if the serialization failed
+ */
+ public void serialize( ObjectOutput out ) throws IOException
+ {
+ // First, the DN
+ // Write the RDN of the DN
+ if( dn.getRdn() == null )
+ {
+ out.writeByte( 0 );
+ }
+ else
+ {
+ out.writeByte( 1 );
+ RdnSerializer.serialize( dn.getRdn(), out );
+ }
+
+ // Then the attributes.
+ out.writeInt( attributes.size() );
+
+ if ( schemaManager != null )
+ {
+ // Iterate through the keys. We store the Attribute
+ // here, to be able to restore it in the readExternal :
+ // we need access to the registries, which are not available
+ // in the ServerAttribute class.
+ for ( AttributeType attributeType:getAttributeTypes() )
+ {
+ // Write the oid to be able to restore the AttributeType when deserializing
+ // the attribute
+ String oid = attributeType.getOid();
+
+ out.writeUTF( oid );
+
+ // Get the attribute
+ DefaultEntryAttribute attribute = (DefaultEntryAttribute)attributes.get( attributeType.getOid() );
+
+ // Write the attribute
+ attribute.serialize( out );
+ }
+ }
+ else
+ {
+ // Loop on the Attribute ID
+ for ( String id:attributes.keySet() )
+ {
+ // Write the id to be able to restore the AttributeType when deserializing
+ // the attribute
+ out.writeUTF( id );
+
+ // Get the attribute
+ DefaultEntryAttribute attribute = (DefaultEntryAttribute)attributes.get( id );
+
+ // Write the attribute
+ attribute.serialize( out );
+ }
+ }
+ }
+
+
+ /**
+ * Deserialize an entry.
+ *
+ * @param in The buffer containing the serialized serverEntry
+ * @throws IOException if there was a problem when deserializing
+ * @throws ClassNotFoundException if we can't deserialize an expected object
+ */
+ public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
+ {
+ // Read the DN
+ dn = new DN();
+
+ byte b = in.readByte();
+
+ if( b == 1 )
+ {
+ RDN rdn = RdnSerializer.deserialize( in );
+ dn.add( rdn );
+ }
+
+ // Read the number of attributes
+ int nbAttributes = in.readInt();
+
+ if ( schemaManager != null )
+ {
+ // Read the attributes
+ for ( int i = 0; i < nbAttributes; i++ )
+ {
+ // Read the attribute's OID
+ String oid = in.readUTF();
+
+ try
+ {
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
+
+ // Create the attribute we will read
+ EntryAttribute attribute = new DefaultEntryAttribute( attributeType );
+
+ // Read the attribute
+ attribute.deserialize( in );
+
+ attributes.put( attributeType.getOid(), attribute );
+ }
+ catch ( LdapException ne )
+ {
+ // We weren't able to find the OID. The attribute will not be added
+ LOG.warn( I18n.err( I18n.ERR_04470, oid ) );
+
+ }
+ }
+ }
+ else
+ {
+ // Read the attributes
+ for ( int i = 0; i < nbAttributes; i++ )
+ {
+ // Read the attribute's ID
+ String id = in.readUTF();
+
+ // Create the attribute we will read
+ EntryAttribute attribute = new DefaultEntryAttribute( id );
+
+ // Read the attribute
+ attribute.deserialize( in );
+
+ attributes.put( id, attribute );
+ }
+ }
+ }
+
+
+ /**
+ * A helper method to recompute the hash code
+ */
private void rehash()
{
h = 37;