use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class ClassHierarchyManager method addDeclarationToPackagePreservingOrder.
public void addDeclarationToPackagePreservingOrder(TypeDeclaration type, AbstractClassTypeDeclarationDescr typeDescr, InternalKnowledgePackage tgtPackage, Map<String, PackageRegistry> pkgRegistryMap) {
Collection<QualifiedName> parents = taxonomy.get(new QualifiedName(type.getFullName()));
int index = getSortedDescriptors().indexOf(typeDescr);
if (parents != null && !parents.isEmpty()) {
for (QualifiedName parentName : parents) {
String nameSpace = parentName.getNamespace();
String name = parentName.getName();
PackageRegistry parentPkgRegistry = pkgRegistryMap.get(nameSpace);
if (parentPkgRegistry != null) {
TypeDeclaration parentDeclaration = parentPkgRegistry.getPackage().getTypeDeclaration(name);
if (parentDeclaration != null && parentDeclaration.getNature() == TypeDeclaration.Nature.DEFINITION) {
index = Math.max(index, parentDeclaration.getOrder());
}
}
}
}
type.setOrder(index + 1);
tgtPackage.addTypeDeclaration(type);
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method buildOtherDeclarations.
protected void buildOtherDeclarations(Collection<CompositePackageDescr> packages) {
for (CompositePackageDescr packageDescr : packages) {
setAssetFilter(packageDescr.getFilter());
PackageRegistry pkgRegistry = getPackageRegistry(packageDescr.getNamespace());
processOtherDeclarations(pkgRegistry, packageDescr);
setAssetFilter(null);
}
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method removeObjectsGeneratedFromResource.
public ResourceRemovalResult removeObjectsGeneratedFromResource(Resource resource) {
boolean modified = false;
if (pkgRegistryMap != null) {
for (PackageRegistry packageRegistry : pkgRegistryMap.values()) {
modified = packageRegistry.removeObjectsGeneratedFromResource(resource) || modified;
}
}
if (results != null) {
Iterator<KnowledgeBuilderResult> i = results.iterator();
while (i.hasNext()) {
if (resource.equals(i.next().getResource())) {
i.remove();
}
}
}
if (processBuilder != null && processBuilder.getErrors() != null) {
Iterator<? extends KnowledgeBuilderResult> i = processBuilder.getErrors().iterator();
while (i.hasNext()) {
if (resource.equals(i.next().getResource())) {
i.remove();
}
}
}
if (results.size() == 0) {
// TODO Error attribution might be bugged
for (PackageRegistry packageRegistry : pkgRegistryMap.values()) {
packageRegistry.getPackage().resetErrors();
}
}
Collection<String> removedTypes = typeBuilder.removeTypesGeneratedFromResource(resource);
for (List<PackageDescr> pkgDescrs : packages.values()) {
for (PackageDescr pkgDescr : pkgDescrs) {
pkgDescr.removeObjectsGeneratedFromResource(resource);
}
}
if (kBase != null) {
modified = kBase.removeObjectsGeneratedFromResource(resource) || modified;
}
return new ResourceRemovalResult(modified, removedTypes);
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method addPackage.
/**
* This adds a package from a Descr/AST This will also trigger a compile, if
* there are any generated classes to compile of course.
*/
public void addPackage(final PackageDescr packageDescr) {
PackageRegistry pkgRegistry = getOrCreatePackageRegistry(packageDescr);
if (pkgRegistry == null) {
return;
}
// merge into existing package
mergePackage(pkgRegistry, packageDescr);
compileKnowledgePackages(packageDescr, pkgRegistry);
wireAllRules();
compileRete(packageDescr);
}
use of org.drools.compiler.compiler.PackageRegistry in project drools by kiegroup.
the class KnowledgeBuilderImpl method addPackage.
public synchronized void addPackage(InternalKnowledgePackage newPkg) {
PackageRegistry pkgRegistry = this.pkgRegistryMap.get(newPkg.getName());
InternalKnowledgePackage pkg = null;
if (pkgRegistry != null) {
pkg = pkgRegistry.getPackage();
}
if (pkg == null) {
PackageDescr packageDescr = new PackageDescr(newPkg.getName());
pkgRegistry = getOrCreatePackageRegistry(packageDescr);
mergePackage(this.pkgRegistryMap.get(packageDescr.getNamespace()), packageDescr);
pkg = pkgRegistry.getPackage();
}
// first merge anything related to classloader re-wiring
pkg.getDialectRuntimeRegistry().merge(newPkg.getDialectRuntimeRegistry(), this.rootClassLoader);
if (newPkg.getFunctions() != null) {
for (Map.Entry<String, Function> entry : newPkg.getFunctions().entrySet()) {
if (pkg.getFunctions().containsKey(entry.getKey())) {
addBuilderResult(new DuplicateFunction(entry.getValue(), this.configuration));
}
pkg.addFunction(entry.getValue());
}
}
pkg.getClassFieldAccessorStore().merge(newPkg.getClassFieldAccessorStore());
pkg.getDialectRuntimeRegistry().onBeforeExecute();
// we have to do this before the merging, as it does some classloader resolving
TypeDeclaration lastType = null;
try {
// Resolve the class for the type declaation
if (newPkg.getTypeDeclarations() != null) {
// add type declarations
for (TypeDeclaration type : newPkg.getTypeDeclarations().values()) {
lastType = type;
type.setTypeClass(this.rootClassLoader.loadClass(type.getTypeClassName()));
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("unable to resolve Type Declaration class '" + lastType.getTypeName() + "'");
}
// now merge the new package into the existing one
mergePackage(pkg, newPkg);
}
Aggregations