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