1 | /* |
2 | * jDTAUS Core API |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * <cs@schulte.it> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2.1 of the License, or any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | package org.jdtaus.core.container; |
22 | |
23 | import java.io.Serializable; |
24 | |
25 | /** |
26 | * Message meta-data. |
27 | * <p>A message consists of the properties {@code name}, {@code template} and |
28 | * {@code arguments}. Property {@code name} holds a name uniquely identifying |
29 | * the message in a set of messages. Property {@code template} holds the |
30 | * template of the message. Property {@code arguments} holds meta-data |
31 | * describing arguments to format the message with.</p> |
32 | * |
33 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
34 | * @version $JDTAUS: Message.java 8743 2012-10-07 03:06:20Z schulte $ |
35 | */ |
36 | public class Message extends ModelObject implements Cloneable, Serializable |
37 | { |
38 | //--Constants--------------------------------------------------------------- |
39 | |
40 | /** Serial version UID for backwards compatibility with 1.5.x classes. */ |
41 | private static final long serialVersionUID = 8433823757935477327L; |
42 | |
43 | //---------------------------------------------------------------Constants-- |
44 | //--Message.---------------------------------------------------------------- |
45 | |
46 | /** |
47 | * The name of the message. |
48 | * @serial |
49 | */ |
50 | private String name; |
51 | |
52 | /** |
53 | * The name of the module holding the message. |
54 | * @serial |
55 | */ |
56 | private String moduleName; |
57 | |
58 | /** |
59 | * The template of the message. |
60 | * @serial |
61 | */ |
62 | private Text template; |
63 | |
64 | /** |
65 | * The arguments of the message. |
66 | * @serial |
67 | */ |
68 | private Arguments arguments; |
69 | |
70 | /** Creates a new {@code Message} instance. */ |
71 | public Message() |
72 | { |
73 | super(); |
74 | } |
75 | |
76 | /** |
77 | * Gets the name of the message. |
78 | * |
79 | * @return the name of the message. |
80 | */ |
81 | public String getName() |
82 | { |
83 | if ( this.name == null ) |
84 | { |
85 | this.name = ""; |
86 | } |
87 | |
88 | return this.name; |
89 | } |
90 | |
91 | /** |
92 | * Setter for property {@code name}. |
93 | * |
94 | * @param value the new name of the message. |
95 | */ |
96 | public void setName( final String value ) |
97 | { |
98 | this.name = value; |
99 | } |
100 | |
101 | /** |
102 | * Gets the name of the module holding the message. |
103 | * |
104 | * @return the name of the module holding the message. |
105 | */ |
106 | public String getModuleName() |
107 | { |
108 | if ( this.moduleName == null ) |
109 | { |
110 | this.moduleName = ""; |
111 | } |
112 | |
113 | return this.moduleName; |
114 | } |
115 | |
116 | /** |
117 | * Setter for property {@code moduleName}. |
118 | * |
119 | * @param value the new name of the module holding the message. |
120 | */ |
121 | public void setModuleName( final String value ) |
122 | { |
123 | this.moduleName = value; |
124 | } |
125 | |
126 | /** |
127 | * Gets the template of the message. |
128 | * |
129 | * @return the template of the message. |
130 | */ |
131 | public Text getTemplate() |
132 | { |
133 | if ( this.template == null ) |
134 | { |
135 | this.template = new Text(); |
136 | } |
137 | |
138 | return this.template; |
139 | } |
140 | |
141 | /** |
142 | * Setter for property {@code template}. |
143 | * |
144 | * @param value the new template of the message. |
145 | */ |
146 | public void setTemplate( final Text value ) |
147 | { |
148 | this.template = value; |
149 | } |
150 | |
151 | /** |
152 | * Gets the arguments of the message. |
153 | * |
154 | * @return the arguments of the message. |
155 | */ |
156 | public Arguments getArguments() |
157 | { |
158 | if ( this.arguments == null ) |
159 | { |
160 | this.arguments = new Arguments(); |
161 | } |
162 | |
163 | return this.arguments; |
164 | } |
165 | |
166 | /** |
167 | * Setter for property {@code arguments}. |
168 | * |
169 | * @param value the new arguments of the message. |
170 | */ |
171 | public void setArguments( final Arguments value ) |
172 | { |
173 | this.arguments = value; |
174 | } |
175 | |
176 | /** |
177 | * Creates a string representing the properties of the instance. |
178 | * |
179 | * @return a string representing the properties of the instance. |
180 | */ |
181 | private String internalString() |
182 | { |
183 | final StringBuffer buf = new StringBuffer( 500 ).append( '{' ). |
184 | append( this.internalString( this ) ). |
185 | append( ", name=" ).append( this.name ). |
186 | append( ", moduleName=" ).append( this.moduleName ). |
187 | append( ", template=" ).append( this.template ). |
188 | append( ", arguments=" ).append( this.arguments ); |
189 | |
190 | buf.append( '}' ); |
191 | return buf.toString(); |
192 | } |
193 | |
194 | //----------------------------------------------------------------Template-- |
195 | //--Object------------------------------------------------------------------ |
196 | |
197 | /** |
198 | * Returns a string representation of the object. |
199 | * |
200 | * @return a string representation of the object. |
201 | */ |
202 | public String toString() |
203 | { |
204 | return super.toString() + this.internalString(); |
205 | } |
206 | |
207 | /** |
208 | * Creates and returns a copy of this object. This method performs a |
209 | * "shallow copy" of this object, not a "deep copy" operation. |
210 | * |
211 | * @return a clone of this instance. |
212 | */ |
213 | public Object clone() |
214 | { |
215 | try |
216 | { |
217 | return super.clone(); |
218 | } |
219 | catch ( final CloneNotSupportedException e ) |
220 | { |
221 | throw new AssertionError( e ); |
222 | } |
223 | } |
224 | |
225 | /** |
226 | * Indicates whether some other object is equal to this one by comparing |
227 | * properties {@code name} and {@code moduleName}. |
228 | * |
229 | * @param o the reference object with which to compare. |
230 | * |
231 | * @return {@code true} if this object is the same as {@code o}; |
232 | * {@code false} otherwise. |
233 | */ |
234 | public final boolean equals( final Object o ) |
235 | { |
236 | boolean equal = o == this; |
237 | if ( !equal && o instanceof Message ) |
238 | { |
239 | final Message that = (Message) o; |
240 | equal = this.getName().equals( that.getName() ) && |
241 | this.getModuleName().equals( that.getModuleName() ); |
242 | |
243 | } |
244 | |
245 | return equal; |
246 | } |
247 | |
248 | /** |
249 | * Returns a hash code value for this object. |
250 | * |
251 | * @return a hash code value for this object. |
252 | */ |
253 | public final int hashCode() |
254 | { |
255 | return this.getName().hashCode() + this.getModuleName().hashCode(); |
256 | } |
257 | |
258 | //------------------------------------------------------------------Object-- |
259 | } |