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.model.message;
21
22
23 import java.util.Arrays;
24
25 import org.apache.directory.api.util.Strings;
26
27
28
29
30
31
32
33 public class IntermediateResponseImpl extends AbstractResultResponse implements IntermediateResponse
34 {
35 static final long serialVersionUID = -6646752766410531060L;
36
37
38 protected String responseName;
39
40
41 private static final MessageTypeEnum TYPE = MessageTypeEnum.INTERMEDIATE_RESPONSE;
42
43
44 protected byte[] responseValue;
45
46
47
48
49
50
51 public IntermediateResponseImpl( String responseName )
52 {
53 super( -1, TYPE );
54 this.responseName = responseName;
55 }
56
57
58
59
60
61
62
63
64 public IntermediateResponseImpl( int id, String responseName )
65 {
66 super( id, TYPE );
67 this.responseName = responseName;
68 }
69
70
71
72
73
74
75 public IntermediateResponseImpl( int id )
76 {
77 super( id, TYPE );
78 }
79
80
81
82
83
84
85
86
87
88
89
90 @Override
91 public byte[] getResponseValue()
92 {
93 if ( responseValue == null )
94 {
95 return null;
96 }
97
98 final byte[] copy = new byte[responseValue.length];
99 System.arraycopy( responseValue, 0, copy, 0, responseValue.length );
100 return copy;
101 }
102
103
104
105
106
107
108
109 @Override
110 public void setResponseValue( byte[] value )
111 {
112 if ( value != null )
113 {
114 this.responseValue = new byte[value.length];
115 System.arraycopy( value, 0, this.responseValue, 0, value.length );
116 }
117 else
118 {
119 this.responseValue = null;
120 }
121 }
122
123
124
125
126
127
128
129
130 @Override
131 public String getResponseName()
132 {
133 return ( responseName == null ) ? "" : responseName;
134 }
135
136
137
138
139
140
141
142
143 @Override
144 public void setResponseName( String oid )
145 {
146 this.responseName = oid;
147 }
148
149
150
151
152
153 @Override
154 public int hashCode()
155 {
156 int hash = 37;
157 if ( responseName != null )
158 {
159 hash = hash * 17 + responseName.hashCode();
160 }
161 if ( responseValue != null )
162 {
163 hash = hash * 17 + Arrays.hashCode( responseValue );
164 }
165 hash = hash * 17 + super.hashCode();
166
167 return hash;
168 }
169
170
171
172
173
174
175
176
177 @Override
178 public boolean equals( Object obj )
179 {
180 if ( obj == this )
181 {
182 return true;
183 }
184
185 if ( !super.equals( obj ) )
186 {
187 return false;
188 }
189
190 if ( !( obj instanceof IntermediateResponse ) )
191 {
192 return false;
193 }
194
195 IntermediateResponse resp = ( IntermediateResponse ) obj;
196
197 if ( ( responseName != null ) && ( resp.getResponseName() == null ) )
198 {
199 return false;
200 }
201
202 if ( ( responseName == null ) && ( resp.getResponseName() != null ) )
203 {
204 return false;
205 }
206
207 if ( ( responseName != null ) && ( resp.getResponseName() != null )
208 && !responseName.equals( resp.getResponseName() ) )
209 {
210 return false;
211 }
212
213 if ( ( responseValue != null ) && ( resp.getResponseValue() == null ) )
214 {
215 return false;
216 }
217
218 if ( ( responseValue == null ) && ( resp.getResponseValue() != null ) )
219 {
220 return false;
221 }
222
223 return ( responseValue == null ) || ( resp.getResponseValue() == null )
224 || Arrays.equals( responseValue, resp.getResponseValue() );
225 }
226
227
228
229
230
231
232
233 @Override
234 public String toString()
235 {
236 StringBuilder sb = new StringBuilder();
237
238 sb.append( " Intermediate Response\n" );
239
240 if ( responseName != null )
241 {
242 sb.append( " Response name :'" ).append( responseName ).append( "'\n" );
243 }
244
245 if ( responseValue != null )
246 {
247 sb.append( " ResponseValue :'" );
248 sb.append( Strings.dumpBytes( responseValue ) );
249 sb.append( "'\n" );
250 }
251
252 sb.append( super.toString() );
253
254 return super.toString( sb.toString() );
255 }
256 }