Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 87108 invoked from network); 27 Apr 2010 16:06:10 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 Apr 2010 16:06:10 -0000 Received: (qmail 55384 invoked by uid 500); 27 Apr 2010 16:06:10 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 55347 invoked by uid 500); 27 Apr 2010 16:06:10 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 55340 invoked by uid 99); 27 Apr 2010 16:06:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Apr 2010 16:06:10 +0000 X-ASF-Spam-Status: No, hits=-1333.9 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Apr 2010 16:06:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2E4B723889FD; Tue, 27 Apr 2010 16:05:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r938536 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry: DefaultServerEntry.java client/DefaultClientEntry.java Date: Tue, 27 Apr 2010 16:05:27 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100427160527.2E4B723889FD@eris.apache.org> 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 : - * [a byte] : if the DN is empty 0 will be written else 1 - * [RDN] : The entry's RDN. - * [numberAttr] : the bumber of attributes. Can be 0 - * [attribute's oid]* : The attribute's OID to get back - * the attributeType on deserialization - * [Attribute]* 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 : + * [a byte] : if the DN is empty 0 will be written else 1 + * [RDN] : The entry's RDN. + * [numberAttr] : the bumber of attributes. Can be 0 + * [attribute's oid]* : The attribute's OID to get back + * the attributeType on deserialization + * [Attribute]* 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;