![JAR search and dependency download from the Maven repository](/logo.png)
brainslug.flow.execution.node.task.CallDefinitionExecutor Maven / Gradle / Ivy
The newest version!
package brainslug.flow.execution.node.task;
import brainslug.flow.builder.ServiceCallInvocationSupport;
import brainslug.flow.context.ExecutionContext;
import brainslug.flow.expression.Value;
import brainslug.flow.expression.Property;
import brainslug.flow.node.task.CallDefinition;
import brainslug.flow.node.task.HandlerCallDefinition;
import brainslug.flow.node.task.InvokeDefinition;
import brainslug.flow.node.task.Task;
import brainslug.util.Option;
import brainslug.util.ReflectionUtil;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class CallDefinitionExecutor {
public Object execute(CallDefinition callDefinition, ExecutionContext execution) {
if (callDefinition instanceof HandlerCallDefinition) {
final Object callee = ((HandlerCallDefinition) callDefinition).getCallee();
return executeDelegate(callee, execution);
} else if (callDefinition instanceof InvokeDefinition) {
return invokeMethod((InvokeDefinition) callDefinition, execution);
}
throw new IllegalArgumentException("unable to execute call: " + callDefinition);
}
protected Object invokeMethod(InvokeDefinition method, ExecutionContext context) {
Class> targetClass = method.getTargetClass();
Object serviceInstance = context.service(targetClass);
return invokeMethodWithArguments(method.getMethod(), serviceInstance, getArguments(method, context));
}
protected Object invokeMethodWithArguments(Method serviceMethod, Object serviceInstance, Object[] arguments) {
try {
return serviceMethod.invoke(serviceInstance, arguments);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
protected Object[] getArguments(CallDefinition callDefinition, ExecutionContext executionContext) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy