1 package org.apache.turbine.services.intake.xmlmodel;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.Serializable;
20
21 import org.apache.turbine.services.intake.validator.Constraint;
22
23 import org.xml.sax.Attributes;
24
25 /***
26 * A Class for holding data about a constraint on a property.
27 *
28 * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
29 * @version $Id: Rule.java 278822 2005-09-05 19:53:05Z henning $
30 */
31 public class Rule
32 implements Constraint, Serializable
33 {
34 /*** Serial Version UID */
35 private static final long serialVersionUID = 3662886424992562964L;
36
37 private String name;
38 private String value;
39 private String message;
40 private XmlField parent;
41
42 /***
43 * Default Constructor
44 */
45 public Rule()
46 {
47 }
48
49 /***
50 * Imports a column from an XML specification
51 */
52 public void loadFromXML(Attributes attrib)
53 {
54 setName(attrib.getValue("name"));
55 setValue(attrib.getValue("value"));
56 }
57
58 /***
59 * Set the name of the parameter
60 */
61 public void setName(String newName)
62 {
63 name = newName;
64 }
65
66 /***
67 * Get the name of the parameter
68 */
69 public String getName()
70 {
71 return name;
72 }
73
74 /***
75 * Set the value of the parameter
76 */
77 public void setValue(String newValue)
78 {
79 value = newValue;
80 }
81
82 /***
83 * Get the value of the parameter
84 */
85 public String getValue()
86 {
87 return value;
88 }
89
90 /***
91 * Set the error message
92 */
93 public void setMessage(String newMessage)
94 {
95 message = newMessage;
96 }
97
98 /***
99 * Get the error message
100 */
101 public String getMessage()
102 {
103 return message;
104 }
105
106 /***
107 * Set the parent Field of the rule
108 */
109 public void setField(XmlField parent)
110 {
111 this.parent = parent;
112 }
113
114 /***
115 * Get the parent Field of the rule
116 */
117 public XmlField getField()
118 {
119 return parent;
120 }
121
122 /***
123 * String representation of the column. This
124 * is an xml representation.
125 */
126 public String toString()
127 {
128 StringBuffer result = new StringBuffer(100);
129
130 result.append("<rule name=\"" + name + "\"")
131 .append(" value=\"" + value + "\"");
132
133 if (message == null)
134 {
135 result.append(" />\n");
136 }
137 else
138 {
139 result.append(">")
140 .append(message)
141 .append("</rule>\n");
142 }
143
144 return result.toString();
145 }
146
147 }
148
149
150