View Javadoc

1   /*
2    * Created on 29-mar-2006
3    *
4    */
5   package org.state4j.sm.executors;
6   
7   import java.util.LinkedList;
8   import java.util.List;
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.state4j.exceptions.LogicErrorException;
12  import org.state4j.sm.SmContext;
13  import org.state4j.sm.SmExecutor;
14  
15  
16  public class SmChainExecutorImpl implements SmExecutor {
17  	private static Log logger = LogFactory.getLog(SmChainExecutorImpl.class);
18  	private List<SmExecutor> smExecutors;
19  
20      public void execute(SmContext cntx) {
21      	List<SmExecutor> list = new LinkedList<SmExecutor>(this.getSmExecutors());
22      	try {
23          	
24          	for(int i = 0; i < list.size(); i++) {
25          		list.get(i).execute(cntx);
26          	}
27          } catch (Exception e) {
28          	logger.error("error executing action ", e);
29              throw new LogicErrorException("error executing action" + e.getMessage(), e);
30          }
31      }
32  
33      public boolean hasSmExecutors() {
34          return smExecutors != null;
35      }
36  
37      public List<SmExecutor> getSmExecutors() {
38          if (!hasSmExecutors()) {
39              throw new LogicErrorException("Sorry!! cannot get smExecutors");
40          }
41          return this.smExecutors;
42      }
43  
44      public void setSmExecutors(List<SmExecutor> smExecutors) {
45          this.smExecutors = smExecutors;
46      }
47  }