001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.message;
021
022
023 import java.util.Arrays;
024
025 /**
026 * Lockable ExtendedResponse implementation
027 *
028 * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
029 * @version $Rev: 764131 $
030 */
031 public class ExtendedResponseImpl extends InternalAbstractResultResponse implements InternalExtendedResponse
032 {
033 static final long serialVersionUID = -6646752766410531060L;
034
035 /** Object identifier for the extended response */
036 protected String oid;
037
038 /** Values encoded in the extended response payload */
039 protected byte[] value;
040
041
042 // ------------------------------------------------------------------------
043 // Constructors
044 // ------------------------------------------------------------------------
045
046 /**
047 * Creates a Lockable ExtendedResponse as a reply to an ExtendedRequest.
048 *
049 * @param id
050 * the session unique message id
051 */
052 public ExtendedResponseImpl( final int id, String oid )
053 {
054 super( id, TYPE );
055 this.oid = oid;
056 }
057
058
059 public ExtendedResponseImpl( int id )
060 {
061 super( id, TYPE );
062 }
063
064
065 // ------------------------------------------------------------------------
066 // ExtendedResponse Interface Method Implementations
067 // ------------------------------------------------------------------------
068
069 /**
070 * Gets the reponse OID specific encoded response values.
071 *
072 * @return the response specific encoded response values.
073 */
074 public byte[] getResponse()
075 {
076 if ( value == null )
077 {
078 return null;
079 }
080
081 final byte[] copy = new byte[ value.length ];
082 System.arraycopy( value, 0, copy, 0, value.length );
083 return copy;
084 }
085
086
087 /**
088 * Sets the response OID specific encoded response values.
089 *
090 * @param value
091 * the response specific encoded response values.
092 */
093 public void setResponse( byte[] value )
094 {
095 if ( value != null )
096 {
097 this.value = new byte[ value.length ];
098 System.arraycopy( value, 0, this.value, 0, value.length );
099 } else {
100 this.value = null;
101 }
102 }
103
104
105 public void setOid( String oid )
106 {
107 this.oid = oid;
108 }
109
110
111 /**
112 * Gets the OID uniquely identifying this extended response (a.k.a. its
113 * name).
114 *
115 * @return the OID of the extended response type.
116 */
117 public String getResponseName()
118 {
119 return oid;
120 }
121
122
123 /**
124 * Sets the OID uniquely identifying this extended response (a.k.a. its
125 * name).
126 *
127 * @param oid
128 * the OID of the extended response type.
129 */
130 public void setResponseName( String oid )
131 {
132 this.oid = oid;
133 }
134
135
136 /**
137 * Checks to see if an object equals this ExtendedRequest.
138 *
139 * @param obj
140 * the object to be checked for equality
141 * @return true if the obj equals this ExtendedRequest, false otherwise
142 */
143 public boolean equals( Object obj )
144 {
145 if ( obj == this )
146 {
147 return true;
148 }
149
150 if ( !super.equals( obj ) )
151 {
152 return false;
153 }
154
155 if ( !( obj instanceof InternalExtendedResponse ) )
156 {
157 return false;
158 }
159
160 InternalExtendedResponse resp = ( InternalExtendedResponse ) obj;
161
162 if ( oid != null && resp.getResponseName() == null )
163 {
164 return false;
165 }
166
167 if ( oid == null && resp.getResponseName() != null )
168 {
169 return false;
170 }
171
172 if ( oid != null && resp.getResponseName() != null )
173 {
174 if ( !oid.equals( resp.getResponseName() ) )
175 {
176 return false;
177 }
178 }
179
180 if ( value != null && resp.getResponse() == null )
181 {
182 return false;
183 }
184
185 if ( value == null && resp.getResponse() != null )
186 {
187 return false;
188 }
189
190 if ( value != null && resp.getResponse() != null )
191 {
192 if ( !Arrays.equals( value, resp.getResponse() ) )
193 {
194 return false;
195 }
196 }
197
198 return true;
199 }
200
201
202 public String getID()
203 {
204 return getResponseName();
205 }
206
207
208 public byte[] getEncodedValue()
209 {
210 return getResponse();
211 }
212 }