01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */package com.bm.ejb3guice.spi;
16:
17: import static com.bm.ejb3guice.internal.Objects.nonNull;
18:
19: /**
20: * A message. Contains a source pointing to the code which resulted
21: * in this message and a text message.
22: *
23: * @author crazybob@google.com (Bob Lee)
24: */
25: public class Message {
26:
27: final Object source;
28: final String message;
29:
30: public Message(Object source, String message) {
31: this .source = nonNull(source, "source");
32: this .message = nonNull(message, "message");
33: }
34:
35: public Message(String message) {
36: this (SourceProviders.UNKNOWN_SOURCE, message);
37: }
38:
39: /**
40: * Gets the source of the configuration which resulted in this error message.
41: */
42: public Object getSource() {
43: return source;
44: }
45:
46: String sourceString = null;
47:
48: /**
49: * Returns a string representation of the source object.
50: */
51: public String getSourceString() {
52: if (sourceString == null) {
53: sourceString = source.toString();
54: }
55: return sourceString;
56: }
57:
58: /**
59: * Gets the error message text.
60: */
61: public String getMessage() {
62: return message;
63: }
64:
65: public String toString() {
66: return getSourceString() + " " + message;
67: }
68:
69: public int hashCode() {
70: return source.hashCode() * 31 + message.hashCode();
71: }
72:
73: public boolean equals(Object o) {
74: if (!(o instanceof Message)) {
75: return false;
76: }
77: Message e = (Message) o;
78: return source.equals(e.source) && message.equals(e.message);
79: }
80: }
|