1 package org.apache.turbine.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Vector;
20
21 /***
22 * A message class for holding information about a message that
23 * relates to a specific form and field. Used together with
24 * FormMessages class.
25 *
26 * @author <a href="mailto:neeme@one.lv">Neeme Praks</a>
27 * @version $Id: FormMessage.java 264148 2005-08-29 14:21:04Z henning $
28 */
29 public class FormMessage
30 {
31 private String message;
32 private String formName;
33 private Vector fieldNames;
34
35 /***
36 * Constructor.
37 */
38 public FormMessage()
39 {
40 fieldNames = new Vector();
41 }
42
43 /***
44 * Constructor.
45 *
46 * @param formName A String with the form name.
47 */
48 public FormMessage(String formName)
49 {
50 this();
51 setFormName(formName);
52 }
53
54 /***
55 * Constructor.
56 *
57 * @param formName A String with the form name.
58 * @param fieldName A String with the field name.
59 */
60 public FormMessage(String formName,
61 String fieldName)
62 {
63 this(formName);
64 setFieldName(fieldName);
65 }
66
67 /***
68 * Constructor.
69 *
70 * @param formName A String with the form name.
71 * @param fieldName A String with the field name.
72 * @param message A String with the message.
73 */
74 public FormMessage(String formName,
75 String fieldName,
76 String message)
77 {
78 this(formName, fieldName);
79 setMessage(message);
80 }
81
82 /***
83 * Return the message.
84 *
85 * @return A String with the message.
86 */
87 public String getMessage()
88 {
89 return message;
90 }
91
92 /***
93 * Return the form name.
94 *
95 * @return A String with the form name.
96 */
97 public String getFormName()
98 {
99 return formName;
100 }
101
102 /***
103 * Return the field names.
104 *
105 * @return A String[] with the field names.
106 */
107 public String[] getFieldNames()
108 {
109 String[] result = new String[fieldNames.size()];
110 fieldNames.copyInto(result);
111 return result;
112 }
113
114 /***
115 * Set the message.
116 *
117 * @param message A String with the message.
118 */
119 public void setMessage(String message)
120 {
121 this.message = message;
122 }
123
124 /***
125 * Set the form name.
126 *
127 * @param formName A String with the form name.
128 */
129 public void setFormName(String formName)
130 {
131 this.formName = formName;
132 }
133
134 /***
135 * Adds one field name.
136 *
137 * @param fieldName A String with the field name.
138 */
139 public void setFieldName(String fieldName)
140 {
141 fieldNames.addElement(fieldName);
142 }
143
144 /***
145 * Write out the contents of the message in a friendly manner.
146 *
147 */
148 public String toString()
149 {
150 StringBuffer sb = new StringBuffer("formName:" + getFormName() + ", fieldNames:");
151 for (int i = 0; i< getFieldNames().length; i++){
152 sb.append(getFieldNames()[i] + " ");
153 }
154 sb.append(", message:" + getMessage());
155
156 return sb.toString();
157 }
158 }