Search in sources :

Example 6 with IEntityIterator

use of org.whole.lang.iterators.IEntityIterator 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 7 with IEntityIterator

use of org.whole.lang.iterators.IEntityIterator in project whole by wholeplatform.

the class ActionCallIterator method initArguments.

protected void initArguments() {
    if (!useSelectedEntities) {
        IEntity selectedEntities = BindingManagerFactory.instance.createTuple();
        if (argsIterators != null && argsIterators.length > 0)
            for (IEntityIterator<?> argIterator : argsIterators) {
                argIterator.setBindings(getBindings());
                argIterator.reset(resetEntity);
                for (IEntity arg : argIterator) selectedEntities.wAdd(arg);
            }
        else
            selectedEntities.wAdd(resetEntity);
        getBindings().wDef("selectedEntities", selectedEntities);
        if (selectedEntities.wSize() > 0)
            getBindings().wDef("primarySelectedEntity", selectedEntities.wGet(0));
    }
    getBindings().wDef("self", resetEntity);
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityIterator(org.whole.lang.iterators.IEntityIterator)

Example 8 with IEntityIterator

use of org.whole.lang.iterators.IEntityIterator in project whole by wholeplatform.

the class ReusablesDynamicCompilerVisitor method visit.

@Override
public void visit(PathSegments entity) {
    int size = entity.wSize();
    if (size == 1)
        entity.get(0).accept(this);
    else {
        IEntityIterator<? extends IEntity>[] segmentIterators = new IEntityIterator<?>[size];
        for (int i = 0; i < size; i++) {
            entity.get(i).accept(this);
            segmentIterators[i] = getResultIterator();
        }
        setResultIterator(IteratorFactory.singleValuedRunnableIterator((IEntity selfEntity, IBindingManager bm, IEntity... arguments) -> {
            if (!BindingManagerFactory.instance.isVoid(selfEntity)) {
                StringBuilder sb = new StringBuilder();
                for (IEntity pathSegment : arguments) appendSegment(sb, pathSegment.wStringValue());
                bm.setResult(BindingManagerFactory.instance.createValue(sb.toString()));
            }
        }, segmentIterators).withSourceEntity(entity));
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IEntityIterator(org.whole.lang.iterators.IEntityIterator)

Aggregations

IEntityIterator (org.whole.lang.iterators.IEntityIterator)8 IEntity (org.whole.lang.model.IEntity)7 IBindingManager (org.whole.lang.bindings.IBindingManager)5 Expressions (org.whole.lang.workflows.model.Expressions)4 Variable (org.whole.lang.workflows.model.Variable)4 Method (java.lang.reflect.Method)2 InvokeJavaClassMethod (org.whole.lang.workflows.model.InvokeJavaClassMethod)2 InvokeJavaInstanceMethod (org.whole.lang.workflows.model.InvokeJavaInstanceMethod)2 Constructor (java.lang.reflect.Constructor)1 HashMap (java.util.HashMap)1 ActionCallIterator (org.whole.lang.actions.iterators.ActionCallIterator)1 SelectedEntities (org.whole.lang.actions.model.SelectedEntities)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 IfWithTemplate (org.whole.lang.queries.codebase.IfWithTemplate)1 IfWithTypeTest (org.whole.lang.queries.codebase.IfWithTypeTest)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1 MissingVariableException (org.whole.lang.visitors.MissingVariableException)1 Arguments (org.whole.lang.workflows.model.Arguments)1