public static Object eval(String str, Map<String, Object> vars) { ParserConfiguration pconf = new ParserConfiguration(); pconf.addPackageImport("org.kie.internal.task.api.model"); pconf.addPackageImport("org.jbpm.services.task"); pconf.addPackageImport("org.jbpm.services.task.impl.model"); pconf.addPackageImport("org.jbpm.services.task.query"); pconf.addPackageImport("org.jbpm.services.task.internals.lifecycle"); pconf.addImport(Status.class); pconf.addImport(Allowed.class); pconf.addPackageImport("java.util"); ParserContext context = new ParserContext(pconf); Serializable s = MVEL.compileExpression(str.trim(), context); if (vars != null) { return MVELSafeHelper.getEvaluator().executeExpression(s, vars); } else { return MVELSafeHelper.getEvaluator().executeExpression(s); } }
public static Object eval(String str, Map<String, Object> vars) { ParserConfiguration pconf = new ParserConfiguration(); pconf.addPackageImport("org.jbpm.services.task"); // pconf.addPackageImport("org.jbpm.services.task.service"); pconf.addPackageImport("org.jbpm.services.task.query"); pconf.addPackageImport("java.util"); for(String entry : getInputs().keySet()){ pconf.addImport(entry, getInputs().get(entry)); } ParserContext context = new ParserContext(pconf); Serializable s = MVEL.compileExpression(str.trim(), context); if( vars != null ) { return MVELSafeHelper.getEvaluator().executeExpression(s, vars); } else { return MVELSafeHelper.getEvaluator().executeExpression(s); } } public static String toString(Reader reader) throws IOException {
@Override protected ParserConfiguration getParserConfiguration(InternalWorkingMemory workingMemory) { ParserConfiguration parserConfiguration = new ParserConfiguration(); parserConfiguration.addImport(Cheese.class); return parserConfiguration; }
/** * Adds a static import for the specified {@link MethodStub} with an alias. * * @param name The alias to use * @param method The instance of <tt>Method</tt> which represents the static import. * @see #addImport(String, org.mvel2.util.MethodStub) */ public void addImport(String name, MethodStub method) { parserConfiguration.addImport(name, method); }
/** * Adds a static import for the specified {@link MethodStub} with an alias. * * @param name The alias to use * @param method The instance of <tt>Method</tt> which represents the static import. * @see #addImport(String, org.mvel2.util.MethodStub) */ public void addImport(String name, MethodStub method) { parserConfiguration.addImport(name, method); }
/** * Adds a static import for the specified {@link MethodStub} with an alias. * * @param name The alias to use * @param method The instance of <tt>Method</tt> which represents the static import. * @see #addImport(String, org.mvel2.util.MethodStub) */ public void addImport(String name, MethodStub method) { parserConfiguration.addImport(name, method); }
public void addImport(String str, Method method) { this.imports.put( str, method ); if ( this.parserConfiguration != null ) { this.parserConfiguration.addImport( str, method ); } }
public void addImport(String str, Class cls) { this.imports.put( str, cls ); if ( this.parserConfiguration != null ) { this.parserConfiguration.addImport( str, cls ); } }
public void addImport(Class cls) { addImport(cls.getSimpleName(), cls); }
public void addImport(String name, Method method) { addImport(name, new MethodStub(method)); }
public void addImport(String name, Method method) { addImport(name, new MethodStub(method)); }
private ParserConfiguration getParserConfiguration() { ParserConfiguration parserConfig = new ParserConfiguration(); parserConfig.addPackageImport("java.util"); parserConfig.addPackageImport("org.apache.commons.lang3"); parserConfig.addPackageImport("org.joda.time"); parserConfig.addImport(Math.class); if (imports != null) { for (String imported : imports) parserConfig.addPackageImport(imported); } return parserConfig; }
public void testMathCeilWithDoubleCast() { String str = "Math.ceil( (double) x / 3 )"; ParserConfiguration pconf = new ParserConfiguration(); pconf.addImport("Math", Math.class); ParserContext pctx = new ParserContext(pconf); pctx.setStrongTyping(true); pctx.addInput("x", Integer.class); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx); Map vars = new HashMap(); vars.put("x", 4); assertEquals(Math.ceil((double) 4 / 3), MVEL.executeExpression(stmt, vars)); } }
public void testEmptyConstructorWithSpace() throws Exception { ParserConfiguration pconf = new ParserConfiguration(); pconf.addImport("getString", StaticClassWithStaticMethod.class.getMethod("getString", null)); String text = "getString( )"; ParserContext pctx = new ParserContext(pconf); pctx.setStrongTyping(true); pctx.setStrictTypeEnforcement(true); MVEL.compileExpression(text, pctx); }
public void testMathCeil() { String str = "Math.ceil( x/3 ) == 2"; ParserConfiguration pconf = new ParserConfiguration(); pconf.addImport("Math", Math.class); ParserContext pctx = new ParserContext(pconf); pctx.setStrongTyping(true); pctx.addInput("x", int.class); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx); Map vars = new HashMap(); vars.put("x", 4); Boolean result = (Boolean) MVEL.executeExpression(stmt, vars); assertTrue(result); }
public void testStaticMethodInvocation() { ParserConfiguration conf = new ParserConfiguration(); conf.addImport(ARef.class); conf.addImport(BRef.class); ParserContext pctx = new ParserContext( conf ); pctx.setStrictTypeEnforcement(true); pctx.setStrongTyping(true); pctx.addInput("value", String.class); Map vars = new HashMap() {{ put("value", "1234"); }}; assertEquals(0, MVEL.executeExpression(MVEL.compileExpression("ARef.getSize(value)", pctx), vars)); assertEquals(4, MVEL.executeExpression(MVEL.compileExpression("BRef.getSize(value)", pctx), vars)); }
public void testFloat() { ParserConfiguration conf = new ParserConfiguration(); conf.addImport( FactWithFloat.class ); ParserContext pctx = new ParserContext( conf ); pctx.setStrictTypeEnforcement(true); pctx.setStrongTyping(true); pctx.addInput("this", FactWithFloat.class); boolean result = ( Boolean ) MVEL.executeExpression(MVEL.compileExpression("floatObjectValue == 15.1", pctx), new FactWithFloat(15.1f)); assertTrue( result ); } }
public void testInstanceofOnInnerClass() { ParserConfiguration conf = new ParserConfiguration(); conf.addImport(ARef.class); ParserContext pctx = new ParserContext( conf ); pctx.setStrictTypeEnforcement(true); pctx.setStrongTyping(true); pctx.addInput("value", Object.class); Map vars = new HashMap() {{ put("value", new ARef()); }}; assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof ARef", pctx), vars)); assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + ARef.class.getCanonicalName(), pctx), vars)); }
public void testFloatPrimitive() { ParserConfiguration conf = new ParserConfiguration(); conf.addImport( FactWithFloat.class ); ParserContext pctx = new ParserContext( conf ); pctx.setStrictTypeEnforcement(true); pctx.setStrongTyping(true); pctx.addInput("this", FactWithFloat.class); boolean result = ( Boolean ) MVEL.executeExpression(MVEL.compileExpression("floatValue == 15.1", pctx), new FactWithFloat(15.1f)); assertTrue( result ); }
public void testInvokeVarargConstructor() { ParserConfiguration conf = new ParserConfiguration(); conf.addImport( Thingy.class ); ParserContext pctx = new ParserContext( conf ); pctx.setStrictTypeEnforcement(true); pctx.setStrongTyping(true); pctx.addInput("name", String.class); Map vars = new HashMap() {{ put("name", "test"); }}; Thingy result = (Thingy) MVEL.executeExpression(MVEL.compileExpression("new Thingy(name)", pctx), vars); assertEquals( "test", result.getName() ); }