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. package org.apache.commons.validator;
  22. import java.io.Serializable;
  23. /**
  24. * A variable that can be associated with a <code>Field</code> for
  25. * passing in information to a pluggable validator. Instances of this class are
  26. * configured with a <var> xml element.
  27. */
  28. public class Var implements Cloneable, Serializable {
  29. /**
  30. * Int Constant for JavaScript type. This can be used
  31. * when auto-generating JavaScript.
  32. */
  33. public static final String JSTYPE_INT = "int";
  34. /**
  35. * String Constant for JavaScript type. This can be used
  36. * when auto-generating JavaScript.
  37. */
  38. public static final String JSTYPE_STRING = "string";
  39. /**
  40. * Regular Expression Constant for JavaScript type. This can be used
  41. * when auto-generating JavaScript.
  42. */
  43. public static final String JSTYPE_REGEXP = "regexp";
  44. /**
  45. * The name of the variable.
  46. */
  47. private String name = null;
  48. /**
  49. * The name of the value.
  50. */
  51. private String value = null;
  52. /**
  53. * The optional JavaScript type of the variable.
  54. */
  55. private String jsType = null;
  56. public Var() {
  57. super();
  58. }
  59. public Var(String name, String value, String jsType) {
  60. this.name = name;
  61. this.value = value;
  62. this.jsType = jsType;
  63. }
  64. /**
  65. * Gets the name of the variable.
  66. */
  67. public String getName() {
  68. return this.name;
  69. }
  70. /**
  71. * Sets the name of the variable.
  72. */
  73. public void setName(String name) {
  74. this.name = name;
  75. }
  76. /**
  77. * Gets the value of the variable.
  78. */
  79. public String getValue() {
  80. return this.value;
  81. }
  82. /**
  83. * Sets the value of the variable.
  84. */
  85. public void setValue(String value) {
  86. this.value = value;
  87. }
  88. /**
  89. * Gets the JavaScript type of the variable.
  90. */
  91. public String getJsType() {
  92. return this.jsType;
  93. }
  94. /**
  95. * Sets the JavaScript type of the variable.
  96. */
  97. public void setJsType(String jsType) {
  98. this.jsType = jsType;
  99. }
  100. /**
  101. * Creates and returns a copy of this object.
  102. */
  103. public Object clone() {
  104. try {
  105. return super.clone();
  106. } catch(CloneNotSupportedException e) {
  107. throw new RuntimeException(e.toString());
  108. }
  109. }
  110. /**
  111. * Returns a string representation of the object.
  112. */
  113. public String toString() {
  114. StringBuffer results = new StringBuffer();
  115. results.append("Var: name=");
  116. results.append(name);
  117. results.append(" value=");
  118. results.append(value);
  119. results.append(" jsType=");
  120. results.append(jsType);
  121. results.append("\n");
  122. return results.toString();
  123. }
  124. }