001 package org.apache.fulcrum.intake.xmlmodel;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.io.Serializable;
023
024 import org.apache.fulcrum.intake.validator.Constraint;
025
026 import org.xml.sax.Attributes;
027
028 /**
029 * A Class for holding data about a constraint on a property.
030 *
031 * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
032 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
033 * @version $Id: Rule.java 670328 2008-06-22 09:34:11Z tv $
034 */
035 public class Rule
036 implements Constraint, Serializable
037 {
038 /**
039 * Serial version id
040 */
041 private static final long serialVersionUID = -4059931768288150848L;
042
043 private String name;
044 private String value;
045 private String message;
046 private XmlField parent;
047
048 /**
049 * Default Constructor
050 */
051 public Rule()
052 {
053 //
054 }
055
056 /**
057 * Imports a column from an XML specification
058 */
059 public void loadFromXML(Attributes attrib)
060 {
061 setName(attrib.getValue("name"));
062 setValue(attrib.getValue("value"));
063 }
064
065 /**
066 * Set the name of the parameter
067 */
068 public void setName(String newName)
069 {
070 name = newName;
071 }
072
073 /**
074 * Get the name of the parameter
075 */
076 public String getName()
077 {
078 return name;
079 }
080
081 /**
082 * Set the value of the parameter
083 */
084 public void setValue(String newValue)
085 {
086 value = newValue;
087 }
088
089 /**
090 * Get the value of the parameter
091 */
092 public String getValue()
093 {
094 return value;
095 }
096
097 /**
098 * Set the error message
099 */
100 public void setMessage(String newMessage)
101 {
102 message = newMessage;
103 }
104
105 /**
106 * Get the error message
107 */
108 public String getMessage()
109 {
110 return message;
111 }
112
113 /**
114 * Set the parent Field of the rule
115 */
116 public void setField(XmlField parent)
117 {
118 this.parent = parent;
119 }
120
121 /**
122 * Get the parent Field of the rule
123 */
124 public XmlField getField()
125 {
126 return parent;
127 }
128
129 /**
130 * String representation of the column. This
131 * is an xml representation.
132 */
133 public String toString()
134 {
135 StringBuffer result = new StringBuffer(100);
136
137 result.append("<rule name=\"" + name + "\"")
138 .append(" value=\"" + value + "\"");
139
140 if (message == null)
141 {
142 result.append(" />\n");
143 }
144 else
145 {
146 result.append(">")
147 .append(message)
148 .append("</rule>\n");
149 }
150
151 return result.toString();
152 }
153
154 }
155
156
157