View Javadoc

1   package org.apache.turbine.services.intake.xmlmodel;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Serializable;
23  
24  import org.apache.turbine.services.intake.validator.Constraint;
25  
26  import org.xml.sax.Attributes;
27  
28  /***
29   * A Class for holding data about a constraint on a property.
30   *
31   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
32   * @version $Id: Rule.java 534527 2007-05-02 16:10:59Z tv $
33   */
34  public class Rule
35          implements Constraint, Serializable
36  {
37      /*** Serial Version UID */
38      private static final long serialVersionUID = 3662886424992562964L;
39  
40      private String name;
41      private String value;
42      private String message;
43      private XmlField parent;
44  
45      /***
46       * Default Constructor
47       */
48      public Rule()
49      {
50      }
51  
52      /***
53       * Imports a column from an XML specification
54       */
55      public void loadFromXML(Attributes attrib)
56      {
57          setName(attrib.getValue("name"));
58          setValue(attrib.getValue("value"));
59      }
60  
61      /***
62       * Set the name of the parameter
63       */
64      public void setName(String newName)
65      {
66          name = newName;
67      }
68  
69      /***
70       * Get the name of the parameter
71       */
72      public String getName()
73      {
74          return name;
75      }
76  
77      /***
78       * Set the value of the parameter
79       */
80      public void setValue(String newValue)
81      {
82          value = newValue;
83      }
84  
85      /***
86       * Get the value of the parameter
87       */
88      public String getValue()
89      {
90          return value;
91      }
92  
93      /***
94       * Set the error message
95       */
96      public void setMessage(String newMessage)
97      {
98          message = newMessage;
99      }
100 
101     /***
102      * Get the error message
103      */
104     public String getMessage()
105     {
106         return message;
107     }
108 
109     /***
110      * Set the parent Field of the rule
111      */
112     public void setField(XmlField parent)
113     {
114         this.parent = parent;
115     }
116 
117     /***
118      * Get the parent Field of the rule
119      */
120     public XmlField getField()
121     {
122         return parent;
123     }
124 
125     /***
126      * String representation of the column. This
127      * is an xml representation.
128      */
129     public String toString()
130     {
131         StringBuffer result = new StringBuffer(100);
132 
133         result.append("<rule name=\"" + name + "\"")
134                 .append(" value=\"" + value + "\"");
135 
136         if (message == null)
137         {
138             result.append(" />\n");
139         }
140         else
141         {
142             result.append(">")
143                     .append(message)
144                     .append("</rule>\n");
145         }
146 
147         return result.toString();
148     }
149 
150 }
151 
152 
153