Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Arg |
|
| 1.25;1.25 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.apache.commons.validator; | |
18 | ||
19 | import java.io.Serializable; | |
20 | ||
21 | /** | |
22 | * <p> | |
23 | * A default argument or an argument for a | |
24 | * specific validator definition (ex: required) | |
25 | * can be stored to pass into a message as parameters. This can be used in a | |
26 | * pluggable validator for constructing locale | |
27 | * sensitive messages by using <code>java.text.MessageFormat</code> | |
28 | * or an equivalent class. The resource field can be | |
29 | * used to determine if the value stored in the argument | |
30 | * is a value to be retrieved from a locale sensitive | |
31 | * message retrieval system like <code>java.util.PropertyResourceBundle</code>. | |
32 | * The resource field defaults to 'true'. | |
33 | * </p> | |
34 | * <p>Instances of this class are configured with an <arg> xml element.</p> | |
35 | * | |
36 | * @version $Revision: 1739356 $ | |
37 | */ | |
38 | //TODO mutable non-private fields | |
39 | 163 | public class Arg implements Cloneable, Serializable { |
40 | ||
41 | private static final long serialVersionUID = -8922606779669839294L; | |
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 | 163 | protected String bundle = null; |
49 | ||
50 | /** | |
51 | * The key or value of the argument. | |
52 | */ | |
53 | 163 | protected String key = null; |
54 | ||
55 | /** | |
56 | * The name dependency that this argument goes with (optional). | |
57 | */ | |
58 | 163 | protected String 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 | 163 | 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 | 163 | protected boolean resource = true; |
73 | ||
74 | /** | |
75 | * Creates and returns a copy of this object. | |
76 | * @return A copy of this object. | |
77 | */ | |
78 | @Override | |
79 | public Object clone() { | |
80 | try { | |
81 | 0 | return super.clone(); |
82 | ||
83 | 0 | } catch(CloneNotSupportedException e) { |
84 | 0 | throw new RuntimeException(e.toString()); |
85 | } | |
86 | } | |
87 | ||
88 | /** | |
89 | * Returns the resource bundle name. | |
90 | * @return the bundle name. | |
91 | * @since Validator 1.1 | |
92 | */ | |
93 | public String getBundle() { | |
94 | 0 | return this.bundle; |
95 | } | |
96 | ||
97 | /** | |
98 | * Gets the key/value. | |
99 | * @return the key value. | |
100 | */ | |
101 | public String getKey() { | |
102 | 406 | return this.key; |
103 | } | |
104 | ||
105 | /** | |
106 | * Gets the name of the dependency. | |
107 | * @return the name of the dependency. | |
108 | */ | |
109 | public String getName() { | |
110 | 193 | return this.name; |
111 | } | |
112 | ||
113 | /** | |
114 | * Argument's replacement position. | |
115 | * @return This argument's replacement position. | |
116 | */ | |
117 | public int getPosition() { | |
118 | 800 | return this.position; |
119 | } | |
120 | ||
121 | /** | |
122 | * Tests whether or not the key is a resource key or literal value. | |
123 | * @return <code>true</code> if key is a resource key. | |
124 | */ | |
125 | public boolean isResource() { | |
126 | 0 | return this.resource; |
127 | } | |
128 | ||
129 | /** | |
130 | * Sets the resource bundle name. | |
131 | * @param bundle The new bundle name. | |
132 | * @since Validator 1.1 | |
133 | */ | |
134 | public void setBundle(String bundle) { | |
135 | 6 | this.bundle = bundle; |
136 | 6 | } |
137 | ||
138 | /** | |
139 | * Sets the key/value. | |
140 | * @param key They to access the argument. | |
141 | */ | |
142 | public void setKey(String key) { | |
143 | 203 | this.key = key; |
144 | 203 | } |
145 | ||
146 | /** | |
147 | * Sets the name of the dependency. | |
148 | * @param name the name of the dependency. | |
149 | */ | |
150 | public void setName(String name) { | |
151 | 9 | this.name = name; |
152 | 9 | } |
153 | ||
154 | /** | |
155 | * Set this argument's replacement position. | |
156 | * @param position set this argument's replacement position. | |
157 | */ | |
158 | public void setPosition(int position) { | |
159 | 163 | this.position = position; |
160 | 163 | } |
161 | ||
162 | /** | |
163 | * Sets whether or not the key is a resource. | |
164 | * @param resource If true indicates the key is a resource. | |
165 | */ | |
166 | public void setResource(boolean resource) { | |
167 | 0 | this.resource = resource; |
168 | 0 | } |
169 | ||
170 | /** | |
171 | * Returns a string representation of the object. | |
172 | * @return a string representation of the object. | |
173 | */ | |
174 | @Override | |
175 | public String toString() { | |
176 | 0 | StringBuilder results = new StringBuilder(); |
177 | ||
178 | 0 | results.append("Arg: name="); |
179 | 0 | results.append(name); |
180 | 0 | results.append(" key="); |
181 | 0 | results.append(key); |
182 | 0 | results.append(" position="); |
183 | 0 | results.append(position); |
184 | 0 | results.append(" bundle="); |
185 | 0 | results.append(bundle); |
186 | 0 | results.append(" resource="); |
187 | 0 | results.append(resource); |
188 | 0 | results.append("\n"); |
189 | ||
190 | 0 | return results.toString(); |
191 | } | |
192 | ||
193 | } |