Search in sources :

Example 1 with GlobalError

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);
            }
        }
    }
}
Also used : GlobalDescr(org.drools.compiler.lang.descr.GlobalDescr) GlobalError(org.drools.compiler.compiler.GlobalError) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 GlobalError (org.drools.compiler.compiler.GlobalError)1 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1