use of org.drools.compiler.compiler.GlobalError in project drools by kiegroup.
the class KnowledgeBuilderImpl method processGlobals.
private void processGlobals(PackageRegistry pkgRegistry, PackageDescr packageDescr) {
InternalKnowledgePackage pkg = pkgRegistry.getPackage();
Set<String> existingGlobals = new HashSet<String>(pkg.getGlobals().keySet());
for (final GlobalDescr global : packageDescr.getGlobals()) {
final String identifier = global.getIdentifier();
existingGlobals.remove(identifier);
String className = global.getType();
// JBRULES-3039: can't handle type name with generic params
while (className.indexOf('<') >= 0) {
className = className.replaceAll("<[^<>]+?>", "");
}
try {
Class<?> clazz = pkgRegistry.getTypeResolver().resolveType(className);
if (clazz.isPrimitive()) {
addBuilderResult(new GlobalError(global, " Primitive types are not allowed in globals : " + className));
return;
}
pkg.addGlobal(identifier, clazz);
addGlobal(identifier, clazz);
if (kBase != null) {
kBase.addGlobal(identifier, clazz);
}
} catch (final ClassNotFoundException e) {
addBuilderResult(new GlobalError(global, e.getMessage()));
e.printStackTrace();
}
}
for (String toBeRemoved : existingGlobals) {
if (filterAcceptsRemoval(ResourceChange.Type.GLOBAL, pkg.getName(), toBeRemoved)) {
pkg.removeGlobal(toBeRemoved);
if (kBase != null) {
kBase.removeGlobal(toBeRemoved);
}
}
}
}
Aggregations