View Javadoc

1   /*
2    * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java,v 1.12.2.2 2004/11/11 15:32:03 niallp Exp $
3    * $Revision: 1.12.2.2 $
4    * $Date: 2004/11/11 15:32:03 $
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   * 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 &lt;msg&gt; xml element.
31   */
32  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      protected String bundle = null;
40  
41      /***
42       * The key or value of the argument.
43       */
44      protected String key = null;
45  
46      /***
47       * The name dependency that this argument goes with (optional).
48       */
49      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      protected boolean resource = true;
58  
59      /***
60       * Returns the resource bundle name.
61       * @since Validator 1.1
62       */
63      public String getBundle() {
64          return this.bundle;
65      }
66  
67      /***
68       * Sets the resource bundle name.
69       * @param bundle The new bundle name.
70       * @since Validator 1.1
71       */
72      public void setBundle(String bundle) {
73          this.bundle = bundle;
74      }
75  
76      /***
77       * Gets the name of the dependency.
78       */
79      public String getName() {
80          return name;
81      }
82  
83      /***
84       * Sets the name of the dependency.
85       */
86      public void setName(String name) {
87          this.name = name;
88      }
89  
90      /***
91       * Gets the key/value.
92       */
93      public String getKey() {
94          return key;
95      }
96  
97      /***
98       * Sets the key/value.
99       */
100     public void setKey(String key) {
101         this.key = key;
102     }
103 
104     /***
105      * Tests whether or not the key is a resource key or literal value.
106      * @return <code>true</code> if key is a resource key.
107      * @since Validator 1.1.4
108      */
109     public boolean isResource() {
110         return this.resource;
111     }
112 
113     /***
114      * Sets whether or not the key is a resource.
115      * @param resource If true indicates the key is a resource.
116      * @since Validator 1.1.4
117      */
118     public void setResource(boolean resource) {
119         this.resource = resource;
120     }
121 
122     /***
123      * Creates and returns a copy of this object.
124      */
125     public Object clone() {
126         try {
127             return super.clone();
128 
129         } catch(CloneNotSupportedException e) {
130             throw new RuntimeException(e.toString());
131         }
132     }
133 
134     /***
135      * Returns a string representation of the object.
136      */
137     public String toString() {
138         StringBuffer results = new StringBuffer();
139 
140         results.append("Msg: name=");
141         results.append(name);
142         results.append("  key=");
143         results.append(key);
144         results.append("  resource=");
145         results.append(resource);
146         results.append("  bundle=");
147         results.append(bundle);
148         results.append("\n");
149 
150         return results.toString();
151     }
152 
153 }