View Javadoc

1   /*
2    * Created on 29-mar-2006
3    *
4    */
5   package org.state4j.sm.evaluators;
6   
7   import org.state4j.exceptions.LogicErrorException;
8   import org.state4j.sm.SmContext;
9   import org.state4j.sm.SmEvaluator;
10  
11  
12  public class SmReflectionEvaluatorImpl implements SmEvaluator {
13      private String methodName;
14  
15      public boolean hasMethodName() {
16          return methodName != null;
17      }
18  
19      public String getMethodName() {
20          if (!hasMethodName()) {
21              throw new RuntimeException("this.methodName is null and can't be returned");
22          }
23          return this.methodName;
24      }
25  
26      public void setMethodName(String methodName) {
27          this.methodName = methodName;
28      }
29  
30  	public boolean evaluate(SmContext cntx) {
31          try {
32              return (Boolean)cntx.getClass().getMethod(methodName).invoke(cntx);
33          } catch (Exception e) {
34              throw new LogicErrorException("Invocation failed: " + e.getMessage());
35          }
36  	}
37  }