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 ; 10 import java.util.List ; 11 12 13 21 public class StateSet implements ObjectHandlerIF { 22 private List _includes; 23 private List _excludes; 24 private List _steps = new ArrayList (); 25 26 public StateSet() { 27 } 28 29 public StatePattern createInclude() { 30 if (_includes == null) { 31 _includes = new ArrayList (); 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 (); 43 } 44 45 StatePattern sp = new StatePattern(); 46 _excludes.add(sp); 47 48 return sp; 49 } 50 51 public List 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 84 public void handleObject(String name, Object obj) 85 throws ConfigurationException { 86 if (obj instanceof Step) { 87 _steps.add(obj); 88 } 89 } 90 91 private static boolean matches(State s, List 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 |