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   * The base request message class.
25   * 
26   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
27   */
28  public class AbstractRequest extends AbstractMessage implements Request
29  {
30      static final long serialVersionUID = -4511116249089399040L;
31  
32      /** Flag indicating whether or not this request returns a response. */
33      private final boolean hasResponse;
34  
35  
36      /**
37       * Subclasses must provide these parameters via a super constructor call.
38       * 
39       * @param id the sequential message identifier
40       * @param type the request type enum
41       * @param hasResponse flag indicating if this request generates a response
42       */
43      protected AbstractRequest( final int id, final MessageTypeEnum type, boolean hasResponse )
44      {
45          super( id, type );
46  
47          this.hasResponse = hasResponse;
48      }
49  
50  
51      /**
52       * Indicator flag used to determine whether or not this type of request
53       * produces a reply.
54       * 
55       * @return true if any reply is generated, false if no response is generated
56       */
57      @Override
58      public boolean hasResponse()
59      {
60          return hasResponse;
61      }
62  
63  
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public boolean equals( Object obj )
69      {
70          if ( obj == this )
71          {
72              return true;
73          }
74  
75          if ( ( obj == null ) || !( obj instanceof Request ) )
76          {
77              return false;
78          }
79  
80          if ( hasResponse != ( ( Request ) obj ).hasResponse() )
81          {
82              return false;
83          }
84          return super.equals( obj );
85      }
86  
87  
88      /**
89       * @see Object#hashCode()
90       * @return the instance's hash code 
91       */
92      @Override
93      public int hashCode()
94      {
95          int hash = 37;
96          hash = hash * 17 + ( hasResponse ? 0 : 1 );
97          hash = hash * 17 + super.hashCode();
98  
99          return hash;
100     }
101 }