| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.validator.Msg |
|
|
| 1 | /* |
|
| 2 | * $Id: Msg.java 280974 2005-09-15 00:06:59Z niallp $ |
|
| 3 | * $Rev: 280974 $ |
|
| 4 | * $Date: 2005-09-15 01:06:59 +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 | * An alternative message can be associated with a <code>Field</code> |
|
| 28 | * and a pluggable validator instead of using the default message |
|
| 29 | * stored in the <code>ValidatorAction</code> (aka pluggable validator). |
|
| 30 | * Instances of this class are configured with a <msg> xml element. |
|
| 31 | */ |
|
| 32 | 0 | public class Msg implements Cloneable, Serializable { |
| 33 | ||
| 34 | /** |
|
| 35 | * The resource bundle name that this Msg's <code>key</code> should be |
|
| 36 | * resolved in (optional). |
|
| 37 | * @since Validator 1.1 |
|
| 38 | */ |
|
| 39 | 0 | protected String bundle = null; |
| 40 | ||
| 41 | /** |
|
| 42 | * The key or value of the argument. |
|
| 43 | */ |
|
| 44 | 0 | protected String key = null; |
| 45 | ||
| 46 | /** |
|
| 47 | * The name dependency that this argument goes with (optional). |
|
| 48 | */ |
|
| 49 | 0 | protected String name = null; |
| 50 | ||
| 51 | /** |
|
| 52 | * Whether or not the key is a message resource (optional). Defaults to |
|
| 53 | * true. If it is 'true', the value will try to be resolved as a message |
|
| 54 | * resource. |
|
| 55 | * @since Validator 1.1.4 |
|
| 56 | */ |
|
| 57 | 0 | protected boolean resource = true; |
| 58 | ||
| 59 | /** |
|
| 60 | * Returns the resource bundle name. |
|
| 61 | * @return The bundle name. |
|
| 62 | * @since Validator 1.1 |
|
| 63 | */ |
|
| 64 | public String getBundle() { |
|
| 65 | 0 | return this.bundle; |
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Sets the resource bundle name. |
|
| 70 | * @param bundle The new bundle name. |
|
| 71 | * @since Validator 1.1 |
|
| 72 | */ |
|
| 73 | public void setBundle(String bundle) { |
|
| 74 | 0 | this.bundle = bundle; |
| 75 | 0 | } |
| 76 | ||
| 77 | /** |
|
| 78 | * Gets the name of the dependency. |
|
| 79 | * @return The dependency name. |
|
| 80 | */ |
|
| 81 | public String getName() { |
|
| 82 | 0 | return name; |
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * Sets the name of the dependency. |
|
| 87 | * @param name The dependency name. |
|
| 88 | */ |
|
| 89 | public void setName(String name) { |
|
| 90 | 0 | this.name = name; |
| 91 | 0 | } |
| 92 | ||
| 93 | /** |
|
| 94 | * Gets the key/value. |
|
| 95 | * @return The message key/value. |
|
| 96 | */ |
|
| 97 | public String getKey() { |
|
| 98 | 0 | return key; |
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * Sets the key/value. |
|
| 103 | * @param key The message key/value. |
|
| 104 | */ |
|
| 105 | public void setKey(String key) { |
|
| 106 | 0 | this.key = key; |
| 107 | 0 | } |
| 108 | ||
| 109 | /** |
|
| 110 | * Tests whether or not the key is a resource key or literal value. |
|
| 111 | * @return <code>true</code> if key is a resource key. |
|
| 112 | * @since Validator 1.1.4 |
|
| 113 | */ |
|
| 114 | public boolean isResource() { |
|
| 115 | 0 | return this.resource; |
| 116 | } |
|
| 117 | ||
| 118 | /** |
|
| 119 | * Sets whether or not the key is a resource. |
|
| 120 | * @param resource If true indicates the key is a resource. |
|
| 121 | * @since Validator 1.1.4 |
|
| 122 | */ |
|
| 123 | public void setResource(boolean resource) { |
|
| 124 | 0 | this.resource = resource; |
| 125 | 0 | } |
| 126 | ||
| 127 | /** |
|
| 128 | * Creates and returns a copy of this object. |
|
| 129 | * @return A copy of the Msg. |
|
| 130 | */ |
|
| 131 | public Object clone() { |
|
| 132 | try { |
|
| 133 | 0 | return super.clone(); |
| 134 | ||
| 135 | } catch(CloneNotSupportedException e) { |
|
| 136 | 0 | throw new RuntimeException(e.toString()); |
| 137 | } |
|
| 138 | } |
|
| 139 | ||
| 140 | /** |
|
| 141 | * Returns a string representation of the object. |
|
| 142 | * @return Msg String representation. |
|
| 143 | */ |
|
| 144 | public String toString() { |
|
| 145 | 0 | StringBuffer results = new StringBuffer(); |
| 146 | ||
| 147 | 0 | results.append("Msg: name="); |
| 148 | 0 | results.append(name); |
| 149 | 0 | results.append(" key="); |
| 150 | 0 | results.append(key); |
| 151 | 0 | results.append(" resource="); |
| 152 | 0 | results.append(resource); |
| 153 | 0 | results.append(" bundle="); |
| 154 | 0 | results.append(bundle); |
| 155 | 0 | results.append("\n"); |
| 156 | ||
| 157 | 0 | return results.toString(); |
| 158 | } |
|
| 159 | ||
| 160 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |