View Javadoc

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