Coverage report

  %line %branch
org.apache.commons.validator.Var
51% 
93% 

 1  
 /*
 2  
  * $Id: Var.java 289160 2005-09-15 05:48:33Z niallp $
 3  
  * $Rev: 289160 $
 4  
  * $Date: 2005-09-15 06:48:33 +0100 (Thu, 15 Sep 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;
 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  125
     private String name = null;
 55  
 
 56  
     /**
 57  
      * The key or value the variable.
 58  
      */
 59  125
     private String value = null;
 60  
 
 61  
     /**
 62  
      * The optional JavaScript type of the variable.
 63  
      */
 64  125
     private String jsType = null;
 65  
 
 66  
     /**
 67  
      * Whether the variable is a resource [false]
 68  
      */
 69  125
     private boolean resource = false;
 70  
 
 71  
     /**
 72  
      * The bundle for a variable (when resource = 'true').
 73  
      */
 74  125
     private String bundle = null;
 75  
 
 76  
     /**
 77  
      * Default Constructor.
 78  
      */
 79  
     public Var() {
 80  125
         super();
 81  125
     }
 82  
 
 83  
     /**
 84  
      * Constructs a variable with a specified name, value
 85  
      * and Javascript type.
 86  
      * @param name Variable name.
 87  
      * @param value Variable value.
 88  
      * @param jsType Variable Javascript type.
 89  
      */
 90  0
     public Var(String name, String value, String jsType) {
 91  0
         this.name = name;
 92  0
         this.value = value;
 93  0
         this.jsType = jsType;
 94  0
     }
 95  
 
 96  
     /**
 97  
      * Gets the name of the variable.
 98  
      * @return The name of the variable.
 99  
      */
 100  
     public String getName() {
 101  128
         return this.name;
 102  
     }
 103  
 
 104  
     /**
 105  
      * Sets the name of the variable.
 106  
      * @param name The name of the variable.
 107  
      */
 108  
     public void setName(String name) {
 109  125
         this.name = name;
 110  125
     }
 111  
 
 112  
     /**
 113  
      * Gets the value of the variable.
 114  
      * @return The value of the variable.
 115  
      */
 116  
     public String getValue() {
 117  272
         return this.value;
 118  
     }
 119  
 
 120  
     /**
 121  
      * Sets the value of the variable.
 122  
      * @param value The value of the variable.
 123  
      */
 124  
     public void setValue(String value) {
 125  205
         this.value = value;
 126  205
     }
 127  
 
 128  
     /**
 129  
      * Tests whether or not the value is a resource key or literal value.
 130  
      * @return <code>true</code> if value is a resource key.
 131  
      * @since Validator 1.2.0
 132  
      */
 133  
     public boolean isResource() {
 134  3
         return this.resource;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Sets whether or not the value is a resource.
 139  
      * @param resource If true indicates the value is a resource.
 140  
      * @since Validator 1.2.0
 141  
      */
 142  
     public void setResource(boolean resource) {
 143  2
         this.resource = resource;
 144  2
     }
 145  
 
 146  
     /**
 147  
      * Returns the resource bundle name.
 148  
      * @return The bundle name.
 149  
      * @since Validator 1.2.0
 150  
      */
 151  
     public String getBundle() {
 152  3
         return this.bundle;
 153  
     }
 154  
 
 155  
     /**
 156  
      * Sets the resource bundle name.
 157  
      * @param bundle The new bundle name.
 158  
      * @since Validator 1.2.0
 159  
      */
 160  
     public void setBundle(String bundle) {
 161  2
         this.bundle = bundle;
 162  2
     }
 163  
 
 164  
     /**
 165  
      * Gets the JavaScript type of the variable.
 166  
      * @return The Javascript type of the variable.
 167  
      */
 168  
     public String getJsType() {
 169  3
         return this.jsType;
 170  
     }
 171  
 
 172  
     /**
 173  
      * Sets the JavaScript type of the variable.
 174  
      * @param jsType The Javascript type of the variable.
 175  
      */
 176  
     public void setJsType(String jsType) {
 177  2
         this.jsType = jsType;
 178  2
     }
 179  
 
 180  
     /**
 181  
      * Creates and returns a copy of this object.
 182  
      * @return A copy of the variable.
 183  
      */
 184  
     public Object clone() {
 185  
         try {
 186  0
             return super.clone();
 187  
 
 188  
         } catch(CloneNotSupportedException e) {
 189  0
             throw new RuntimeException(e.toString());
 190  
         }
 191  
     }
 192  
 
 193  
     /**
 194  
      * Returns a string representation of the object.
 195  
      * @return A string representation of the variable.
 196  
      */
 197  
     public String toString() {
 198  0
         StringBuffer results = new StringBuffer();
 199  
 
 200  0
         results.append("Var: name=");
 201  0
         results.append(name);
 202  0
         results.append("  value=");
 203  0
         results.append(value);
 204  0
         results.append("  resource=");
 205  0
         results.append(resource);
 206  0
         if (resource) {
 207  0
             results.append("  bundle=");
 208  0
             results.append(bundle);
 209  
         }
 210  0
         results.append("  jsType=");
 211  0
         results.append(jsType);
 212  0
         results.append("\n");
 213  
 
 214  0
         return results.toString();
 215  
     }
 216  
 
 217  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.