View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.message;
21  
22  
23  /**
24   * A simple ExtendedResponse implementation.
25   * 
26   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
27   */
28  public class ExtendedResponseImpl extends AbstractResultResponse implements ExtendedResponse
29  {
30      static final long serialVersionUID = -6646752766410531060L;
31  
32      /** Object identifier for the extended response */
33      protected String responseName;
34  
35  
36      /**
37       * Creates an ExtendedResponse as a reply to an ExtendedRequest.
38       * 
39       * @param responseName the ExtendedResponse's name
40       */
41      public ExtendedResponseImpl( String responseName )
42      {
43          super( -1, TYPE );
44          this.responseName = responseName;
45      }
46  
47  
48      /**
49       * Creates an ExtendedResponse as a reply to an ExtendedRequest.
50       * 
51       * @param id the session unique message id
52       * @param responseName the ExtendedResponse's name
53       */
54      public ExtendedResponseImpl( final int id, String responseName )
55      {
56          super( id, TYPE );
57          this.responseName = responseName;
58      }
59  
60  
61      /**
62       * Creates an ExtendedResponse as a reply to an ExtendedRequest.
63       * 
64       * @param id the session unique message id
65       */
66      public ExtendedResponseImpl( int id )
67      {
68          super( id, TYPE );
69      }
70  
71  
72      // ------------------------------------------------------------------------
73      // ExtendedResponse Interface Method Implementations
74      // ------------------------------------------------------------------------
75  
76      /**
77       * Gets the OID uniquely identifying this extended response (a.k.a. its
78       * name).
79       * 
80       * @return the responseName of the extended response
81       */
82      public String getResponseName()
83      {
84          return ( ( responseName == null ) ? "" : responseName );
85      }
86  
87  
88      /**
89       * Sets the OID uniquely identifying this extended response (a.k.a. its
90       * name).
91       * 
92       * @param responseName the OID of the extended response type.
93       */
94      public void setResponseName( String responseName )
95      {
96          this.responseName = responseName;
97      }
98  
99  
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     public int hashCode()
105     {
106         int hash = 37;
107 
108         if ( responseName != null )
109         {
110             hash = hash * 17 + responseName.hashCode();
111         }
112 
113         hash = hash * 17 + super.hashCode();
114 
115         return hash;
116     }
117 
118 
119     /**
120      * Checks to see if an object equals this ExtendedRequest.
121      * 
122      * @param obj
123      *            the object to be checked for equality
124      * @return true if the obj equals this ExtendedRequest, false otherwise
125      */
126     public boolean equals( Object obj )
127     {
128         if ( obj == this )
129         {
130             return true;
131         }
132 
133         if ( !super.equals( obj ) )
134         {
135             return false;
136         }
137 
138         if ( !( obj instanceof ExtendedResponse ) )
139         {
140             return false;
141         }
142 
143         ExtendedResponse resp = ( ExtendedResponse ) obj;
144 
145         if ( ( responseName != null ) && ( resp.getResponseName() == null ) )
146         {
147             return false;
148         }
149 
150         if ( ( responseName == null ) && ( resp.getResponseName() != null ) )
151         {
152             return false;
153         }
154 
155         if ( ( responseName != null ) && ( resp.getResponseName() != null )
156             && !responseName.equals( resp.getResponseName() ) )
157         {
158             return false;
159         }
160 
161         return true;
162     }
163 
164 
165     /**
166      * Get a String representation of an ExtendedResponse
167      * 
168      * @return An ExtendedResponse String
169      */
170     public String toString()
171     {
172         StringBuilder sb = new StringBuilder();
173 
174         sb.append( "    Extended Response\n" );
175 
176         if ( responseName != null )
177         {
178             sb.append( "        ResponseName :'" ).append( responseName ).append( "'\n" );
179         }
180 
181         sb.append( super.toString() );
182 
183         return super.toString( sb.toString() );
184     }
185 }