Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 34445 invoked from network); 4 Mar 2011 18:39:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Mar 2011 18:39:59 -0000 Received: (qmail 19830 invoked by uid 500); 4 Mar 2011 18:39:59 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 19780 invoked by uid 500); 4 Mar 2011 18:39:59 -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 19767 invoked by uid 99); 4 Mar 2011 18:39:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 18:39:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED 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; Fri, 04 Mar 2011 18:39:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 577D523888CE; Fri, 4 Mar 2011 18:39:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1078094 - /directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java Date: Fri, 04 Mar 2011 18:39:38 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110304183938.577D523888CE@eris.apache.org> Author: elecharny Date: Fri Mar 4 18:39:38 2011 New Revision: 1078094 URL: http://svn.apache.org/viewvc?rev=1078094&view=rev Log: Added the missing serializer Added: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java Added: 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=1078094&view=auto ============================================================================== --- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java (added) +++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEventSerializer.java Fri Mar 4 18:39:38 2011 @@ -0,0 +1,125 @@ +/* + * 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.server.core.changelog; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.List; + +import org.apache.directory.server.core.LdapPrincipal; +import org.apache.directory.server.core.LdapPrincipalSerializer; +import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException; +import org.apache.directory.shared.ldap.model.ldif.LdifEntry; +import org.apache.directory.shared.ldap.model.ldif.LdifEntrySerializer; +import org.apache.directory.shared.ldap.model.schema.SchemaManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A helper class which serialize and deserialize a ChangeLogEvent. + * + * @author Apache Directory Project + */ +public final class ChangeLogEventSerializer +{ + /** The LoggerFactory used by this class */ + protected static final Logger LOG = LoggerFactory.getLogger( ChangeLogEventSerializer.class ); + + /** + * Private constructor. + */ + private ChangeLogEventSerializer() + { + } + + + /** + * Serializes a ChangeLogEvent instance. + * + * @param principal The ChangeLogEvent instance to serialize + * @param out The stream into which we will write the serialized instance + * @throws IOException If the stream can't be written + */ + public static void serialize( ChangeLogEvent event, ObjectOutput out ) throws IOException + { + // The date the change has been created, "yyyyMMddHHmmss'Z'" + out.writeUTF( event.getZuluTime() ); + + // The committer's Principal + LdapPrincipalSerializer.serialize( event.getCommitterPrincipal(), out ); + + // The revision + out.writeLong( event.getRevision() ); + + // The forward LDIF + LdifEntrySerializer.serialize( event.getForwardLdif(), out ); + + // The reverse LDIFs number + int nbReverses = event.getReverseLdifs().size(); + out.writeInt( nbReverses ); + + for ( LdifEntry reverseLdif : event.getReverseLdifs() ) + { + LdifEntrySerializer.serialize( reverseLdif, out ); + } + } + + + /** + * Deserializes a ChangeLogEvent instance. + * + * @param schemaManager The SchemaManager (can be null) + * @param in The input stream from which the ChengaLogEvent is read + * @return a deserialized ChangeLogEvent + * @throws IOException If the stream can't be read + */ + public static ChangeLogEvent deserialize( SchemaManager schemaManager, ObjectInput in ) + throws IOException, LdapInvalidDnException + { + // The date the change has been created, "yyyyMMddHHmmss'Z'" + String zuluTime = in.readUTF(); + + // The committer's Principal + LdapPrincipal committerPrincipal = LdapPrincipalSerializer.deserialize( schemaManager, in ); + + // The revision + long revision = in.readLong(); + + // The forward LDIF + LdifEntry forwardEntry = LdifEntrySerializer.deserialize( schemaManager, in ); + + // The reverse LDIFs number + int nbReverses = in.readInt(); + + List reverses = new ArrayList( nbReverses ); + + for ( int i = 0; i < nbReverses; i++ ) + { + LdifEntry reverseEntry = LdifEntrySerializer.deserialize( schemaManager, in ); + reverses.add( reverseEntry ); + } + + ChangeLogEvent changeLogEvent = new ChangeLogEvent( revision, zuluTime, committerPrincipal, forwardEntry, reverses ); + + return changeLogEvent; + } +}