1
2
3
4
5 package org.state4j.sm.executors;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.state4j.exceptions.LogicErrorException;
10 import org.state4j.sm.SmContext;
11 import org.state4j.sm.SmExecutor;
12
13
14 public class SmReflectionExecutorImpl implements SmExecutor {
15 private static Log logger = LogFactory.getLog(SmReflectionExecutorImpl.class);
16 private String methodName;
17
18 public void execute(SmContext cntx) {
19 try {
20 cntx.getClass().getMethod(this.getMethodName()).invoke(cntx);
21 } catch (Exception e) {
22 logger.error("error executing method " + this.methodName, e);
23 throw new LogicErrorException("Invocation method " + this.methodName + " failed: " + e.getMessage());
24 }
25 }
26
27 public boolean hasMethodName() {
28 return methodName != null;
29 }
30
31 public String getMethodName() {
32 if (!hasMethodName()) {
33 throw new LogicErrorException("this.methodName is null and can't be returned");
34 }
35 return this.methodName;
36 }
37
38 public void setMethodName(String methodName) {
39 this.methodName = methodName;
40 }
41 }