View Javadoc
1   package org.apache.fulcrum.intake.model;
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 javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAttribute;
27  import javax.xml.bind.annotation.XmlType;
28  import javax.xml.bind.annotation.XmlValue;
29  
30  import org.apache.fulcrum.intake.validator.Constraint;
31  
32  /**
33   * A Class for holding data about a constraint on a property.
34   *
35   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
36   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
37   * @version $Id$
38   */
39  @XmlType(name="rule")
40  @XmlAccessorType(XmlAccessType.NONE)
41  public class Rule implements Constraint, Serializable
42  {
43      /**
44       * Serial version id
45       */
46      private static final long serialVersionUID = -4059931768288150848L;
47  
48      @XmlAttribute(required=true)
49      private String name;
50  
51      @XmlAttribute(required=true)
52      private String value;
53  
54      @XmlValue
55      private String message;
56  
57      /**
58       * Get the name of the parameter
59       */
60      @Override
61      public String getName()
62      {
63          return name;
64      }
65  
66      /**
67       * Get the value of the parameter
68       */
69      @Override
70      public String getValue()
71      {
72          return value;
73      }
74  
75      /**
76       * Get the error message
77       */
78      @Override
79      public String getMessage()
80      {
81          return message;
82      }
83  
84      /**
85       * String representation of the column. This
86       * is an xml representation.
87       */
88      @Override
89      public String toString()
90      {
91          StringBuilder result = new StringBuilder(100);
92  
93          result.append("<rule name=\"").append(name).append("\"")
94              .append(" value=\"").append(value).append("\"");
95  
96          if (message == null)
97          {
98              result.append(" />\n");
99          }
100         else
101         {
102             result.append(">")
103                     .append(message)
104                     .append("</rule>\n");
105         }
106 
107         return result.toString();
108     }
109 }