use of org.kie.internal.runtime.conf.DeploymentDescriptor 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.DeploymentDescriptor in project jbpm by kiegroup.
the class RuntimeEnvironmentBuilder method getDefault.
/**
* Provides default configuration of <code>RuntimeEnvironmentBuilder</code> that is based on:
* <ul>
* <li>DefaultRuntimeEnvironment</li>
* </ul>
* This one is tailored to works smoothly with kjars as the notion of kbase and ksessions
* @param releaseId <code>ReleaseId</code> that described the kjar
* @param kbaseName name of the kbase defined in kmodule.xml stored in kjar
* @param ksessionName name of the ksession define in kmodule.xml stored in kjar
* @return new instance of <code>RuntimeEnvironmentBuilder</code> that is already preconfigured with defaults
*
* @see DefaultRuntimeEnvironment
*/
public static RuntimeEnvironmentBuilder getDefault(ReleaseId releaseId, String kbaseName, String ksessionName) {
KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
repository.resolveArtifact(releaseId.toExternalForm());
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = ks.newKieContainer(releaseId);
DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager();
List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
DeploymentDescriptorMerger merger = new DeploymentDescriptorMerger();
DeploymentDescriptor descriptor = merger.merge(descriptorHierarchy, MergeMode.MERGE_COLLECTIONS);
if (StringUtils.isEmpty(kbaseName)) {
KieBaseModel defaultKBaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
if (defaultKBaseModel != null) {
kbaseName = defaultKBaseModel.getName();
} else {
kbaseName = DEFAULT_KBASE_NAME;
}
}
InternalKieModule module = (InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase(kbaseName);
if (module == null) {
throw new IllegalStateException("Cannot find kbase, either it does not exist or there are multiple default kbases in kmodule.xml");
}
KieBase kbase = kieContainer.getKieBase(kbaseName);
RuntimeEnvironmentBuilder builder = null;
if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
builder = getDefaultInMemory();
} else {
builder = getDefault();
}
Map<String, Object> contaxtParams = new HashMap<String, Object>();
contaxtParams.put("classLoader", kieContainer.getClassLoader());
// populate various properties of the builder
if (descriptor.getPersistenceUnit() != null) {
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
builder.entityManagerFactory(emf);
contaxtParams.put("entityManagerFactory", emf);
}
// process object models that are globally configured (environment entries, session configuration)
for (NamedObjectModel model : descriptor.getEnvironmentEntries()) {
Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
builder.addEnvironmentEntry(model.getName(), entry);
}
for (NamedObjectModel model : descriptor.getConfiguration()) {
Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
builder.addConfiguration(model.getName(), (String) entry);
}
ObjectMarshallingStrategy[] mStrategies = new ObjectMarshallingStrategy[descriptor.getMarshallingStrategies().size() + 1];
int index = 0;
for (ObjectModel model : descriptor.getMarshallingStrategies()) {
Object strategy = getInstanceFromModel(model, kieContainer, contaxtParams);
mStrategies[index] = (ObjectMarshallingStrategy) strategy;
index++;
}
// lastly add the main default strategy
mStrategies[index] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
builder.addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, mStrategies);
builder.addEnvironmentEntry("KieDeploymentDescriptor", descriptor).knowledgeBase(kbase).classLoader(kieContainer.getClassLoader()).registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
return builder;
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class DeploymentDescriptorIO method toXml.
/**
* Serializes descriptor instance to XML
* @param descriptor descriptor to be serialized
* @return xml representation of descriptor as string
*/
public static String toXml(DeploymentDescriptor descriptor) {
try {
Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.jboss.org/jbpm deployment-descriptor.xsd");
marshaller.setSchema(schema);
StringWriter stringWriter = new StringWriter();
// clone the object and cleanup transients
DeploymentDescriptor clone = ((DeploymentDescriptorImpl) descriptor).clearClone();
marshaller.marshal(clone, stringWriter);
String output = stringWriter.toString();
return output;
} catch (Exception e) {
throw new RuntimeException("Unable to generate xml from deployment descriptor", e);
}
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class DefaultRegisterableItemsFactory method getEventListenerFromDescriptor.
@SuppressWarnings("unchecked")
protected <T> List<T> getEventListenerFromDescriptor(RuntimeEngine runtime, Class<T> type) {
List<T> listeners = new ArrayList<T>();
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
if (descriptor != null) {
Map<String, Object> params = getParametersMap(runtime);
for (ObjectModel model : descriptor.getEventListeners()) {
Object listenerInstance = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
if (listenerInstance != null && type.isAssignableFrom(listenerInstance.getClass())) {
listeners.add((T) 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();
}
}
}
}
return listeners;
}
use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.
the class DefaultRegisterableItemsFactory method getTaskListenersFromDescriptor.
protected List<TaskLifeCycleEventListener> getTaskListenersFromDescriptor() {
List<TaskLifeCycleEventListener> defaultListeners = new ArrayList<TaskLifeCycleEventListener>();
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
if (descriptor != null) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("runtimeManager", getRuntimeManager());
params.put("classLoader", getRuntimeManager().getEnvironment().getClassLoader());
params.put("kieContainer", getRuntimeManager().getKieContainer());
for (ObjectModel model : descriptor.getTaskEventListeners()) {
Object taskListener = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
if (taskListener != null) {
defaultListeners.add((TaskLifeCycleEventListener) taskListener);
}
}
}
return defaultListeners;
}
Aggregations