KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > inject > spi > Message


1 /**
2  * Copyright (C) 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  */

16
17 package com.google.inject.spi;
18
19 import static com.google.inject.util.Objects.nonNull;
20
21 /**
22  * A message. Contains a source pointing to the code which resulted
23  * in this message and a text message.
24  *
25  * @author crazybob@google.com (Bob Lee)
26  */

27 public class Message {
28
29   final Object JavaDoc source;
30   final String JavaDoc message;
31
32   public Message(Object JavaDoc source, String JavaDoc message) {
33     this.source = nonNull(source, "source");
34     this.message = nonNull(message, "message");
35   }
36
37   public Message(String JavaDoc message) {
38     this(SourceProviders.UNKNOWN_SOURCE, message);
39   }
40
41   /**
42    * Gets the source of the configuration which resulted in this error message.
43    */

44   public Object JavaDoc getSource() {
45     return source;
46   }
47
48   String JavaDoc sourceString = null;
49
50   /**
51    * Returns a string representation of the source object.
52    */

53   public String JavaDoc getSourceString() {
54     if (sourceString == null) {
55       sourceString = source.toString();
56     }
57     return sourceString;
58   }
59
60   /**
61    * Gets the error message text.
62    */

63   public String JavaDoc getMessage() {
64     return message;
65   }
66
67   public String JavaDoc toString() {
68     return getSourceString() + " " + message;
69   }
70
71   public int hashCode() {
72     return source.hashCode() * 31 + message.hashCode();
73   }
74
75   public boolean equals(Object JavaDoc o) {
76     if (!(o instanceof Message)) {
77       return false;
78     }
79     Message e = (Message) o;
80     return source.equals(e.source) && message.equals(e.message);
81   }
82 }
83
Popular Tags