001: package org.apache.turbine.util;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.Vector;
023:
024: /**
025: * A message class for holding information about a message that
026: * relates to a specific form and field. Used together with
027: * FormMessages class.
028: *
029: * @author <a href="mailto:neeme@one.lv">Neeme Praks</a>
030: * @version $Id: FormMessage.java 534527 2007-05-02 16:10:59Z tv $
031: */
032: public class FormMessage {
033: private String message;
034: private String formName;
035: private Vector fieldNames;
036:
037: /**
038: * Constructor.
039: */
040: public FormMessage() {
041: fieldNames = new Vector();
042: }
043:
044: /**
045: * Constructor.
046: *
047: * @param formName A String with the form name.
048: */
049: public FormMessage(String formName) {
050: this ();
051: setFormName(formName);
052: }
053:
054: /**
055: * Constructor.
056: *
057: * @param formName A String with the form name.
058: * @param fieldName A String with the field name.
059: */
060: public FormMessage(String formName, String fieldName) {
061: this (formName);
062: setFieldName(fieldName);
063: }
064:
065: /**
066: * Constructor.
067: *
068: * @param formName A String with the form name.
069: * @param fieldName A String with the field name.
070: * @param message A String with the message.
071: */
072: public FormMessage(String formName, String fieldName, String message) {
073: this (formName, fieldName);
074: setMessage(message);
075: }
076:
077: /**
078: * Return the message.
079: *
080: * @return A String with the message.
081: */
082: public String getMessage() {
083: return message;
084: }
085:
086: /**
087: * Return the form name.
088: *
089: * @return A String with the form name.
090: */
091: public String getFormName() {
092: return formName;
093: }
094:
095: /**
096: * Return the field names.
097: *
098: * @return A String[] with the field names.
099: */
100: public String[] getFieldNames() {
101: String[] result = new String[fieldNames.size()];
102: fieldNames.copyInto(result);
103: return result;
104: }
105:
106: /**
107: * Set the message.
108: *
109: * @param message A String with the message.
110: */
111: public void setMessage(String message) {
112: this .message = message;
113: }
114:
115: /**
116: * Set the form name.
117: *
118: * @param formName A String with the form name.
119: */
120: public void setFormName(String formName) {
121: this .formName = formName;
122: }
123:
124: /**
125: * Adds one field name.
126: *
127: * @param fieldName A String with the field name.
128: */
129: public void setFieldName(String fieldName) {
130: fieldNames.addElement(fieldName);
131: }
132:
133: /**
134: * Write out the contents of the message in a friendly manner.
135: *
136: */
137: public String toString() {
138: StringBuffer sb = new StringBuffer("formName:" + getFormName()
139: + ", fieldNames:");
140: for (int i = 0; i < getFieldNames().length; i++) {
141: sb.append(getFieldNames()[i] + " ");
142: }
143: sb.append(", message:" + getMessage());
144:
145: return sb.toString();
146: }
147: }
|