001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.validator; 018 019import java.io.Serializable; 020 021/** 022 * An alternative message can be associated with a <code>Field</code> 023 * and a pluggable validator instead of using the default message 024 * stored in the <code>ValidatorAction</code> (aka pluggable validator). 025 * Instances of this class are configured with a <msg> xml element. 026 * 027 * @version $Revision: 1227719 $ $Date: 2012-01-05 12:45:51 -0500 (Thu, 05 Jan 2012) $ 028 */ 029public class Msg implements Cloneable, Serializable { 030 031 private static final long serialVersionUID = 5690015734364127124L; 032 033 /** 034 * The resource bundle name that this Msg's <code>key</code> should be 035 * resolved in (optional). 036 * @since Validator 1.1 037 */ 038 protected String bundle = null; 039 040 /** 041 * The key or value of the argument. 042 */ 043 protected String key = null; 044 045 /** 046 * The name dependency that this argument goes with (optional). 047 */ 048 protected String name = null; 049 050 /** 051 * Whether or not the key is a message resource (optional). Defaults to 052 * true. If it is 'true', the value will try to be resolved as a message 053 * resource. 054 * @since Validator 1.1.4 055 */ 056 protected boolean resource = true; 057 058 /** 059 * Returns the resource bundle name. 060 * @return The bundle name. 061 * @since Validator 1.1 062 */ 063 public String getBundle() { 064 return this.bundle; 065 } 066 067 /** 068 * Sets the resource bundle name. 069 * @param bundle The new bundle name. 070 * @since Validator 1.1 071 */ 072 public void setBundle(String bundle) { 073 this.bundle = bundle; 074 } 075 076 /** 077 * Gets the name of the dependency. 078 * @return The dependency name. 079 */ 080 public String getName() { 081 return name; 082 } 083 084 /** 085 * Sets the name of the dependency. 086 * @param name The dependency name. 087 */ 088 public void setName(String name) { 089 this.name = name; 090 } 091 092 /** 093 * Gets the key/value. 094 * @return The message key/value. 095 */ 096 public String getKey() { 097 return key; 098 } 099 100 /** 101 * Sets the key/value. 102 * @param key The message key/value. 103 */ 104 public void setKey(String key) { 105 this.key = key; 106 } 107 108 /** 109 * Tests whether or not the key is a resource key or literal value. 110 * @return <code>true</code> if key is a resource key. 111 * @since Validator 1.1.4 112 */ 113 public boolean isResource() { 114 return this.resource; 115 } 116 117 /** 118 * Sets whether or not the key is a resource. 119 * @param resource If true indicates the key is a resource. 120 * @since Validator 1.1.4 121 */ 122 public void setResource(boolean resource) { 123 this.resource = resource; 124 } 125 126 /** 127 * Creates and returns a copy of this object. 128 * @return A copy of the Msg. 129 */ 130 public Object clone() { 131 try { 132 return super.clone(); 133 134 } catch(CloneNotSupportedException e) { 135 throw new RuntimeException(e.toString()); 136 } 137 } 138 139 /** 140 * Returns a string representation of the object. 141 * @return Msg String representation. 142 */ 143 public String toString() { 144 StringBuffer results = new StringBuffer(); 145 146 results.append("Msg: name="); 147 results.append(name); 148 results.append(" key="); 149 results.append(key); 150 results.append(" resource="); 151 results.append(resource); 152 results.append(" bundle="); 153 results.append(bundle); 154 results.append("\n"); 155 156 return results.toString(); 157 } 158 159}