View Javadoc

1   package org.apache.turbine.util;
2   
3   
4   /*
5    * Copyright 2001-2004 The Apache Software Foundation.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License")
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  
21  import java.util.Vector;
22  
23  /***
24   * A message class for holding information about a message that
25   * relates to a specific form and field.  Used together with
26   * FormMessages class.
27   *
28   * @author <a href="mailto:neeme@one.lv">Neeme Praks</a>
29   * @version $Id: FormMessage.java 222043 2004-12-06 17:47:33Z painter $
30   */
31  public class FormMessage
32  {
33      private String message;
34      private String formName;
35      private Vector fieldNames;
36  
37      /***
38       * Constructor.
39       */
40      public FormMessage()
41      {
42          fieldNames = new Vector();
43      }
44  
45      /***
46       * Constructor.
47       *
48       * @param formName A String with the form name.
49       */
50      public FormMessage(String formName)
51      {
52          this();
53          setFormName(formName);
54      }
55  
56      /***
57       * Constructor.
58       *
59       * @param formName A String with the form name.
60       * @param fieldName A String with the field name.
61       */
62      public FormMessage(String formName,
63                         String fieldName)
64      {
65          this(formName);
66          setFieldName(fieldName);
67      }
68  
69      /***
70       * Constructor.
71       *
72       * @param formName A String with the form name.
73       * @param fieldName A String with the field name.
74       * @param message A String with the message.
75       */
76      public FormMessage(String formName,
77                         String fieldName,
78                         String message)
79      {
80          this(formName, fieldName);
81          setMessage(message);
82      }
83  
84      /***
85       * Return the message.
86       *
87       * @return A String with the message.
88       */
89      public String getMessage()
90      {
91          return message;
92      }
93  
94      /***
95       * Return the form name.
96       *
97       * @return A String with the form name.
98       */
99      public String getFormName()
100     {
101         return formName;
102     }
103 
104     /***
105      * Return the field names.
106      *
107      * @return A String[] with the field names.
108      */
109     public String[] getFieldNames()
110     {
111         String[] result = new String[fieldNames.size()];
112         fieldNames.copyInto(result);
113         return result;
114     }
115 
116     /***
117      * Set the message.
118      *
119      * @param message A String with the message.
120      */
121     public void setMessage(String message)
122     {
123         this.message = message;
124     }
125 
126     /***
127      * Set the form name.
128      *
129      * @param formName A String with the form name.
130      */
131     public void setFormName(String formName)
132     {
133         this.formName = formName;
134     }
135 
136     /***
137      * Adds one field name.
138      *
139      * @param fieldName A String with the field name.
140      */
141     public void setFieldName(String fieldName)
142     {
143         fieldNames.addElement(fieldName);
144     }
145 
146     /***
147      * Write out the contents of the message in a friendly manner.
148      *
149      */
150     public String toString()
151     {
152         StringBuffer sb = new StringBuffer("formName:" + getFormName() + ", fieldNames:");
153         for (int i = 0; i< getFieldNames().length; i++){
154             sb.append(getFieldNames()[i] + " ");
155         }
156         sb.append(", message:" + getMessage());
157 
158         return sb.toString();
159     }
160 }