MVELObjectModelResolver implements ObjectModelResolver { @Override public Object getInstance(ObjectModel model, ClassLoader cl, Map<String, Object> contextParams) { Object instance = null; InternalRuntimeManager manager = null; if (contextParams.containsKey("runtimeManager")) { manager = (InternalRuntimeManager) contextParams.get("runtimeManager"); instance = manager.getCacheManager().get(model.getIdentifier()); if (instance != null) { return instance; } } ParserConfiguration config = new ParserConfiguration(); config.setClassLoader(cl); ParserContext ctx = new ParserContext(config); if (contextParams != null) { for (Map.Entry<String, Object> entry : contextParams.entrySet()) { ctx.addVariable(entry.getKey(), entry.getValue().getClass()); } } Object compiledExpression = MVEL.compileExpression(model.getIdentifier(), ctx); instance = MVELSafeHelper.getEvaluator().executeExpression( compiledExpression, contextParams ); if (manager != null && instance instanceof Cacheable) { manager.getCacheManager().add(model.getIdentifier(), instance); } return instance; }  @Override Object getInstance(ObjectModel model, ClassLoader cl, Map<String, Object> contextParams); @Override boolean accept(String resolverId); static final String ID; }
@Test public void testSimpleNoArgObjectModel() { ObjectModel model = new ObjectModel("new org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject()"); ObjectModelResolver resolver = new MVELObjectModelResolver(); Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>()); assertNotNull(result); assertTrue(result instanceof SimpleCustomObject); assertEquals("default", ((SimpleCustomObject) result).getName()); }
@Test public void testSimpleStaticObjectModel() { ObjectModel model = new ObjectModel("Integer.parseInt(\"10\")"); ObjectModelResolver resolver = new MVELObjectModelResolver(); Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>()); assertNotNull(result); assertTrue(result instanceof Integer); assertEquals(10, ((Integer) result).intValue()); }
@Test public void testComplexStaticObjectModel() { ObjectModel model = new ObjectModel("String.valueOf(10).substring(1)"); ObjectModelResolver resolver = new MVELObjectModelResolver(); Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>()); assertNotNull(result); assertTrue(result instanceof String); assertEquals("0", ((String) result)); }