KickJava   Java API By Example, From Geeks To Geeks.

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


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

20 public class GlobalWrapper implements State {
21   private ExecContainer _pre = new ExecContainer();
22   private ExecContainer _post = new ExecContainer();
23   private State _toExec;
24
25   /**
26    *
27    */

28   GlobalWrapper(State st) {
29     _toExec = st;
30   }
31
32   /**
33    * @see org.sapia.soto.state.State#getId()
34    */

35   public String JavaDoc getId() {
36     return _toExec.getId();
37   }
38
39   /**
40    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
41    */

42   public void execute(Result st) {
43     _pre.execute(st);
44
45     if (st.isError()) {
46       if (Debug.DEBUG) {
47         Debug.debug("Not executing: error");
48       }
49
50       return;
51     }
52
53     if (Debug.DEBUG) {
54       Debug.debug("Executing: " + _toExec.getId() + "(" +
55         _toExec.getClass().getName() + ")");
56     }
57
58     _toExec.execute(st);
59     _post.execute(st);
60   }
61
62   State getState() {
63     return _toExec;
64   }
65
66   void addPre(List JavaDoc pre) {
67     addExecs(_pre, pre);
68   }
69
70   void addPost(List JavaDoc post) {
71     addExecs(_post, post);
72   }
73
74   private static void addExecs(ExecContainer cont, List JavaDoc execs) {
75     for (int i = 0; i < execs.size(); i++) {
76       cont.addExecutable((Executable) execs.get(i));
77     }
78   }
79 }
80
Popular Tags