KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > config > StateSet


1 package org.sapia.soto.state.config;
2
3 import org.sapia.soto.state.State;
4 import org.sapia.soto.state.Step;
5
6 import org.sapia.util.xml.confix.ConfigurationException;
7 import org.sapia.util.xml.confix.ObjectHandlerIF;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.List JavaDoc;
11
12
13 /**
14  * @author Yanick Duchesne
15  * <dl>
16  * <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>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class StateSet implements ObjectHandlerIF {
22   private List JavaDoc _includes;
23   private List JavaDoc _excludes;
24   private List JavaDoc _steps = new ArrayList JavaDoc();
25
26   public StateSet() {
27   }
28
29   public StatePattern createInclude() {
30     if (_includes == null) {
31       _includes = new ArrayList JavaDoc();
32     }
33
34     StatePattern sp = new StatePattern();
35     _includes.add(sp);
36
37     return sp;
38   }
39
40   public StatePattern createExclude() {
41     if (_excludes == null) {
42       _excludes = new ArrayList JavaDoc();
43     }
44
45     StatePattern sp = new StatePattern();
46     _excludes.add(sp);
47
48     return sp;
49   }
50
51   public List JavaDoc getSteps() {
52     return _steps;
53   }
54
55   public boolean matches(State st) {
56     if (_includes != null) {
57       if (matches(st, _includes)) {
58         if (_excludes != null) {
59           return !matches(st, _excludes);
60         }
61
62         return true;
63       }
64
65       return false;
66     } else {
67       if (_excludes != null) {
68         if (matches(st, _excludes)) {
69           return false;
70         }
71       }
72
73       return true;
74     }
75   }
76
77   public void addStep(Step step) {
78     _steps.add(step);
79   }
80
81   /**
82    * @see org.sapia.util.xml.confix.ObjectHandlerIF#handleObject(java.lang.String, java.lang.Object)
83    */

84   public void handleObject(String JavaDoc name, Object JavaDoc obj)
85     throws ConfigurationException {
86     if (obj instanceof Step) {
87       _steps.add(obj);
88     }
89   }
90
91   private static boolean matches(State s, List JavaDoc patterns) {
92     for (int i = 0; i < patterns.size(); i++) {
93       if (((StatePattern) patterns.get(i)).matches(s.getId())) {
94         return true;
95       }
96     }
97
98     return false;
99   }
100 }
101
Popular Tags