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      public boolean hasResponse()
58      {
59          return hasResponse;
60      }
61  
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public boolean equals( Object obj )
68      {
69          if ( obj == this )
70          {
71              return true;
72          }
73  
74          if ( ( obj == null ) || !( obj instanceof Request ) )
75          {
76              return false;
77          }
78  
79          if ( hasResponse != ( ( Request ) obj ).hasResponse() )
80          {
81              return false;
82          }
83          return super.equals( obj );
84      }
85  
86  
87      /**
88       * @see Object#hashCode()
89       * @return the instance's hash code 
90       */
91      @Override
92      public int hashCode()
93      {
94          int hash = 37;
95          hash = hash * 17 + ( hasResponse ? 0 : 1 );
96          hash = hash * 17 + super.hashCode();
97  
98          return hash;
99      }
100 }