
org.openl.rules.project.instantiation.SimpleMultiModuleInstantiationStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.openl.rules.project Show documentation
Show all versions of org.openl.rules.project Show documentation
Classes and utilities to work with OpenL Rules Project
package org.openl.rules.project.instantiation;
import java.util.Collection;
import java.util.HashSet;
import org.openl.dependency.IDependencyManager;
import org.openl.rules.project.model.MethodFilter;
import org.openl.rules.project.model.Module;
import org.openl.rules.runtime.InterfaceClassGeneratorImpl;
import org.openl.rules.runtime.RulesEngineFactory;
import org.openl.runtime.AOpenLEngineFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The simplest way of multimodule instantiation strategy. There will be created
* virtual module that depends on each predefined module(means virtual module
* will have dependency for each module).
*
* @author PUdalau
*/
public class SimpleMultiModuleInstantiationStrategy extends MultiModuleInstantiationStartegy {
private final Logger log = LoggerFactory.getLogger(SimpleMultiModuleInstantiationStrategy.class);
private RulesEngineFactory> engineFactory;
public SimpleMultiModuleInstantiationStrategy(Collection modules,
IDependencyManager dependencyManager,
ClassLoader classLoader, boolean executionMode) {
super(modules, dependencyManager, classLoader, executionMode);
}
public SimpleMultiModuleInstantiationStrategy(Collection modules, IDependencyManager dependencyManager, boolean executionMode) {
super(modules, dependencyManager, executionMode);
}
public SimpleMultiModuleInstantiationStrategy(Collection modules, boolean executionMode) {
this(modules, null, executionMode);
}
@Override
public void reset() {
super.reset();
engineFactory = null;
}
@Override
public Class> getGeneratedRulesClass() throws RulesInstantiationException {
// Using project class loader for interface generation.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassLoader());
try {
return getEngineFactory().getInterfaceClass();
} catch (Exception e) {
throw new RulesInstantiationException("Can't resolve interface", e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@Override
public Object instantiate(Class> rulesClass) throws RulesInstantiationException {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassLoader());
try {
return getEngineFactory().newEngineInstance();
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@SuppressWarnings("unchecked")
protected RulesEngineFactory> getEngineFactory() {
Class> serviceClass = null;
try {
serviceClass = getServiceClass();
} catch (ClassNotFoundException e) {
log.debug("Failed to get service class.", e);
serviceClass = null;
}
if (engineFactory == null || (serviceClass != null && !engineFactory.getInterfaceClass().equals(serviceClass))) {
engineFactory = new RulesEngineFactory
© 2015 - 2025 Weber Informatics LLC | Privacy Policy