2
* $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Arg.java,v 1.17 2004/02/21 17:10:29 rleland Exp $
4
* $Date: 2004/02/21 17:10:29 $
6
* ====================================================================
7
* Copyright 2001-2004 The Apache Software Foundation
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
13
* http://www.apache.org/licenses/LICENSE-2.0
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.
22
package org.apache.commons.validator;
24
import java.io.Serializable;
28
* A default argument or an argument for a
29
* specific validator definition (ex: required)
30
* can be stored to pass into a message as parameters. This can be used in a
31
* pluggable validator for constructing locale
32
* sensitive messages by using <code>java.text.MessageFormat</code>
33
* or an equivalent class. The resource field can be
34
* used to determine if the value stored in the argument
35
* is a value to be retrieved from a locale sensitive
36
* message retrieval system like <code>java.util.PropertyResourceBundle</code>.
37
* The resource field defaults to 'true'.
39
* <p>Instances of this class are configured with an <arg> xml element.</p>
41
public class Arg implements Cloneable, Serializable {
44
* The resource bundle name that this Arg's <code>key</code> should be
45
* resolved in (optional).
46
* @since Validator 1.1
48
protected String bundle = null;
51
* The key or value of the argument.
53
protected String key = null;
56
* The name dependency that this argument goes with (optional).
58
protected String name = null;
61
* This argument's position in the message. Set postion=0 to
62
* make a replacement in this string: "some msg {0}".
63
* @since Validator 1.1
65
protected int position = 0;
68
* Whether or not the key is a message resource (optional). Defaults to
69
* true. If it is 'true', the value will try to be resolved as a message
72
protected boolean resource = true;
75
* Creates and returns a copy of this object.
76
* @return A copy of this object.
78
public Object clone() {
82
} catch(CloneNotSupportedException e) {
83
throw new RuntimeException(e.toString());
88
* Returns the resource bundle name.
89
* @since Validator 1.1
91
public String getBundle() {
97
* @return the key value.
99
public String getKey() {
104
* Gets the name of the dependency.
105
* @return the name of the dependency.
107
public String getName() {
112
* Argument's replacement position.
113
* @return This argument's replacement position.
115
public int getPosition() {
116
return this.position;
120
* Gets whether or not the key is a resource.
121
* @return Returns true if key is a resource.
122
* @deprecated Use isResource() instead.
124
public boolean getResource() {
125
return this.isResource();
129
* Tests whether or not the key is a resource key or literal value.
130
* @return <code>true</code> if key is a resource key.
132
public boolean isResource() {
133
return this.resource;
137
* Sets the resource bundle name.
138
* @param bundle The new bundle name.
139
* @since Validator 1.1
141
public void setBundle(String bundle) {
142
this.bundle = bundle;
146
* Sets the key/value.
147
* @param key They to access the argument.
149
public void setKey(String key) {
154
* Sets the name of the dependency.
155
* @param name the name of the dependency.
157
public void setName(String name) {
162
* Set this argument's replacement position.
163
* @param position set this argument's replacement position.
165
public void setPosition(int position) {
166
this.position = position;
170
* Sets whether or not the key is a resource.
171
* @param resource If true indicates the key is a resource.
173
public void setResource(boolean resource) {
174
this.resource = resource;
178
* Returns a string representation of the object.
179
* @return a string representation of the object.
181
public String toString() {
182
StringBuffer results = new StringBuffer();
184
results.append("Arg: name=");
185
results.append(name);
186
results.append(" key=");
188
results.append(" resource=");
189
results.append(resource);
190
results.append("\n");
192
return results.toString();
b'\\ No newline at end of file'