use of org.drools.compiler.builder.DroolsAssemblerContext in project drools by kiegroup.
the class DialectUtil method findClassByName.
public static Class<?> findClassByName(RuleBuildContext context, String className) {
if (className == null) {
return null;
}
String namespace = context.getRuleDescr().getNamespace();
DroolsAssemblerContext packageBuilder = context.getKnowledgeBuilder();
Class<?> clazz = null;
try {
clazz = Class.forName(className.indexOf('.') < 0 ? namespace + "." + className : className, false, packageBuilder.getRootClassLoader());
} catch (ClassNotFoundException e) {
}
if (clazz != null) {
return clazz;
}
Set<String> imports = new HashSet<>();
List<PackageDescr> pkgDescrs = packageBuilder.getPackageDescrs(namespace);
if (pkgDescrs == null) {
return null;
}
for (PackageDescr pkgDescr : pkgDescrs) {
for (ImportDescr importDescr : pkgDescr.getImports()) {
imports.add(importDescr.getTarget());
}
}
return findClass(className, imports, packageBuilder.getRootClassLoader());
}
use of org.drools.compiler.builder.DroolsAssemblerContext in project drools by kiegroup.
the class PatternBuilder method getTypeDeclaration.
private TypeDeclaration getTypeDeclaration(RuleBuildContext context, Class<?> userProvidedClass) {
String packageName = ClassUtils.getPackage(userProvidedClass);
DroolsAssemblerContext kbuilder = context.getKnowledgeBuilder();
PackageRegistry pkgr = kbuilder.getPackageRegistry(packageName);
TypeDeclaration typeDeclaration = pkgr != null ? pkgr.getPackage().getTypeDeclaration(userProvidedClass) : null;
if (typeDeclaration == null && kbuilder.getKnowledgeBase() != null) {
// check if the type declaration is contained only in the already existing kbase (possible during incremental compilation)
InternalKnowledgePackage pkg = kbuilder.getKnowledgeBase().getPackage(packageName);
typeDeclaration = pkg != null ? pkg.getTypeDeclaration(userProvidedClass) : null;
}
if (typeDeclaration == null) {
typeDeclaration = context.getPkg().getTypeDeclaration(userProvidedClass);
}
return typeDeclaration;
}
Aggregations