KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > action > ActionMessage


1 /*
2  * $Id: ActionMessage.java 164530 2005-04-25 03:11:07Z niallp $
3  *
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.struts.action;
20
21 import java.io.Serializable JavaDoc;
22
23 /**
24  * <p>An encapsulation of an individual message returned by the
25  * <code>validate</code> method of an <code>ActionForm</code>, consisting
26  * of a message key (to be used to look up message text in an appropriate
27  * message resources database) plus up to four placeholder objects that can
28  * be used for parametric replacement in the message text.</p>
29  *
30  * @version $Rev: 164530 $ $Date: 2005-04-25 04:11:07 +0100 (Mon, 25 Apr 2005) $
31  * @since Struts 1.1
32  */

33 public class ActionMessage implements Serializable JavaDoc {
34
35
36     // ----------------------------------------------------------- Constructors
37

38
39     /**
40      * <p>Construct an action message with no replacement values.</p>
41      *
42      * @param key Message key for this message
43      */

44     public ActionMessage(String JavaDoc key) {
45         this(key, null);
46     }
47
48
49     /**
50      * <p>Construct an action message with the specified replacement values.</p>
51      *
52      * @param key Message key for this message
53      * @param value0 First replacement value
54      */

55     public ActionMessage(String JavaDoc key, Object JavaDoc value0) {
56         this(key, new Object JavaDoc[] { value0 });
57     }
58
59
60     /**
61      * <p>Construct an action message with the specified replacement values.</p>
62      *
63      * @param key Message key for this message
64      * @param value0 First replacement value
65      * @param value1 Second replacement value
66      */

67     public ActionMessage(String JavaDoc key, Object JavaDoc value0, Object JavaDoc value1) {
68         this(key, new Object JavaDoc[] { value0, value1 });
69     }
70
71
72     /**
73      * <p>Construct an action message with the specified replacement values.</p>
74      *
75      * @param key Message key for this message
76      * @param value0 First replacement value
77      * @param value1 Second replacement value
78      * @param value2 Third replacement value
79      */

80     public ActionMessage(String JavaDoc key, Object JavaDoc value0, Object JavaDoc value1,
81                        Object JavaDoc value2) {
82
83         this(key, new Object JavaDoc[] { value0, value1, value2 });
84     }
85
86
87     /**
88      * <p>Construct an action message with the specified replacement values.</p>
89      *
90      * @param key Message key for this message
91      * @param value0 First replacement value
92      * @param value1 Second replacement value
93      * @param value2 Third replacement value
94      * @param value3 Fourth replacement value
95      */

96     public ActionMessage(String JavaDoc key, Object JavaDoc value0, Object JavaDoc value1,
97                        Object JavaDoc value2, Object JavaDoc value3) {
98         
99         this(key, new Object JavaDoc[] { value0, value1, value2, value3 });
100     }
101
102
103     /**
104      * <p>Construct an action message with the specified replacement values.</p>
105      *
106      * @param key Message key for this message
107      * @param values Array of replacement values
108      */

109     public ActionMessage(String JavaDoc key, Object JavaDoc[] values) {
110
111         this.key = key;
112         this.values = values;
113         this.resource = true;
114
115     }
116
117     /**
118      * <p>Construct an action message with the specified replacement values.</p>
119      *
120      * @param key Message key for this message
121      * @param resource Indicates whether the key is a bundle key or literal value
122      */

123     public ActionMessage(String JavaDoc key, boolean resource) {
124  
125         this.key = key;
126         this.resource = resource;
127
128     }
129
130
131     // ----------------------------------------------------- Instance Variables
132

133
134     /**
135      * <p>The message key for this message.</p>
136      */

137     protected String JavaDoc key = null;
138
139
140     /**
141      * <p>The replacement values for this mesasge.</p>
142      */

143     protected Object JavaDoc values[] = null;
144
145     /**
146      * <p>Indicates whether the key is taken to be as a bundle key [true] or literal value [false].</p>
147      */

148     protected boolean resource = true;
149
150
151     // --------------------------------------------------------- Public Methods
152

153
154     /**
155      * <p>Get the message key for this message.</p>
156      */

157     public String JavaDoc getKey() {
158
159         return (this.key);
160
161     }
162
163
164     /**
165      * <p>Get the replacement values for this message.</p>
166      */

167     public Object JavaDoc[] getValues() {
168
169         return (this.values);
170
171     }
172
173
174     /**
175      * <p>Indicate whether the key is taken to be as a bundle key [true] or literal value [false].</p>
176      */

177     public boolean isResource() {
178
179         return (this.resource);
180
181     }
182     
183     /**
184      * <p>Returns a String in the format: key[value1, value2, etc].</p>
185      *
186      * @see java.lang.Object#toString()
187      */

188     public String JavaDoc toString() {
189         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
190         buff.append(this.key);
191         buff.append("[");
192
193         if (this.values != null) {
194
195             for (int i = 0; i < this.values.length; i++) {
196
197                 buff.append(this.values[i]);
198
199                 // don't append comma to last entry
200
if (i < this.values.length - 1) {
201                     buff.append(", ");
202                 }
203                 
204             }
205         }
206
207         buff.append("]");
208
209         return buff.toString();
210     }
211
212
213 }
214
Popular Tags