KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > validator > Msg


1 /*
2  * $Id: Msg.java 155434 2005-02-26 13:16:41Z dirkv $
3  * $Rev$
4  * $Date: 2005-02-26 05:16:41 -0800 (Sat, 26 Feb 2005) $
5  *
6  * ====================================================================
7  * Copyright 2001-2005 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package org.apache.commons.validator;
23
24 import java.io.Serializable JavaDoc;
25
26 /**
27  * An alternative message can be associated with a <code>Field</code>
28  * and a pluggable validator instead of using the default message
29  * stored in the <code>ValidatorAction</code> (aka pluggable validator).
30  * Instances of this class are configured with a &lt;msg&gt; xml element.
31  */

32 public class Msg implements Cloneable JavaDoc, Serializable JavaDoc {
33
34     /**
35      * The resource bundle name that this Msg's <code>key</code> should be
36      * resolved in (optional).
37      * @since Validator 1.1
38      */

39     protected String JavaDoc bundle = null;
40
41     /**
42      * The key or value of the argument.
43      */

44     protected String JavaDoc key = null;
45
46     /**
47      * The name dependency that this argument goes with (optional).
48      */

49     protected String JavaDoc name = null;
50
51     /**
52      * Whether or not the key is a message resource (optional). Defaults to
53      * true. If it is 'true', the value will try to be resolved as a message
54      * resource.
55      * @since Validator 1.1.4
56      */

57     protected boolean resource = true;
58
59     /**
60      * Returns the resource bundle name.
61      * @since Validator 1.1
62      */

63     public String JavaDoc getBundle() {
64         return this.bundle;
65     }
66
67     /**
68      * Sets the resource bundle name.
69      * @param bundle The new bundle name.
70      * @since Validator 1.1
71      */

72     public void setBundle(String JavaDoc bundle) {
73         this.bundle = bundle;
74     }
75
76     /**
77      * Gets the name of the dependency.
78      */

79     public String JavaDoc getName() {
80         return name;
81     }
82
83     /**
84      * Sets the name of the dependency.
85      */

86     public void setName(String JavaDoc name) {
87         this.name = name;
88     }
89
90     /**
91      * Gets the key/value.
92      */

93     public String JavaDoc getKey() {
94         return key;
95     }
96
97     /**
98      * Sets the key/value.
99      */

100     public void setKey(String JavaDoc key) {
101         this.key = key;
102     }
103
104     /**
105      * Tests whether or not the key is a resource key or literal value.
106      * @return <code>true</code> if key is a resource key.
107      * @since Validator 1.1.4
108      */

109     public boolean isResource() {
110         return this.resource;
111     }
112
113     /**
114      * Sets whether or not the key is a resource.
115      * @param resource If true indicates the key is a resource.
116      * @since Validator 1.1.4
117      */

118     public void setResource(boolean resource) {
119         this.resource = resource;
120     }
121
122     /**
123      * Creates and returns a copy of this object.
124      */

125     public Object JavaDoc clone() {
126         try {
127             return super.clone();
128
129         } catch(CloneNotSupportedException JavaDoc e) {
130             throw new RuntimeException JavaDoc(e.toString());
131         }
132     }
133
134     /**
135      * Returns a string representation of the object.
136      */

137     public String JavaDoc toString() {
138         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
139
140         results.append("Msg: name=");
141         results.append(name);
142         results.append(" key=");
143         results.append(key);
144         results.append(" resource=");
145         results.append(resource);
146         results.append(" bundle=");
147         results.append(bundle);
148         results.append("\n");
149
150         return results.toString();
151     }
152
153 }
Popular Tags