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 import org.apache.directory.shared.ldap.message.internal.InternalAbstractResultResponse;
026 import org.apache.directory.shared.ldap.message.internal.InternalIntermediateResponse;
027
028 /**
029 * IntermediateResponse implementation
030 *
031 * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
032 * @version $Rev: 905344 $
033 */
034 public class IntermediateResponseImpl extends InternalAbstractResultResponse implements InternalIntermediateResponse
035 {
036 static final long serialVersionUID = -6646752766410531060L;
037
038 /** ResponseName for the intermediate response */
039 protected String oid;
040
041 /** Response Value for the intermediate response */
042 protected byte[] value;
043
044
045 // ------------------------------------------------------------------------
046 // Constructors
047 // ------------------------------------------------------------------------
048 public IntermediateResponseImpl( int id )
049 {
050 super( id, TYPE );
051 }
052
053
054 // ------------------------------------------------------------------------
055 // IntermediateResponse Interface Method Implementations
056 // ------------------------------------------------------------------------
057
058 /**
059 * Gets the reponseName specific encoded
060 *
061 * @return the response value
062 */
063 public byte[] getResponseValue()
064 {
065 if ( value == null )
066 {
067 return null;
068 }
069
070 final byte[] copy = new byte[ value.length ];
071 System.arraycopy( value, 0, copy, 0, value.length );
072 return copy;
073 }
074
075
076 /**
077 * Sets the response value
078 *
079 * @param value the response value.
080 */
081 public void setResponseValue( byte[] value )
082 {
083 if ( value != null )
084 {
085 this.value = new byte[ value.length ];
086 System.arraycopy( value, 0, this.value, 0, value.length );
087 } else {
088 this.value = null;
089 }
090 }
091
092
093 /**
094 * Gets the OID uniquely identifying this Intemediate response (a.k.a. its
095 * name).
096 *
097 * @return the OID of the Intemediate response type.
098 */
099 public String getResponseName()
100 {
101 return oid;
102 }
103
104
105 /**
106 * Sets the OID uniquely identifying this Intemediate response (a.k.a. its
107 * name).
108 *
109 * @param oid the OID of the Intemediate response type.
110 */
111 public void setResponseName( String oid )
112 {
113 this.oid = oid;
114 }
115
116
117 /**
118 * Checks to see if an object equals this IntemediateResponse.
119 *
120 * @param obj the object to be checked for equality
121 * @return true if the obj equals this IntemediateResponse, false otherwise
122 */
123 public boolean equals( Object obj )
124 {
125 if ( obj == this )
126 {
127 return true;
128 }
129
130 if ( !super.equals( obj ) )
131 {
132 return false;
133 }
134
135 if ( !( obj instanceof InternalIntermediateResponse ) )
136 {
137 return false;
138 }
139
140 InternalIntermediateResponse resp = ( InternalIntermediateResponse ) obj;
141
142 if ( ( oid != null ) && ( resp.getResponseName() == null ) )
143 {
144 return false;
145 }
146
147 if ( ( oid == null ) && ( resp.getResponseName() != null ) )
148 {
149 return false;
150 }
151
152 if ( ( oid != null ) && ( resp.getResponseName() != null ) )
153 {
154 if ( !oid.equals( resp.getResponseName() ) )
155 {
156 return false;
157 }
158 }
159
160 if ( ( value != null ) && ( resp.getResponseValue() == null ) )
161 {
162 return false;
163 }
164
165 if ( ( value == null ) && ( resp.getResponseValue() != null ) )
166 {
167 return false;
168 }
169
170 if ( ( value != null ) && ( resp.getResponseValue() != null ) )
171 {
172 if ( !Arrays.equals( value, resp.getResponseValue() ) )
173 {
174 return false;
175 }
176 }
177
178 return true;
179 }
180 }