Refine search
public void generateTemplates(final String ruleTemplate, final String invokerTemplate, final ProcessBuildContext context, final String className, final Map vars, final Object invokerLookup, final BaseDescr descrLookup) { TemplateRegistry registry = getRuleTemplateRegistry(); context.getMethods().add((String) TemplateRuntime.execute(registry.getNamedTemplate(ruleTemplate), null, new MapVariableResolverFactory(vars), registry) ); registry = getInvokerTemplateRegistry(); final String invokerClassName = context.getPkg().getName() + "." + context.getProcessDescr().getClassName() + StringUtils.ucFirst(className) + "Invoker"; context.getInvokers().put(invokerClassName, (String)TemplateRuntime.execute(registry.getNamedTemplate(invokerTemplate), null, new MapVariableResolverFactory(vars), registry) ); context.addInvokerLookup(invokerClassName, invokerLookup); context.addDescrLookups(invokerClassName, descrLookup); }
public VariableResolver getIndexedVariableResolver(int index) { if (indexedVariableNames == null) return null; if (indexedVariableResolvers[index] == null) { /** * If the register is null, this means we need to forward-allocate the variable onto the * register table. */ return indexedVariableResolvers[index] = super.getVariableResolver(indexedVariableNames[index]); } return indexedVariableResolvers[index]; }
public void testMVEL225() { Serializable compileExpression = MVEL.compileExpression( "def f() { int a=1;a++;return a; }; f();"); MapVariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>()); assertEquals(2, MVEL.executeExpression(compileExpression, factory)); }
public static Object eval(String template, Map vars) { return execute(compileTemplate(template), null, new MapVariableResolverFactory(vars)); }
public void testFunctionReuse() { VariableResolverFactory functionFactory = new MapVariableResolverFactory(); MVEL.eval("def foo() { \"foo\"; }; def bar() { \"bar\" };", functionFactory); VariableResolverFactory myVarFactory = new MapVariableResolverFactory(); myVarFactory.setNextFactory(functionFactory); Serializable s = MVEL.compileExpression("foo() + bar();"); assertEquals("foobar", MVEL.executeExpression(s, myVarFactory)); }
public String getExternalBeansMiningRules() { if (!templateRegistry.contains("ExternalBeansMiningRules")) { InputStream istrm = AbstractModel.class.getResourceAsStream("/org/kie/pmml/pmml_4_2/templates/mvel/global/externalBeanInput.mvel"); if (istrm != null) { CompiledTemplate ct = TemplateCompiler.compileTemplate(istrm); templateRegistry.addNamedTemplate("ExternalBeansMiningRules", ct); } } Map<String, Object> vars = new HashMap<>(); vars.put("externalBeanRefs", externalMiningFields); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { TemplateRuntime.execute(templateRegistry.getNamedTemplate("ExternalBeansMiningRules"), null, new MapVariableResolverFactory(vars), baos); } catch (TemplateError te) { return null; } return new String(baos.toByteArray()); }
MapVariableResolverFactory rootResolverFactory = new MapVariableResolverFactory(variableMap); MapVariableResolverFactory contextVariableResolverFactory = new MapVariableResolverFactory((Map<?, ?>) contextObject); rootResolverFactory.setNextFactory(contextVariableResolverFactory); rootResolverFactory.createVariable(MVEL_VARIABLES_VARIABLE_NAME, new MVELVariables(rootResolverFactory)); return DataConversion.convert(MVEL.executeExpression(compiled, rootResolverFactory), toType); } else { return MVEL.executeExpression(compiled, rootResolverFactory); return DataConversion.convert(MVEL.executeExpression(compiled, contextObject, new MapVariableResolverFactory(variableMap)), toType); } else { return MVEL.executeExpression(compiled, contextObject, new MapVariableResolverFactory(variableMap));
/** * {@inheritDoc} */ @Override public Object run(Map<String, Object> variables) { if (variables == null) { variables = new HashMap<String, Object>(); } VariableResolverFactory factory = new MapVariableResolverFactory(variables, _propertyResolverFactory); return isCompiled() ? MVEL.executeExpression(_compiled, factory) : MVEL.eval(_expression, factory); }
public Integer execute(String columnValue, Map<String, Object> extension) { Map<String, Object> vrs = new HashMap<String, Object>(); //, Map<String, ElFunction<?,?>> functionMap //vrs.putAll(functionMap);// 拓展函数 Map<String, Object> params = new HashMap<String, Object>(); params.put("value", columnValue); vrs.put("$ROOT", params); VariableResolverFactory vrfactory = new MapVariableResolverFactory(vrs); return MVEL.eval(expression, params, vrfactory, Integer.class); }
public static void executeExpression(Iterable<CompiledExpression> compiledExpression, Object ctx, Map vars) { executeExpression(compiledExpression, ctx, new MapVariableResolverFactory(vars)); }
public String generateFieldMapperGenerator(TypeOracle oracle, JField targetWidget, JType targetType, JField targeEntityMember, JField targetEntityField) { InputStream istream = this.getClass().getResourceAsStream("CheckBoxFMGenerator.mv"); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("typeOracle", oracle); vars.put("targetWidget", targetWidget); vars.put("targetType", targetType); vars.put("fieldType", targeEntityMember); vars.put("fieldName", targetEntityField.getName()); return (String) TemplateRuntime.eval(istream, null, new MapVariableResolverFactory(vars), null); }
if (value == null) { try { value = MVELSafeHelper.getEvaluator().eval(association.getSources().get(0), new MapVariableResolverFactory(objects)); } catch (Throwable t) {
/** * Evaluate a script from a file with injected variables and return the resultant value. * * @param file The file to process * @param vars Variables to be injected * @return The resultant value * @throws IOException Exception thrown if there is an IO problem accessing the file. */ public static Object evalFile(File file, Map<String, Object> vars) throws IOException { return _evalFile(file, null, new MapVariableResolverFactory(vars)); }
public VariableResolver createVariable(String name, Object value) { VariableResolver vr; try { (vr = getVariableResolver(name)).setValue(value); return vr; } catch (UnresolveablePropertyException e) { addResolver(name, vr = new MapVariableResolver(variables, name)).setValue(value); return vr; } }
public VariableResolver createVariable(String name, Object value, Class<?> type) { if (indexedVariableNames == null) return super.createVariable(name, value, type); VariableResolver vr; boolean newVar = false; try { int idx; if ((idx = variableIndexOf(name)) != -1) { vr = new SimpleValueResolver(value); if (indexedVariableResolvers[idx] == null) { indexedVariableResolvers[idx] = vr; } variableResolvers.put(indexedVariableNames[idx], vr); vr = indexedVariableResolvers[idx]; newVar = true; } else { return super.createVariable(name, value, type); } } catch (UnresolveablePropertyException e) { vr = null; } if (!newVar && vr != null && vr.getType() != null) { throw new RuntimeException("variable already defined within scope: " + vr.getType() + " " + name); } else { addResolver(name, vr = new MapVariableResolver(variables, name, type)).setValue(value); return vr; } }
public void testReflectiveOptimizerWorksFine() { OptimizerFactory.setDefaultOptimizer("reflective"); Serializable compileExpression = MVEL.compileExpression( biglistTestScript ); VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap()); int actual = (Integer) executeExpression(compileExpression, factory); assertEquals( actual, 25); }
public static void eval(String template, Object ctx, Map vars, OutputStream stream) { execute(compileTemplate(template), ctx, new MapVariableResolverFactory(vars), null, stream); }
public Map.Entry<String, String> getTreeNodeJava() { Map<String,String> result = new HashMap<>(); if (!templateRegistry.contains(TREE_NODE_POJO_TEMPLATE_NAME)) { InputStream istrm = Treemodel.class.getResourceAsStream(TREE_NODE_POJO_TEMPLATE); if (istrm != null) { CompiledTemplate ct = TemplateCompiler.compileTemplate(istrm); templateRegistry.addNamedTemplate(TREE_NODE_POJO_TEMPLATE_NAME,ct); } } Map<String,Object> vars = new HashMap<>(); vars.put("pmmlPackageName", PMML_JAVA_PACKAGE_NAME); vars.put("outcomeType",getOutputFieldType()); vars.put("context", this.getModelId()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { TemplateRuntime.execute( templateRegistry.getNamedTemplate(TREE_NODE_POJO_TEMPLATE_NAME), null, new MapVariableResolverFactory(vars), baos ); } catch (TemplateRuntimeError tre) { // need to figure out logging here return null; } String fullName = PMML_JAVA_PACKAGE_NAME+"."+this.getModelId()+"TreeNode"; result.put(fullName, new String(baos.toByteArray())); if (!result.isEmpty()) return result.entrySet().iterator().next(); return null; }
MapVariableResolverFactory rootResolverFactory = new MapVariableResolverFactory(variableMap); MapVariableResolverFactory contextVariableResolverFactory = new MapVariableResolverFactory((Map<?, ?>) contextObject); rootResolverFactory.setNextFactory(contextVariableResolverFactory); rootResolverFactory.createVariable(MVEL_VARIABLES_VARIABLE_NAME, new MVELVariables(rootResolverFactory)); return DataConversion.convert(MVEL.executeExpression(compiled, rootResolverFactory), toType); } else { return MVEL.executeExpression(compiled, rootResolverFactory); return DataConversion.convert(MVEL.executeExpression(compiled, contextObject, new MapVariableResolverFactory(variableMap)), toType); } else { return MVEL.executeExpression(compiled, contextObject, new MapVariableResolverFactory(variableMap));
/** * {@inheritDoc} */ @Override public Object run(Map<String, Object> variables) { if (variables == null) { variables = new HashMap<String, Object>(); } VariableResolverFactory factory = new MapVariableResolverFactory(variables, _propertyResolverFactory); return isCompiled() ? MVEL.executeExpression(_compiled, factory) : MVEL.eval(_expression, factory); }