Package org.jibeframework.core.app.condition

Source Code of org.jibeframework.core.app.condition.ConfigWiredConditionFunctionExecutor

/**
*
*/
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);
  }
}
TOP

Related Classes of org.jibeframework.core.app.condition.ConfigWiredConditionFunctionExecutor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.