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 protected byte[] responseValue;
42
43
44
45
46
47
48 public IntermediateResponseImpl( int id )
49 {
50 super( id, TYPE );
51 }
52
53
54
55
56
57
58
59
60
61
62
63 @Override
64 public byte[] getResponseValue()
65 {
66 if ( responseValue == null )
67 {
68 return null;
69 }
70
71 final byte[] copy = new byte[responseValue.length];
72 System.arraycopy( responseValue, 0, copy, 0, responseValue.length );
73 return copy;
74 }
75
76
77
78
79
80
81
82 @Override
83 public void setResponseValue( byte[] value )
84 {
85 if ( value != null )
86 {
87 this.responseValue = new byte[value.length];
88 System.arraycopy( value, 0, this.responseValue, 0, value.length );
89 }
90 else
91 {
92 this.responseValue = null;
93 }
94 }
95
96
97
98
99
100
101
102
103 @Override
104 public String getResponseName()
105 {
106 return ( responseName == null ) ? "" : responseName;
107 }
108
109
110
111
112
113
114
115
116 @Override
117 public void setResponseName( String oid )
118 {
119 this.responseName = oid;
120 }
121
122
123
124
125
126 @Override
127 public int hashCode()
128 {
129 int hash = 37;
130 if ( responseName != null )
131 {
132 hash = hash * 17 + responseName.hashCode();
133 }
134 if ( responseValue != null )
135 {
136 hash = hash * 17 + Arrays.hashCode( responseValue );
137 }
138 hash = hash * 17 + super.hashCode();
139
140 return hash;
141 }
142
143
144
145
146
147
148
149
150 @Override
151 public boolean equals( Object obj )
152 {
153 if ( obj == this )
154 {
155 return true;
156 }
157
158 if ( !super.equals( obj ) )
159 {
160 return false;
161 }
162
163 if ( !( obj instanceof IntermediateResponse ) )
164 {
165 return false;
166 }
167
168 IntermediateResponse resp = ( IntermediateResponse ) obj;
169
170 if ( ( responseName != null ) && ( resp.getResponseName() == null ) )
171 {
172 return false;
173 }
174
175 if ( ( responseName == null ) && ( resp.getResponseName() != null ) )
176 {
177 return false;
178 }
179
180 if ( ( responseName != null ) && ( resp.getResponseName() != null )
181 && !responseName.equals( resp.getResponseName() ) )
182 {
183 return false;
184 }
185
186 if ( ( responseValue != null ) && ( resp.getResponseValue() == null ) )
187 {
188 return false;
189 }
190
191 if ( ( responseValue == null ) && ( resp.getResponseValue() != null ) )
192 {
193 return false;
194 }
195
196 return ( responseValue == null ) || ( resp.getResponseValue() == null )
197 || Arrays.equals( responseValue, resp.getResponseValue() );
198 }
199
200
201
202
203
204
205
206 @Override
207 public String toString()
208 {
209 StringBuilder sb = new StringBuilder();
210
211 sb.append( " Intermediate Response\n" );
212
213 if ( responseName != null )
214 {
215 sb.append( " Response name :'" ).append( responseName ).append( "'\n" );
216 }
217
218 if ( responseValue != null )
219 {
220 sb.append( " ResponseValue :'" );
221 sb.append( Strings.dumpBytes( responseValue ) );
222 sb.append( "'\n" );
223 }
224
225 sb.append( super.toString() );
226
227 return super.toString( sb.toString() );
228 }
229 }