KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: Arg.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  * <p>
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'.
38  * </p>
39  * <p>Instances of this class are configured with an &lt;arg&gt; xml element.</p>
40  */

41 public class Arg implements Cloneable JavaDoc, Serializable JavaDoc {
42
43     /**
44      * The resource bundle name that this Arg's <code>key</code> should be
45      * resolved in (optional).
46      * @since Validator 1.1
47      */

48     protected String JavaDoc bundle = null;
49
50     /**
51      * The key or value of the argument.
52      */

53     protected String JavaDoc key = null;
54
55     /**
56      * The name dependency that this argument goes with (optional).
57      */

58     protected String JavaDoc name = null;
59
60     /**
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
64      */

65     protected int position = -1;
66
67     /**
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
70      * resource.
71      */

72     protected boolean resource = true;
73
74     /**
75      * Creates and returns a copy of this object.
76      * @return A copy of this object.
77      */

78     public Object JavaDoc clone() {
79         try {
80             return super.clone();
81
82         } catch(CloneNotSupportedException JavaDoc e) {
83             throw new RuntimeException JavaDoc(e.toString());
84         }
85     }
86
87     /**
88      * Returns the resource bundle name.
89      * @since Validator 1.1
90      */

91     public String JavaDoc getBundle() {
92         return this.bundle;
93     }
94
95     /**
96      * Gets the key/value.
97      * @return the key value.
98      */

99     public String JavaDoc getKey() {
100         return this.key;
101     }
102
103     /**
104      * Gets the name of the dependency.
105      * @return the name of the dependency.
106      */

107     public String JavaDoc getName() {
108         return this.name;
109     }
110
111     /**
112      * Argument's replacement position.
113      * @return This argument's replacement position.
114      */

115     public int getPosition() {
116         return this.position;
117     }
118
119     /**
120      * Tests whether or not the key is a resource key or literal value.
121      * @return <code>true</code> if key is a resource key.
122      */

123     public boolean isResource() {
124         return this.resource;
125     }
126
127     /**
128      * Sets the resource bundle name.
129      * @param bundle The new bundle name.
130      * @since Validator 1.1
131      */

132     public void setBundle(String JavaDoc bundle) {
133         this.bundle = bundle;
134     }
135
136     /**
137      * Sets the key/value.
138      * @param key They to access the argument.
139      */

140     public void setKey(String JavaDoc key) {
141         this.key = key;
142     }
143
144     /**
145      * Sets the name of the dependency.
146      * @param name the name of the dependency.
147      */

148     public void setName(String JavaDoc name) {
149         this.name = name;
150     }
151
152     /**
153      * Set this argument's replacement position.
154      * @param position set this argument's replacement position.
155      */

156     public void setPosition(int position) {
157         this.position = position;
158     }
159
160     /**
161      * Sets whether or not the key is a resource.
162      * @param resource If true indicates the key is a resource.
163      */

164     public void setResource(boolean resource) {
165         this.resource = resource;
166     }
167
168     /**
169      * Returns a string representation of the object.
170      * @return a string representation of the object.
171      */

172     public String JavaDoc toString() {
173         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
174
175         results.append("Arg: name=");
176         results.append(name);
177         results.append(" key=");
178         results.append(key);
179         results.append(" position=");
180         results.append(position);
181         results.append(" bundle=");
182         results.append(bundle);
183         results.append(" resource=");
184         results.append(resource);
185         results.append("\n");
186
187         return results.toString();
188     }
189
190 }
Popular Tags