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