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