use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method createPackageRegistry.
private PackageRegistry createPackageRegistry(PackageDescr packageDescr) {
initPackage(packageDescr);
InternalKnowledgePackage pkg;
if (this.kBase == null || (pkg = this.kBase.getPackage(packageDescr.getName())) == null) {
// there is no rulebase or it does not define this package so define it
pkg = new KnowledgePackageImpl(packageDescr.getName());
pkg.setClassFieldAccessorCache(new ClassFieldAccessorCache(this.rootClassLoader));
// if there is a rulebase then add the package.
if (this.kBase != null) {
try {
pkg = (InternalKnowledgePackage) this.kBase.addPackage(pkg).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
} else {
// the RuleBase will also initialise the
pkg.getDialectRuntimeRegistry().onAdd(this.rootClassLoader);
}
}
PackageRegistry pkgRegistry = new PackageRegistry(rootClassLoader, configuration, pkg);
// add default import for this namespace
pkgRegistry.addImport(new ImportDescr(packageDescr.getNamespace() + ".*"));
for (ImportDescr importDescr : packageDescr.getImports()) {
pkgRegistry.registerImport(importDescr.getTarget());
}
return pkgRegistry;
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method validateUniqueRuleNames.
protected void validateUniqueRuleNames(final PackageDescr packageDescr) {
final Set<String> names = new HashSet<String>();
PackageRegistry packageRegistry = this.pkgRegistryMap.get(packageDescr.getNamespace());
InternalKnowledgePackage pkg = null;
if (packageRegistry != null) {
pkg = packageRegistry.getPackage();
}
for (final RuleDescr rule : packageDescr.getRules()) {
validateRule(packageDescr, rule);
final String name = rule.getName();
if (names.contains(name)) {
addBuilderResult(new ParserError(rule.getResource(), "Duplicate rule name: " + name, rule.getLine(), rule.getColumn(), packageDescr.getNamespace()));
}
if (pkg != null) {
RuleImpl duplicatedRule = pkg.getRule(name);
if (duplicatedRule != null) {
Resource resource = rule.getResource();
Resource duplicatedResource = duplicatedRule.getResource();
if (resource == null || duplicatedResource == null || duplicatedResource.getSourcePath() == null || duplicatedResource.getSourcePath().equals(resource.getSourcePath())) {
addBuilderResult(new DuplicateRule(rule, packageDescr, this.configuration));
} else {
addBuilderResult(new ParserError(rule.getResource(), "Duplicate rule name: " + name, rule.getLine(), rule.getColumn(), packageDescr.getNamespace()));
}
}
}
names.add(name);
}
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method buildRules.
protected void buildRules(Collection<CompositePackageDescr> packages) {
for (CompositePackageDescr packageDescr : packages) {
setAssetFilter(packageDescr.getFilter());
PackageRegistry pkgRegistry = getPackageRegistry(packageDescr.getNamespace());
compileKnowledgePackages(packageDescr, pkgRegistry);
setAssetFilter(null);
}
wireAllRules();
processKieBaseTypes();
for (CompositePackageDescr packageDescr : packages) {
setAssetFilter(packageDescr.getFilter());
compileRete(packageDescr);
setAssetFilter(null);
}
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class TypeDeclarationCache method getExistingTypeDeclaration.
private TypeDeclaration getExistingTypeDeclaration(Class<?> cls) {
TypeDeclaration typeDeclaration = null;
PackageRegistry pkgReg = kbuilder.getPackageRegistry(ClassUtils.getPackage(cls));
if (pkgReg != null) {
String className = cls.getName();
String typeName = className.substring(className.lastIndexOf(".") + 1);
typeDeclaration = pkgReg.getPackage().getTypeDeclaration(typeName);
}
return typeDeclaration;
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class TypeDeclarationCache method createTypeDeclarationForBean.
private TypeDeclaration createTypeDeclarationForBean(Class<?> cls) {
Annotated annotated = new Annotated.ClassAdapter(cls);
TypeDeclaration typeDeclaration = TypeDeclaration.createTypeDeclarationForBean(cls, annotated, kbuilder.getBuilderConfiguration().getPropertySpecificOption());
String namespace = ClassUtils.getPackage(cls);
PackageRegistry pkgRegistry = kbuilder.getOrCreatePackageRegistry(new PackageDescr(namespace));
processMvelBasedAccessors(kbuilder, pkgRegistry, annotated, typeDeclaration);
return typeDeclaration;
}
Aggregations