Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BasicMessage |
|
| 1.2857142857142858;1.286 |
1 | /* | |
2 | * $Id: BasicMessage.java 366395 2006-01-06 02:42:19Z niallp $ | |
3 | * $Revision: 366395 $ | |
4 | * $Date: 2006-01-06 02:42:19 +0000 (Fri, 06 Jan 2006) $ | |
5 | * | |
6 | * ==================================================================== | |
7 | * | |
8 | * Copyright 2003-2006 The Apache Software Foundation | |
9 | * | |
10 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
11 | * you may not use this file except in compliance with the License. | |
12 | * You may obtain a copy of the License at | |
13 | * | |
14 | * http://www.apache.org/licenses/LICENSE-2.0 | |
15 | * | |
16 | * Unless required by applicable law or agreed to in writing, software | |
17 | * distributed under the License is distributed on an "AS IS" BASIS, | |
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 | * See the License for the specific language governing permissions and | |
20 | * limitations under the License. | |
21 | * | |
22 | */ | |
23 | ||
24 | package org.apache.commons.resources.impl; | |
25 | ||
26 | import java.io.Serializable; | |
27 | ||
28 | import org.apache.commons.resources.Message; | |
29 | ||
30 | /** | |
31 | * A basic implementation of the Message interface. | |
32 | * <p> | |
33 | * Orginally based on org.apache.struts.action.ActionMessage, Revision 49176. | |
34 | */ | |
35 | public class BasicMessage implements Serializable, Message { | |
36 | ||
37 | /** | |
38 | * The logical name of the {@link org.apache.commons.resources.Resources} | |
39 | * instance this message is associated with (optional). | |
40 | */ | |
41 | private String resourcesName; | |
42 | ||
43 | /** | |
44 | * The message key for this message. | |
45 | */ | |
46 | 0 | private String key = null; |
47 | ||
48 | /** | |
49 | * The replacement values for this message. | |
50 | */ | |
51 | 0 | private Object[] values = null; |
52 | ||
53 | /** | |
54 | * Default Constructor. | |
55 | */ | |
56 | public BasicMessage() { | |
57 | 0 | super(); |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Construct a message with no replacement values. | |
62 | * | |
63 | * @param key Message key for this message | |
64 | */ | |
65 | 0 | public BasicMessage(String key) { |
66 | ||
67 | 0 | this.key = key; |
68 | 0 | this.values = null; |
69 | ||
70 | 0 | } |
71 | ||
72 | /** | |
73 | * Construct a message with the specified replacement values. | |
74 | * | |
75 | * @param key Message key for this message | |
76 | * @param value0 First replacement value | |
77 | */ | |
78 | 0 | public BasicMessage(String key, Object value0) { |
79 | ||
80 | 0 | this.key = key; |
81 | 0 | this.values = new Object[]{value0}; |
82 | ||
83 | 0 | } |
84 | ||
85 | /** | |
86 | * Construct a message with the specified replacement values. | |
87 | * | |
88 | * @param key Message key for this message | |
89 | * @param value0 First replacement value | |
90 | * @param value1 Second replacement value | |
91 | */ | |
92 | 0 | public BasicMessage(String key, Object value0, Object value1) { |
93 | ||
94 | 0 | this.key = key; |
95 | 0 | this.values = new Object[]{value0, value1}; |
96 | ||
97 | 0 | } |
98 | ||
99 | /** | |
100 | * Construct a message with the specified replacement values. | |
101 | * | |
102 | * @param key Message key for this message | |
103 | * @param value0 First replacement value | |
104 | * @param value1 Second replacement value | |
105 | * @param value2 Third replacement value | |
106 | */ | |
107 | public BasicMessage(String key, Object value0, Object value1, | |
108 | 0 | Object value2) { |
109 | ||
110 | 0 | this.key = key; |
111 | 0 | this.values = new Object[]{value0, value1, value2}; |
112 | ||
113 | 0 | } |
114 | ||
115 | /** | |
116 | * Construct a message with the specified replacement values. | |
117 | * | |
118 | * @param key Message key for this message | |
119 | * @param value0 First replacement value | |
120 | * @param value1 Second replacement value | |
121 | * @param value2 Third replacement value | |
122 | * @param value3 Fourth replacement value | |
123 | */ | |
124 | public BasicMessage(String key, Object value0, Object value1, | |
125 | 0 | Object value2, Object value3) { |
126 | ||
127 | 0 | this.key = key; |
128 | 0 | this.values = new Object[]{value0, value1, value2, value3}; |
129 | 0 | } |
130 | ||
131 | /** | |
132 | * Construct a message with the specified replacement values. | |
133 | * | |
134 | * @param key Message key for this message | |
135 | * @param values Array of replacement values | |
136 | */ | |
137 | 0 | public BasicMessage(String key, Object[] values) { |
138 | 0 | this.key = key; |
139 | 0 | this.values = values; |
140 | 0 | } |
141 | ||
142 | /** | |
143 | * <p>Return the logical name of the {@link org.apache.commons.resources.Resources} | |
144 | * instance this message is associated with.</p> | |
145 | * | |
146 | * @return The name of the resources instance. | |
147 | */ | |
148 | public String getResourcesName() { | |
149 | 0 | return resourcesName; |
150 | } | |
151 | ||
152 | /** | |
153 | * <p>Set the logical name of the {@link org.apache.commons.resources.Resources} | |
154 | * instance this message is associated with.</p> | |
155 | * | |
156 | * @param resourcesName The name of the resources instance. | |
157 | */ | |
158 | public void setResourcesName(String resourcesName) { | |
159 | 0 | this.resourcesName = resourcesName; |
160 | 0 | } |
161 | ||
162 | /** | |
163 | * @return Get the message key for this message. | |
164 | */ | |
165 | public String getKey() { | |
166 | 0 | return (this.key); |
167 | } | |
168 | ||
169 | /** | |
170 | * Set the key for the message. | |
171 | * | |
172 | * @param key The key to set. | |
173 | */ | |
174 | public void setKey(String key) { | |
175 | 0 | this.key = key; |
176 | 0 | } |
177 | ||
178 | /** | |
179 | * @return Get the replacement values for this message. | |
180 | */ | |
181 | public Object[] getValues() { | |
182 | 0 | return (this.values); |
183 | } | |
184 | ||
185 | /** | |
186 | * @param values The replacement values for this message. | |
187 | */ | |
188 | public void setValues(Object[] values) { | |
189 | 0 | this.values = values; |
190 | 0 | } |
191 | ||
192 | /** | |
193 | * Returns a String in the format: resourcesName:key[value0, value1, etc]. | |
194 | * @see java.lang.Object#toString() | |
195 | */ | |
196 | public String toString() { | |
197 | 0 | StringBuffer buff = new StringBuffer(); |
198 | 0 | if (this.resourcesName != null) { |
199 | 0 | buff.append(this.resourcesName); |
200 | 0 | buff.append(":"); |
201 | } | |
202 | 0 | buff.append(this.key); |
203 | 0 | buff.append("["); |
204 | ||
205 | 0 | if (this.values != null) { |
206 | ||
207 | 0 | for (int i = 0; i < this.values.length; i++) { |
208 | ||
209 | 0 | buff.append(this.values[i]); |
210 | ||
211 | // don't append comma to last entry | |
212 | 0 | if (i < this.values.length - 1) { |
213 | 0 | buff.append(", "); |
214 | } | |
215 | ||
216 | } | |
217 | } | |
218 | ||
219 | 0 | buff.append("]"); |
220 | ||
221 | 0 | return buff.toString(); |
222 | } | |
223 | ||
224 | } |