use of org.whole.lang.workflows.model.Expressions 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));
}
use of org.whole.lang.workflows.model.Expressions 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();
}
use of org.whole.lang.workflows.model.Expressions in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
@Override
public void visit(CreateEntity entity) {
try {
entity.getEntityName().accept(this);
String typeName = getResultString();
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(typeName);
if (ed == null)
throw new WholeIllegalArgumentException("The requested entity does not exist: " + typeName).withSourceEntity(entity).withBindings(getBindings());
IEntityRegistryProvider provider = null;
switch(entity.getRegistry().getValue().getOrdinal()) {
case RegistryEnum.DEFAULT_ord:
provider = RegistryConfigurations.DEFAULT;
break;
case RegistryEnum.RESOLVER_ord:
provider = RegistryConfigurations.RESOLVER;
break;
case RegistryEnum.ADAPTER_ord:
provider = RegistryConfigurations.ADAPTER;
break;
case RegistryEnum.STRICT_ord:
provider = RegistryConfigurations.STRICT;
break;
case RegistryEnum.CUSTOM_ord:
provider = RegistryConfigurations.CUSTOM;
break;
}
IEntityFactory ef = GenericEntityFactory.instance(provider);
IEntity model;
Arguments arguments = entity.getArguments();
if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
arguments.accept(this);
for (int i = 0; i < arguments.wSize(); i++) {
String name = ((Assignments) arguments).get(i).getName().getValue();
FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(name);
if (fd != null)
getBindings().wDef(name, EntityUtils.convertCloneIfReparenting(getBindings().wGet(name), ed.getEntityFeatureDescriptor(fd)));
}
model = ef.create(ed, getBindings());
resettableScope.rollback();
getBindings().wExitScope();
} else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
IEntity selfEntity = getBindings().wGet("self");
if (ed.getEntityKind().isData()) {
((Expressions) arguments).get(0).accept(this);
model = DataTypeUtils.convertCloneIfParented(getResult(), ed);
resetSelfEntity(selfEntity);
} else {
IEntity[] values = new IEntity[arguments.wSize()];
for (int i = 0; i < values.length; i++) {
((Expressions) arguments).get(i).accept(this);
values[i] = EntityUtils.convertCloneIfReparenting(getResult(), ed.getEntityFeatureDescriptor(i));
resetSelfEntity(selfEntity);
}
model = ef.create(ed, values);
}
} else
model = ef.create(ed);
setResult(entity.getModel(), model);
} catch (Exception e) {
throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
}
}
use of org.whole.lang.workflows.model.Expressions in project whole by wholeplatform.
the class WorkflowsDynamicCompilerVisitor method visit.
// FIXME add compilation of Assignments before fixing
// @Override
// public void visit(CreateEntity entity) {
// final Variable resultVariable = entity.getModel();
//
// entity.getEntityName().accept(this);
// final String typeName = getResult().wStringValue();
//
// IEntityRegistryProvider provider = null;
// switch (entity.getRegistry().getValue().getOrdinal()) {
// case RegistryEnum.DEFAULT_ord:
// provider = RegistryConfigurations.DEFAULT;
// break;
// case RegistryEnum.RESOLVER_ord:
// provider = RegistryConfigurations.RESOLVER;
// break;
// case RegistryEnum.ADAPTER_ord:
// provider = RegistryConfigurations.ADAPTER;
// break;
// case RegistryEnum.STRICT_ord:
// provider = RegistryConfigurations.STRICT;
// break;
// case RegistryEnum.CUSTOM_ord:
// provider = RegistryConfigurations.CUSTOM;
// break;
// }
// final IEntityFactory ef = GenericEntityFactory.instance(provider);
//
// final Arguments arguments = entity.getArguments();
// int size = arguments.wSize();
// IEntityIterator<?>[] runnableIterators = new IEntityIterator<?>[size];
//
// if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
// for (int i=0; i<size; i++) {
// Assign argument = ((Assignments) arguments).get(i);
// String name = argument.getName().getValue();
// argument.getExpression().accept(this);
// runnableIterators[i] = getResultIterator();//FIXME
// }
// } else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
// for (int i=0; i<size; i++) {
// ((Expressions) arguments).get(i).accept(this);
// runnableIterators[i] = getResultIterator();
// }
// }
//
// setResultIterator(IteratorFactory.multiValuedRunnableIterator(new AbstractWorkflowsRunnable() {
// public void run(IEntity selfEntity, IBindingManager bm, IEntity... argsEntities) {
// EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(typeName);
// if (ed == null)
// throw new IllegalArgumentException("The requested entity does not exist: "+typeName);
//
// IEntity resultValue;
// if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
// ResettableScope resettableScope = BindingManagerFactory.instance.createResettableScope();
// bm.wEnterScope(resettableScope);
//
// //FIXME
// for (int i = 0; i < arguments.wSize(); i++) {
// String name = ((Assignments) arguments).get(i).getName().getValue();
// bm.wSet(name, EntityUtils.convert(bm.wGet(name), ed.getEntityDescriptor(i)));
// }
// resultValue = ef.create(ed, bm);
//
// resettableScope.reset();
// bm.wExitScope();
// } else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
// if (ed.getEntityKind().isData())
// resultValue = DataTypeUtils.convert(argsEntities[0], ed);
// else {
// IEntity[] values = new IEntity[argsEntities.length];
// for (int i = 0; i < values.length; i++)
// values[i] = EntityUtils.convert(argsEntities[i], ed.getEntityDescriptor(i));
// resultValue = ef.create(ed, values);
// }
// } else
// resultValue = ef.create(ed);
//
// setResult(bm, resultVariable, resultValue);
// }
// }, runnableIterators).withDomainEntity(entity));
// }
@Override
public void visit(CreateJavaClassInstance 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.getConstructor().accept(this);
runnableIterators[1] = getResultIterator();
for (int i = 0; i < size; i++) {
arguments.get(i).accept(this);
runnableIterators[2 + i] = getResultIterator();
}
setResultIterator(IteratorFactory.singleValuedRunnableIterator(new AbstractWorkflowsRunnable() {
public void run(IEntity selfEntity, IBindingManager bm, IEntity... argsEntities) {
String className = argsEntities[0].wStringValue();
IEntity constructorData = argsEntities[1];
Constructor<?> constructor;
if (DataTypeUtils.getDataKind(constructorData).isString())
constructor = JavaReflectUtils.getConstructor(className, constructorData.wStringValue(), ReflectionFactory.getClassLoader(bm));
else
constructor = (Constructor<?>) constructorData.wGetValue();
Object[] arguments = toArguments(constructor.getParameterTypes(), constructor.isVarArgs(), argsEntities);
Object resultValue = JavaReflectUtils.invokeConstructor(constructor, arguments);
setResult(bm, resultVariable, resultValue, constructor.getDeclaringClass());
}
}, runnableIterators).withSourceEntity(entity));
}
use of org.whole.lang.workflows.model.Expressions 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));
}
Aggregations