/**
*
*/
package org.jibeframework.core.app.condition;
import org.jibeframework.core.JibeRuntimeException;
import org.jibeframework.core.service.CoreServices;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.MethodExecutor;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.support.BooleanTypedValue;
public class AnnotatedConditionFunctionExecutor implements MethodExecutor {
private String evalMethod;
public AnnotatedConditionFunctionExecutor(String evalMethod) {
this.evalMethod = evalMethod;
}
public TypedValue execute(EvaluationContext context, Object target, Object... arguments)
throws AccessException {
Object obj = CoreServices.getMethodService().invoke(
org.jibeframework.core.annotation.ConditionFunction.class, evalMethod, arguments);
if (obj instanceof Boolean) {
Boolean result = (Boolean) obj;
return result ? BooleanTypedValue.TRUE : BooleanTypedValue.FALSE;
}
throw new JibeRuntimeException("Condition evaluation methods has to have Boolean return value: "
+ evalMethod);
}
}