KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > util > FormMessage


1 package org.apache.turbine.util;
2
3 /*
4  * Copyright 2001-2004 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 import java.util.Vector JavaDoc;
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,v 1.4.2.2 2004/05/20 03:16:38 seade Exp $
28  */

29 public class FormMessage
30 {
31     private String JavaDoc message;
32     private String JavaDoc formName;
33     private Vector JavaDoc fieldNames;
34
35     /**
36      * Constructor.
37      */

38     public FormMessage()
39     {
40         fieldNames = new Vector JavaDoc();
41     }
42
43     /**
44      * Constructor.
45      *
46      * @param formName A String with the form name.
47      */

48     public FormMessage(String JavaDoc 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 JavaDoc formName,
61                        String JavaDoc 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 JavaDoc formName,
75                        String JavaDoc fieldName,
76                        String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc[] getFieldNames()
108     {
109         String JavaDoc[] result = new String JavaDoc[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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc toString()
149     {
150         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("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 }
159
Popular Tags