Search in sources :

Example 1 with InvokeJavaInstanceMethod

use of org.whole.lang.workflows.model.InvokeJavaInstanceMethod in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(InvokeJavaInstanceMethod entity) {
    try {
        entity.getClassName().accept(this);
        String className = getResultString();
        entity.getMethod().accept(this);
        IEntity methodData = getResult();
        Method method;
        if (DataTypeUtils.getDataKind(methodData).isString())
            method = JavaReflectUtils.getMethod(className, methodData.wStringValue(), ReflectionFactory.getClassLoader(getBindings()));
        else
            method = (Method) methodData.wGetValue();
        Object[] arguments = toArguments(method.getParameterTypes(), method.isVarArgs(), entity.getArguments());
        Variable object = entity.getObject();
        Object instance = unbox(method.getDeclaringClass(), object, false);
        Object resultValue = JavaReflectUtils.invokeMethod(instance, method, arguments);
        setResult(entity.getResult(), resultValue, method.getReturnType());
    } catch (Exception e) {
        throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
    }
}
Also used : Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) InvokeJavaClassMethod(org.whole.lang.workflows.model.InvokeJavaClassMethod) InvokeJavaInstanceMethod(org.whole.lang.workflows.model.InvokeJavaInstanceMethod) Method(java.lang.reflect.Method) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Example 2 with InvokeJavaInstanceMethod

use of org.whole.lang.workflows.model.InvokeJavaInstanceMethod in project whole by wholeplatform.

the class WorkflowsDynamicCompilerVisitor method visit.

@Override
public void visit(InvokeJavaInstanceMethod entity) {
    final Variable resultVariable = entity.getResult();
    final Variable instanceVariable = entity.getObject();
    Expressions arguments = entity.getArguments();
    int size = arguments.wSize();
    IEntityIterator<?>[] runnableIterators = new IEntityIterator<?>[2 + size];
    entity.getClassName().accept(this);
    runnableIterators[0] = getResultIterator();
    entity.getMethod().accept(this);
    runnableIterators[1] = getResultIterator();
    for (int i = 0; i < size; i++) {
        arguments.get(i).accept(this);
        runnableIterators[2 + i] = getResultIterator();
    }
    setResultIterator(IteratorFactory.multiValuedRunnableIterator(new AbstractWorkflowsRunnable() {

        public void run(IEntity selfEntity, IBindingManager bm, IEntity... argsEntities) {
            String className = argsEntities[0].wStringValue();
            IEntity methodData = argsEntities[1];
            Method method;
            if (DataTypeUtils.getDataKind(methodData).isString())
                method = JavaReflectUtils.getMethod(className, methodData.wStringValue(), ReflectionFactory.getClassLoader(bm));
            else
                method = (Method) methodData.wGetValue();
            IEntity instanceEntity = bm.wGet(instanceVariable.getValue());
            if (instanceEntity == null)
                throw new MissingVariableException(instanceVariable.getValue()).withSourceEntity(getSourceEntity()).withBindings(getBindings());
            Object instance = DataTypeUtils.unbox(instanceEntity, method.getDeclaringClass(), false);
            Object[] arguments = toArguments(method.getParameterTypes(), method.isVarArgs(), argsEntities);
            Object resultValue = JavaReflectUtils.invokeMethod(instance, method, arguments);
            setResult(bm, resultVariable, resultValue, method.getReturnType());
        }
    }, runnableIterators).withSourceEntity(entity));
}
Also used : Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Expressions(org.whole.lang.workflows.model.Expressions) InvokeJavaClassMethod(org.whole.lang.workflows.model.InvokeJavaClassMethod) InvokeJavaInstanceMethod(org.whole.lang.workflows.model.InvokeJavaInstanceMethod) Method(java.lang.reflect.Method) IEntityIterator(org.whole.lang.iterators.IEntityIterator) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 3 with InvokeJavaInstanceMethod

use of org.whole.lang.workflows.model.InvokeJavaInstanceMethod in project whole by wholeplatform.

the class InvokeJavaInstanceMethodPart method refreshVisuals.

@Override
protected void refreshVisuals() {
    InvokeJavaInstanceMethod entity = getModelEntity();
    Expression e = entity.getMethod();
    String name = Matcher.matchImpl(WorkflowsEntityDescriptorEnum.StringLiteral, e) ? e.wStringValue() : "?";
    int endIndex = name.indexOf('(');
    if (endIndex > 0)
        name = name.substring(0, endIndex);
    getFigure().setMethodName(name);
    super.refreshVisuals();
}
Also used : Expression(org.whole.lang.workflows.model.Expression) InvokeJavaInstanceMethod(org.whole.lang.workflows.model.InvokeJavaInstanceMethod)

Example 4 with InvokeJavaInstanceMethod

use of org.whole.lang.workflows.model.InvokeJavaInstanceMethod in project whole by wholeplatform.

the class InvokeJavaInstanceMethodPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    InvokeJavaInstanceMethod entity = getModelEntity();
    List<IEntity> children = new ArrayList<IEntity>(7);
    children.add(entity.getLabel());
    children.add(entity.getClassName());
    children.add(entity.getMethod());
    // children.add(entity.getTypeArguments());
    children.add(entity.getObject());
    children.add(entity.getArguments());
    children.add(entity.getResult());
    return children;
}
Also used : IEntity(org.whole.lang.model.IEntity) InvokeJavaInstanceMethod(org.whole.lang.workflows.model.InvokeJavaInstanceMethod) ArrayList(java.util.ArrayList)

Aggregations

InvokeJavaInstanceMethod (org.whole.lang.workflows.model.InvokeJavaInstanceMethod)4 IEntity (org.whole.lang.model.IEntity)3 Method (java.lang.reflect.Method)2 MissingVariableException (org.whole.lang.visitors.MissingVariableException)2 InvokeJavaClassMethod (org.whole.lang.workflows.model.InvokeJavaClassMethod)2 Variable (org.whole.lang.workflows.model.Variable)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)1 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)1 IEntityIterator (org.whole.lang.iterators.IEntityIterator)1 ParseException (org.whole.lang.parsers.ParseException)1 VisitException (org.whole.lang.visitors.VisitException)1 Expression (org.whole.lang.workflows.model.Expression)1 Expressions (org.whole.lang.workflows.model.Expressions)1