directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
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 GMT
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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+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<LdifEntry> reverses = new ArrayList<LdifEntry>( 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;
+    }
+}



Mime
View raw message