View Javadoc

1   /*
2    * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Var.java,v 1.11 2004/02/21 17:10:29 rleland Exp $
3    * $Revision: 1.11 $
4    * $Date: 2004/02/21 17:10:29 $
5    *
6    * ====================================================================
7    * Copyright 2001-2004 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;
25  
26  /***
27   * A variable that can be associated with a <code>Field</code> for
28   * passing in information to a pluggable validator.  Instances of this class are
29   * configured with a &lt;var&gt; xml element.
30   */
31  public class Var implements Cloneable, Serializable {
32  
33      /***
34       * Int Constant for JavaScript type.  This can be used
35       * when auto-generating JavaScript.
36       */
37      public static final String JSTYPE_INT = "int";
38  
39      /***
40       * String Constant for JavaScript type.  This can be used
41       * when auto-generating JavaScript.
42       */
43      public static final String JSTYPE_STRING = "string";
44  
45      /***
46       * Regular Expression Constant for JavaScript type.  This can be used
47       * when auto-generating JavaScript.
48       */
49      public static final String JSTYPE_REGEXP = "regexp";
50  
51      /***
52       * The name of the variable.
53       */
54      private String name = null;
55  
56      /***
57       * The name of the value.
58       */
59      private String value = null;
60  
61      /***
62       * The optional JavaScript type of the variable.
63       */
64      private String jsType = null;
65  
66      public Var() {
67          super();
68      }
69  
70      public Var(String name, String value, String jsType) {
71          this.name = name;
72          this.value = value;
73          this.jsType = jsType;
74      }
75  
76      /***
77       * Gets the name of the variable.
78       */
79      public String getName() {
80          return this.name;
81      }
82  
83      /***
84       * Sets the name of the variable.
85       */
86      public void setName(String name) {
87          this.name = name;
88      }
89  
90      /***
91       * Gets the value of the variable.
92       */
93      public String getValue() {
94          return this.value;
95      }
96  
97      /***
98       * Sets the value of the variable.
99       */
100     public void setValue(String value) {
101         this.value = value;
102     }
103 
104     /***
105      * Gets the JavaScript type of the variable.
106      */
107     public String getJsType() {
108         return this.jsType;
109     }
110 
111     /***
112      * Sets the JavaScript type of the variable.
113      */
114     public void setJsType(String jsType) {
115         this.jsType = jsType;
116     }
117 
118     /***
119      * Creates and returns a copy of this object.
120      */
121     public Object clone() {
122         try {
123             return super.clone();
124 
125         } catch(CloneNotSupportedException e) {
126             throw new RuntimeException(e.toString());
127         }
128     }
129 
130     /***
131      * Returns a string representation of the object.
132      */
133     public String toString() {
134         StringBuffer results = new StringBuffer();
135 
136         results.append("Var: name=");
137         results.append(name);
138         results.append("  value=");
139         results.append(value);
140         results.append("  jsType=");
141         results.append(jsType);
142         results.append("\n");
143 
144         return results.toString();
145     }
146 
147 }