1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.api.changelog;
21
22
23 import java.io.IOException;
24 import java.io.ObjectInput;
25 import java.io.ObjectOutput;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
30 import org.apache.directory.api.ldap.model.ldif.LdifEntry;
31 import org.apache.directory.api.ldap.model.schema.SchemaManager;
32 import org.apache.directory.server.core.api.LdapPrincipal;
33 import org.apache.directory.server.core.api.LdapPrincipalSerializer;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41
42
43 public final class ChangeLogEventSerializer
44 {
45
46 protected static final Logger LOG = LoggerFactory.getLogger( ChangeLogEventSerializer.class );
47
48
49
50
51
52 private ChangeLogEventSerializer()
53 {
54 }
55
56
57
58
59
60
61
62
63
64 public static void serialize( ChangeLogEvent event, ObjectOutput out ) throws IOException
65 {
66
67 out.writeUTF( event.getZuluTime() );
68
69
70 LdapPrincipalSerializer.serialize( event.getCommitterPrincipal(), out );
71
72
73 out.writeLong( event.getRevision() );
74
75
76 event.getForwardLdif().writeExternal( out );
77
78
79 int nbReverses = event.getReverseLdifs().size();
80 out.writeInt( nbReverses );
81
82 for ( LdifEntry reverseLdif : event.getReverseLdifs() )
83 {
84 reverseLdif.writeExternal( out );
85 }
86
87 out.flush();
88 }
89
90
91
92
93
94
95
96
97
98
99 public static ChangeLogEvent deserialize( SchemaManager schemaManager, ObjectInput in )
100 throws IOException, LdapInvalidDnException
101 {
102
103 String zuluTime = in.readUTF();
104
105
106 LdapPrincipal committerPrincipal = LdapPrincipalSerializer.deserialize( schemaManager, in );
107
108
109 long revision = in.readLong();
110
111
112 LdifEntry forwardEntry = new LdifEntry();
113
114 try
115 {
116 forwardEntry.readExternal( in );
117 }
118 catch ( ClassNotFoundException cnfe )
119 {
120 IOException ioe = new IOException( cnfe.getMessage() );
121 ioe.initCause( cnfe );
122 throw ioe;
123 }
124
125
126 int nbReverses = in.readInt();
127
128 List<LdifEntry> reverses = new ArrayList<LdifEntry>( nbReverses );
129
130 for ( int i = 0; i < nbReverses; i++ )
131 {
132 LdifEntry reverseEntry = new LdifEntry();
133
134 try
135 {
136 reverseEntry.readExternal( in );
137 }
138 catch ( ClassNotFoundException cnfe )
139 {
140 IOException ioe = new IOException( cnfe.getMessage() );
141 ioe.initCause( cnfe );
142 throw ioe;
143 }
144
145 reverses.add( reverseEntry );
146 }
147
148 ChangeLogEvent changeLogEvent = new ChangeLogEvent( revision, zuluTime, committerPrincipal, forwardEntry,
149 reverses );
150
151 return changeLogEvent;
152 }
153 }