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.mina.filter.reqres;
21  
22  /**
23   * TODO Add documentation
24   * 
25   * @author The Apache MINA Project (dev@mina.apache.org)
26   * @version $Rev: 663549 $, $Date: 2008-06-05 13:56:55 +0200 (Thu, 05 Jun 2008) $
27   */
28  public class Response {
29      private final Request request;
30  
31      private final ResponseType type;
32  
33      private final Object message;
34  
35      public Response(Request request, Object message, ResponseType type) {
36          if (request == null) {
37              throw new NullPointerException("request");
38          }
39  
40          if (message == null) {
41              throw new NullPointerException("message");
42          }
43  
44          if (type == null) {
45              throw new NullPointerException("type");
46          }
47  
48          this.request = request;
49          this.type = type;
50          this.message = message;
51      }
52  
53      public Request getRequest() {
54          return request;
55      }
56  
57      public ResponseType getType() {
58          return type;
59      }
60  
61      public Object getMessage() {
62          return message;
63      }
64  
65      @Override
66      public int hashCode() {
67          return getRequest().getId().hashCode();
68      }
69  
70      @Override
71      public boolean equals(Object o) {
72          if (o == this) {
73              return true;
74          }
75  
76          if (o == null) {
77              return false;
78          }
79  
80          if (!(o instanceof Response)) {
81              return false;
82          }
83  
84          Response that = (Response) o;
85          if (!this.getRequest().equals(that.getRequest())) {
86              return false;
87          }
88  
89          return this.getType().equals(that.getType());
90      }
91  
92      @Override
93      public String toString() {
94          return "response: { requestId=" + getRequest().getId() + ", type="
95                  + getType() + ", message=" + getMessage() + " }";
96      }
97  }