use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mvel.
the class TemplateTests method testMVEL244.
public void testMVEL244() {
Foo244 foo = new Foo244("plop");
String template = "@foreach{val : foo.liste[0].liste} plop @end{}";
CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(template);
Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", foo);
System.out.println(TemplateRuntime.execute(compiledTemplate, new ParserContext(), new MapVariableResolverFactory(model)));
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project jbpm by kiegroup.
the class RuleSetNodeInstance method processOutputs.
private void processOutputs(Map<String, Object> objects) {
RuleSetNode ruleSetNode = getRuleSetNode();
if (ruleSetNode != null) {
for (Iterator<DataAssociation> iterator = ruleSetNode.getOutAssociations().iterator(); iterator.hasNext(); ) {
DataAssociation association = iterator.next();
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), objects);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, association.getTarget());
if (variableScopeInstance != null && parameterValue != null) {
variableScopeInstance.setVariable(association.getTarget(), parameterValue);
} else {
logger.warn("Could not find variable scope for variable {}", association.getTarget());
logger.warn("Continuing without setting variable.");
}
if (parameterValue != null) {
variableScopeInstance.setVariable(association.getTarget(), parameterValue);
}
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, association.getTarget());
if (variableScopeInstance != null) {
Object value = objects.get(association.getSources().get(0));
if (value == null) {
try {
value = MVELSafeHelper.getEvaluator().eval(association.getSources().get(0), new MapVariableResolverFactory(objects));
} catch (Throwable t) {
// do nothing
}
}
Variable varDef = variableScopeInstance.getVariableScope().findVariable(association.getTarget());
DataType dataType = varDef.getType();
// exclude java.lang.Object as it is considered unknown type
if (!dataType.getStringType().endsWith("java.lang.Object") && value instanceof String) {
value = dataType.readValue((String) value);
}
variableScopeInstance.setVariable(association.getTarget(), value);
} else {
logger.warn("Could not find variable scope for variable {}", association.getTarget());
}
}
}
}
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mule by mulesoft.
the class MVELExpressionLanguageContextTestCase method testGetVariableResolverNextFactory.
@Test
public void testGetVariableResolverNextFactory() {
parserConfig.addImport(String.class);
MuleBaseVariableResolverFactory resoverFactory = new MVELExpressionLanguageContext(parserConfig, muleContext);
resoverFactory.setNextFactory(new MapVariableResolverFactory(Collections.singletonMap("foo", "val")));
assertNotNull(resoverFactory.getVariableResolver("foo"));
assertEquals("val", resoverFactory.getVariableResolver("foo").getValue());
assertNull(resoverFactory.getVariableResolver("bar"));
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.
the class ForNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
VariableResolverFactory ctxFactory = indexAlloc ? factory : new MapVariableResolverFactory(new HashMap<String, Object>(1), factory);
Object v;
for (initializer.getValue(ctx, thisValue, ctxFactory); (Boolean) condition.getValue(ctx, thisValue, ctxFactory); after.getValue(ctx, thisValue, ctxFactory)) {
v = compiledBlock.getValue(ctx, thisValue, ctxFactory);
if (ctxFactory.tiltFlag())
return v;
}
return null;
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.
the class CompiledForEachNode method eval.
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
Iterator[] iters = new Iterator[item.length];
Object o;
for (int i = 0; i < iters.length; i++) {
if ((o = MVEL.executeExpression(ce[i], ctx, factory)) instanceof Iterable) {
iters[i] = ((Iterable) o).iterator();
} else if (o instanceof Object[]) {
iters[i] = new ArrayIterator((Object[]) o);
} else if (o instanceof Integer) {
iters[i] = new CountIterator((Integer) o);
} else {
throw new TemplateRuntimeError("cannot iterate object type: " + o.getClass().getName());
}
}
Map<String, Object> locals = new HashMap<String, Object>();
MapVariableResolverFactory localFactory = new MapVariableResolverFactory(locals, factory);
int iterate = iters.length;
while (true) {
for (int i = 0; i < iters.length; i++) {
if (!iters[i].hasNext()) {
iterate--;
locals.put(item[i], "");
} else {
locals.put(item[i], iters[i].next());
}
}
if (iterate != 0) {
nestedNode.eval(runtime, appender, ctx, localFactory);
if (sepExpr != null) {
for (Iterator it : iters) {
if (it.hasNext()) {
appender.append(String.valueOf(MVEL.executeExpression(cSepExpr, ctx, factory)));
break;
}
}
}
} else
break;
}
return next != null ? next.eval(runtime, appender, ctx, factory) : null;
}
Aggregations