use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderImpl method compileAndLoadClass.
/**
* Compile the given sources and add them to given <code>Classloader</code> of the current instance.
* Returns the <code>Class</code> with the given <b>fullClassName</b>
* @param sourcesMap
* @param fullClassName
* @return
*/
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader, JavaConfiguration.CompilerType.ECLIPSE);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderMock method compileAndLoadClass.
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderMock method compileAndLoadClass.
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderMock method compileAndLoadClass.
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class InstancesHashcodedTest method build.
/*
<dimension name="bck_cycle_dm" item-expression="cycleDimension"
mode="ignore" cache="10" export-to="cycle_id">
<id name="objid" type="long" generator-sql="select bck_dimensions_uid.nextval from dual"/>
<field name="cut_date" type="java.util.Date" value="cutDate" key="true"/>
<field name="due_date" type="java.util.Date" value="dueDate" key="true"/>
<field name="cycle_code" type="java.lang.String" value="cycleCode"/>
<field name="issue_date" type="java.util.Date" value="issueDate"/>
</dimension>
*/
private Class build(ClassBuilder builder, ClassDefinition classDef) throws Exception {
ProjectClassLoader prjClassLoader = ProjectClassLoader.createProjectClassLoader();
byte[] d = builder.buildClass(classDef, prjClassLoader);
JavaDialectRuntimeData data = new JavaDialectRuntimeData();
data.write(convertClassToResourcePath(classDef.getClassName()), d);
ClassLoader classLoader = new PackageClassLoader(data.getStore(), prjClassLoader);
ClassFieldAccessorStore store = new ClassFieldAccessorStore();
store.setClassFieldAccessorCache(new ClassFieldAccessorCache(classLoader));
store.setEagerWire(true);
Class clazz = classLoader.loadClass(classDef.getClassName());
classDef.setDefinedClass(clazz);
return clazz;
}
Aggregations