use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.
the class CaseConfigurationDeploymentListener method getEventListenerFromDescriptor.
protected List<CaseEventListener> getEventListenerFromDescriptor(InternalRuntimeManager runtimeManager) {
List<CaseEventListener> listeners = new ArrayList<CaseEventListener>();
DeploymentDescriptor descriptor = runtimeManager.getDeploymentDescriptor();
if (descriptor != null) {
Map<String, Object> params = getParametersMap(runtimeManager);
for (ObjectModel model : descriptor.getEventListeners()) {
ObjectModelResolver resolver = ObjectModelResolverProvider.get(model.getResolver());
if (resolver == null) {
logger.warn("Unable to find ObjectModelResolver for {}", model.getResolver());
continue;
}
try {
Object listenerInstance = resolver.getInstance(model, runtimeManager.getEnvironment().getClassLoader(), params);
if (listenerInstance != null && CaseEventListener.class.isAssignableFrom(listenerInstance.getClass())) {
listeners.add((CaseEventListener) listenerInstance);
} else {
// close/cleanup instance as it is not going to be used at the moment, except these that are cacheable
if (listenerInstance instanceof Closeable && !(listenerInstance instanceof Cacheable)) {
((Closeable) listenerInstance).close();
}
}
} catch (Exception e) {
logger.debug("Unable to build listener {}", model);
}
}
}
return listeners;
}
use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.
the class MVELObjectModelResolverTest method testSimpleStaticObjectModel.
@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());
}
use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.
the class ReflectionObjectModelResolverTest method testSimpleNotExistingObjectModel.
@Test(expected = IllegalArgumentException.class)
public void testSimpleNotExistingObjectModel() {
ObjectModel model = new ObjectModel("org.jbpm.runtime.manager.impl.deploy.testobject.NotExistingObject");
ObjectModelResolver resolver = new ReflectionObjectModelResolver();
resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
}
use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.
the class ReflectionObjectModelResolverTest method testSimpleSingleObjectArgObjectModel.
@Test
public void testSimpleSingleObjectArgObjectModel() {
ObjectModel model = new ObjectModel("org.jbpm.runtime.manager.impl.deploy.testobject.EmbedingCustomObject", new Object[] { new ObjectModel("org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject", new Object[] { "john" }), "testing object model" });
ObjectModelResolver resolver = new ReflectionObjectModelResolver();
Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
assertNotNull(result);
assertTrue(result instanceof EmbedingCustomObject);
assertEquals("testing object model", ((EmbedingCustomObject) result).getDescription());
SimpleCustomObject customObject = ((EmbedingCustomObject) result).getCustomObject();
assertNotNull(customObject);
assertEquals("john", customObject.getName());
}
use of org.kie.internal.runtime.conf.ObjectModelResolver in project jbpm by kiegroup.
the class ReflectionObjectModelResolverTest method testSimpleNoArgNamedObjectModel.
@Test
public void testSimpleNoArgNamedObjectModel() {
NamedObjectModel model = new NamedObjectModel("CustomObject", "org.jbpm.runtime.manager.impl.deploy.testobject.SimpleCustomObject");
assertEquals("CustomObject", model.getName());
ObjectModelResolver resolver = new ReflectionObjectModelResolver();
Object result = resolver.getInstance(model, this.getClass().getClassLoader(), new HashMap<String, Object>());
assertNotNull(result);
assertTrue(result instanceof SimpleCustomObject);
assertEquals("default", ((SimpleCustomObject) result).getName());
}
Aggregations