/**
*
*/
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 ConfigWiredConditionFunctionExecutor implements MethodExecutor {
private String methodReference;
public ConfigWiredConditionFunctionExecutor(String methodReference) {
this.methodReference = methodReference;
}
public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {
Object obj = CoreServices.getMethodService().invoke(methodReference, 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: "
+ methodReference);
}
}