KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > validator > RuleSet


1 package org.sapia.validator;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.sapia.util.xml.confix.ConfigurationException;
7 import org.sapia.util.xml.confix.ObjectHandlerIF;
8
9 /**
10  * This class models a set of rules
11  *
12  * @author Yanick Duchesne
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class RuleSet implements Validatable, ObjectHandlerIF {
20   private List JavaDoc _rules = new ArrayList JavaDoc();
21   private String JavaDoc _id;
22   private boolean _stop;
23
24   /**
25    * Constructor for RuleSet.
26    */

27   public RuleSet() {
28     super();
29   }
30
31   /**
32    * Sets this instance's identifier.
33    *
34    * @param an identifier, as a string.
35    */

36   public void setId(String JavaDoc id) {
37     _id = id;
38   }
39
40   /**
41    * @see Validatable#getId()
42    */

43   public String JavaDoc getId() {
44     return _id;
45   }
46
47   /**
48    * Adds a <code>Validatable</code> to this instance.
49    *
50    * @param v a <code>Validatable</code> instance.
51    */

52   public void addValidatable(Validatable v) {
53     _rules.add(v);
54   }
55
56   /**
57    * Adds a rule set to this instance and returns it.
58    *
59    * @return a <code>RuleSet</code> instance.
60    */

61   public RuleSet createRuleSet() {
62     RuleSet set = new RuleSet();
63
64     _rules.add(set);
65
66     return set;
67   }
68
69   /**
70    * @see CompositeRule#setStop(boolean)
71    */

72   public void setStop(boolean stop) {
73     _stop = stop;
74   }
75
76   /**
77    * @see org.sapia.validator.Validatable#validate(ValidationContext)
78    */

79   public final void validate(ValidationContext ctx) {
80     Validatable current;
81
82     for (int i = 0; i < _rules.size(); i++) {
83       current = (Validatable) _rules.get(i);
84
85       current.validate(ctx);
86
87       if (ctx.getStatus().isError() && _stop) {
88         break;
89       }
90     }
91   }
92
93   /**
94    * @see org.sapia.util.xml.confix.ObjectHandlerIF#handleObject(String, Object)
95    */

96   public void handleObject(String JavaDoc name, Object JavaDoc validatable)
97     throws ConfigurationException {
98     if (validatable instanceof Validatable) {
99       addValidatable((Validatable) validatable);
100     } else {
101       throw new ConfigurationException("Unexpected element: " + name);
102     }
103   }
104 }
105
Popular Tags