Search in sources :

Example 1 with Variable

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

the class WorkflowsDynamicCompilerVisitor method visit.

@Override
public void visit(InvokeJavaClassMethod entity) {
    final Variable resultVariable = entity.getResult();
    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();
            Object[] arguments = toArguments(method.getParameterTypes(), method.isVarArgs(), argsEntities);
            Object resultValue = JavaReflectUtils.invokeMethod(null, 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)

Example 2 with Variable

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

the class ChooseModelsDialog method open.

@Override
public int open() {
    int status = super.open();
    if (status == Dialog.OK) {
        WorkflowsEntityFactory wef = WorkflowsEntityFactory.instance;
        Tuple tuple = QueriesEntityFactory.instance.createTuple(0);
        for (Object element : getResult()) try {
            IEntity model = getPersistenceKit().readModel(new IFilePersistenceProvider((IFile) element));
            tuple.wAdd(createStageUpFragment(QueriesEntityDescriptorEnum.Expression, model));
        } catch (Exception e) {
        }
        Variable variable = wef.createVariable("selectedModels");
        Expression fragment = createSameStageFragment(Expression, tuple);
        Assign assign = wef.createAssign(variable, fragment);
        assignments.wAdd(assign);
    }
    return status;
}
Also used : WorkflowsEntityFactory(org.whole.lang.workflows.factories.WorkflowsEntityFactory) Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) Expression(org.whole.lang.workflows.model.Expression) Expression(org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.Expression) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) Assign(org.whole.lang.workflows.model.Assign) Tuple(org.whole.lang.queries.model.Tuple)

Example 3 with Variable

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

the class WorkflowsIDEInterpreterVisitor method visit.

@Override
public void visit(Task entity) {
    entity.getLabel().accept(this);
    String title = PrettyPrinterOperation.toPrettyPrintString(getResult());
    entity.getDescription().accept(this);
    String description = PrettyPrinterOperation.toPrettyPrintString(getResult());
    Assignments assignments = EntityUtils.clone(entity.getAssignments());
    Variable factoryVariable = entity.getFactory();
    ITaskDialogFactory factory;
    if (EntityUtils.isNotResolver(factoryVariable)) {
        factoryVariable.accept(this);
        factory = (ITaskDialogFactory) getResultValue();
    } else if (EntityUtils.isNotResolver(assignments)) {
        factory = AssignmentsDialogFactory.instance();
    } else
        factory = ConfirmationDialogFactory.instance();
    if (EntityUtils.isNotResolver(assignments)) {
        stagedVisit(assignments, 1);
        assignments = (Assignments) getResult();
    }
    if (!TaskDialogHelper.showTaskDialog(factory, title, description, assignments, getBindings()))
        throw new OperationCanceledException(new VisitException("task not completed: " + description));
    assignments.accept(this);
}
Also used : ITaskDialogFactory(org.whole.lang.workflows.ui.dialogs.ITaskDialogFactory) Variable(org.whole.lang.workflows.model.Variable) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) VisitException(org.whole.lang.visitors.VisitException) Assignments(org.whole.lang.workflows.model.Assignments)

Example 4 with Variable

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

the class WorkflowsInterpreterVisitor method afterWriteModel.

protected void afterWriteModel(SaveModel entity, IPersistenceProvider provider) throws Exception {
    if (getResourceKind(entity).wContainsValue(ResourceKindEnum.VARIABLE)) {
        String result = ((StringPersistenceProvider) provider).getStore();
        Variable variable = (Variable) entity.getResource();
        getBindings().wDefValue(variable.getValue(), result);
    }
}
Also used : Variable(org.whole.lang.workflows.model.Variable) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider)

Example 5 with Variable

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

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(InvokeQuery entity) {
    Variable queryName = entity.getQueryName();
    Arguments arguments = entity.getArguments();
    IEntityIterator<? extends IEntity>[] argsIterators = new IEntityIterator<?>[0];
    Set<String> filterNames = getOperation().getResultsScope().wNames();
    IBindingManager args = BindingManagerFactory.instance.createBindingManager(BindingManagerFactory.instance.createExcludeFilterScope(filterNames).wWithEnclosingScope(getBindings()), getBindings().wGetEnvironmentManager());
    if (!EntityUtils.isNotResolver(arguments)) {
        setResultValue(argsIterators);
        arguments.accept(this);
        argsIterators = (IEntityIterator<?>[]) getResultValue();
    } else if (Matcher.match(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
        IEntity selfEntity = getBindings().wGet("self");
        argsIterators = new IEntityIterator<?>[arguments.wSize()];
        for (int i = 0; i < argsIterators.length; i++) {
            ((Expressions) arguments).get(i).accept(this);
            argsIterators[i] = getResultIterator();
            setResultIterator(null);
            resetSelfEntity(selfEntity);
        }
    } else
        define(args, (Assignments) arguments);
    IEntityIterator<?> iterator = QueriesIteratorFactory.callIterator(queryName.getValue(), argsIterators);
    iterator.setBindings(args);
    resetIterator(iterator);
    while (iterator.hasNext()) iterator.next();
}
Also used : Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) Arguments(org.whole.lang.workflows.model.Arguments) IBindingManager(org.whole.lang.bindings.IBindingManager) Expressions(org.whole.lang.workflows.model.Expressions) IEntityIterator(org.whole.lang.iterators.IEntityIterator)

Aggregations

Variable (org.whole.lang.workflows.model.Variable)11 IEntity (org.whole.lang.model.IEntity)7 IBindingManager (org.whole.lang.bindings.IBindingManager)5 IEntityIterator (org.whole.lang.iterators.IEntityIterator)4 Expressions (org.whole.lang.workflows.model.Expressions)4 Method (java.lang.reflect.Method)3 MissingVariableException (org.whole.lang.visitors.MissingVariableException)3 VisitException (org.whole.lang.visitors.VisitException)3 InvokeJavaClassMethod (org.whole.lang.workflows.model.InvokeJavaClassMethod)3 InvokeJavaInstanceMethod (org.whole.lang.workflows.model.InvokeJavaInstanceMethod)3 IOException (java.io.IOException)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)2 ParseException (org.whole.lang.parsers.ParseException)2 Constructor (java.lang.reflect.Constructor)1 TreeSet (java.util.TreeSet)1 IArtifactsEntity (org.whole.lang.artifacts.model.IArtifactsEntity)1 Synchronize (org.whole.lang.artifacts.visitors.ArtifactsSynchronizerVisitor.Synchronize)1 Traverse (org.whole.lang.artifacts.visitors.ArtifactsSynchronizerVisitor.Traverse)1 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)1