}
public void removeKnowledgePackage(String packageName) {
lock();
try {
final InternalKnowledgePackage pkg = this.pkgs.get( packageName );
if (pkg == null) {
throw new IllegalArgumentException( "Package name '" + packageName +
"' does not exist for this Rule Base." );
}
this.removalsSinceLock++;
this.eventSupport.fireBeforePackageRemoved( pkg );
for (Rule rule : pkg.getRules()) {
removeRule( pkg, (RuleImpl)rule );
}
// getting the list of referenced globals
final Set<String> referencedGlobals = new HashSet<String>();
for (InternalKnowledgePackage pkgref : this.pkgs.values()) {
if (pkgref != pkg) {
referencedGlobals.addAll( pkgref.getGlobals().keySet() );
}
}
// removing globals declared inside the package that are not shared
for (String globalName : pkg.getGlobals().keySet()) {
if (!referencedGlobals.contains( globalName )) {
this.globals.remove( globalName );
}
}
//and now the rule flows
for ( String processName : new ArrayList<String>(pkg.getRuleFlows().keySet()) ) {
removeProcess( processName );
}
// removing the package itself from the list
this.pkgs.remove( pkg.getName() );
pkg.getDialectRuntimeRegistry().onRemove();
//clear all members of the pkg
pkg.clear();
this.eventSupport.fireAfterPackageRemoved( pkg );
} finally {
unlock();
}