1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.extras.extended.startTransaction;
21
22
23 import java.util.Arrays;
24
25 import org.apache.directory.api.i18n.I18n;
26 import org.apache.directory.api.ldap.model.message.AbstractExtendedResponse;
27 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
28 import org.apache.directory.api.util.Strings;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class StartTransactionResponseImpl extends AbstractExtendedResponse implements StartTransactionResponse
47 {
48
49 private byte[] transactionId;
50
51
52
53
54
55
56
57
58 public StartTransactionResponseImpl( int messageId, ResultCodeEnum resultCode, byte[] transactionId )
59 {
60 super( messageId );
61
62 switch ( resultCode )
63 {
64 case SUCCESS:
65 this.transactionId = Strings.copy( transactionId );
66 break;
67
68 case CANCELED:
69 case CANNOT_CANCEL:
70 case NO_SUCH_OPERATION:
71 case TOO_LATE:
72 break;
73
74 default:
75 throw new IllegalArgumentException( I18n.err( I18n.ERR_13503_RESULT_CODE_SHOULD_BE_IN, ResultCodeEnum.SUCCESS,
76 ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
77 }
78
79 super.getLdapResult().setMatchedDn( null );
80 super.getLdapResult().setResultCode( resultCode );
81 }
82
83
84
85
86
87
88
89
90 public StartTransactionResponseImpl( int messageId, byte[] transactionId )
91 {
92 super( messageId );
93 super.getLdapResult().setMatchedDn( null );
94 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
95 this.transactionId = Strings.copy( transactionId );
96 }
97
98
99
100
101
102
103
104 public StartTransactionResponseImpl( byte[] transactionId )
105 {
106 super( StartTransactionRequest.EXTENSION_OID );
107 super.getLdapResult().setMatchedDn( null );
108 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
109 this.transactionId = Strings.copy( transactionId );
110 }
111
112
113
114
115
116 public StartTransactionResponseImpl()
117 {
118 super( StartTransactionRequest.EXTENSION_OID );
119 super.getLdapResult().setMatchedDn( null );
120 super.getLdapResult().setResultCode( ResultCodeEnum.UNWILLING_TO_PERFORM );
121 }
122
123
124
125
126
127 @Override
128 public int hashCode()
129 {
130 int hash = 37;
131
132 if ( transactionId != null )
133 {
134 for ( byte b : transactionId )
135 {
136 hash += hash * 17 + b;
137 }
138 }
139
140 hash = hash * 17 + getClass().getName().hashCode();
141
142 return hash;
143 }
144
145
146
147
148
149 @Override
150 public boolean equals( Object obj )
151 {
152 if ( obj == this )
153 {
154 return true;
155 }
156
157 if ( !( obj instanceof StartTransactionResponseImpl ) )
158 {
159 return false;
160 }
161
162 return Arrays.equals( transactionId, ( ( StartTransactionResponseImpl ) obj ).transactionId );
163 }
164
165
166
167
168
169 @Override
170 public byte[] getTransactionId()
171 {
172 return Strings.copy( transactionId );
173 }
174
175
176
177
178
179 public void setTransactionId( byte[] transactionId )
180 {
181 this.transactionId = Strings.copy( transactionId );
182 }
183
184
185
186
187
188 @Override
189 public String toString()
190 {
191 StringBuilder sb = new StringBuilder();
192
193 sb.append( "StartTransactionResponse :" );
194 sb.append( "\n transactionID : " );
195
196 if ( transactionId != null )
197 {
198 sb.append( Strings.dumpBytes( transactionId ) );
199 }
200 else
201 {
202 sb.append( "null" );
203 }
204
205 return sb.toString();
206 }
207 }