KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > intake > xmlmodel > Rule


1 package org.apache.turbine.services.intake.xmlmodel;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.Serializable JavaDoc;
20
21 import org.apache.turbine.services.intake.validator.Constraint;
22
23 import org.xml.sax.Attributes JavaDoc;
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,v 1.5.2.2 2004/05/20 03:06:49 seade Exp $
30  */

31 public class Rule
32         implements Constraint, Serializable JavaDoc
33 {
34     private String JavaDoc name;
35     private String JavaDoc value;
36     private String JavaDoc message;
37     private XmlField parent;
38
39     /**
40      * Default Constructor
41      */

42     public Rule()
43     {
44     }
45
46     /**
47      * Imports a column from an XML specification
48      */

49     public void loadFromXML(Attributes JavaDoc attrib)
50     {
51         setName(attrib.getValue("name"));
52         setValue(attrib.getValue("value"));
53     }
54
55     /**
56      * Set the name of the parameter
57      */

58     public void setName(String JavaDoc newName)
59     {
60         name = newName;
61     }
62
63     /**
64      * Get the name of the parameter
65      */

66     public String JavaDoc getName()
67     {
68         return name;
69     }
70
71     /**
72      * Set the value of the parameter
73      */

74     public void setValue(String JavaDoc newValue)
75     {
76         value = newValue;
77     }
78
79     /**
80      * Get the value of the parameter
81      */

82     public String JavaDoc getValue()
83     {
84         return value;
85     }
86
87     /**
88      * Set the error message
89      */

90     public void setMessage(String JavaDoc newMessage)
91     {
92         message = newMessage;
93     }
94
95     /**
96      * Get the error message
97      */

98     public String JavaDoc getMessage()
99     {
100         return message;
101     }
102
103     /**
104      * Set the parent Field of the rule
105      */

106     public void setField(XmlField parent)
107     {
108         this.parent = parent;
109     }
110
111     /**
112      * Get the parent Field of the rule
113      */

114     public XmlField getField()
115     {
116         return parent;
117     }
118
119     /**
120      * String representation of the column. This
121      * is an xml representation.
122      */

123     public String JavaDoc toString()
124     {
125         StringBuffer JavaDoc result = new StringBuffer JavaDoc(100);
126
127         result.append("<rule name=\"" + name + "\"")
128                 .append(" value=\"" + value + "\"");
129
130         if (message == null)
131         {
132             result.append(" />\n");
133         }
134         else
135         {
136             result.append(">")
137                     .append(message)
138                     .append("</rule>\n");
139         }
140
141         return result.toString();
142     }
143
144 }
145
146
147
148
Popular Tags