Search in sources :

Example 1 with DuplicateFunction

use of org.drools.compiler.compiler.DuplicateFunction 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.mergeStore(newPkg);
    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);
}
Also used : AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) DuplicateFunction(org.drools.compiler.compiler.DuplicateFunction) Function(org.drools.core.rule.Function) DuplicateFunction(org.drools.compiler.compiler.DuplicateFunction) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) PackageDescr(org.drools.drl.ast.descr.PackageDescr) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TypeDeclaration(org.drools.core.rule.TypeDeclaration) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 2 with DuplicateFunction

use of org.drools.compiler.compiler.DuplicateFunction in project drools by kiegroup.

the class KnowledgeBuilderImpl method processFunctions.

protected void processFunctions(PackageRegistry pkgRegistry, PackageDescr packageDescr) {
    for (FunctionDescr function : packageDescr.getFunctions()) {
        Function existingFunc = pkgRegistry.getPackage().getFunctions().get(function.getName());
        if (existingFunc != null && function.getNamespace().equals(existingFunc.getNamespace())) {
            addBuilderResult(new DuplicateFunction(function, this.configuration));
        }
    }
    for (final FunctionImportDescr functionImport : packageDescr.getFunctionImports()) {
        String importEntry = functionImport.getTarget();
        pkgRegistry.addStaticImport(functionImport);
        pkgRegistry.getPackage().addStaticImport(importEntry);
    }
}
Also used : AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) DuplicateFunction(org.drools.compiler.compiler.DuplicateFunction) Function(org.drools.core.rule.Function) DuplicateFunction(org.drools.compiler.compiler.DuplicateFunction) FunctionImportDescr(org.drools.drl.ast.descr.FunctionImportDescr) FunctionDescr(org.drools.drl.ast.descr.FunctionDescr)

Aggregations

DuplicateFunction (org.drools.compiler.compiler.DuplicateFunction)2 Function (org.drools.core.rule.Function)2 AccumulateFunction (org.kie.api.runtime.rule.AccumulateFunction)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 TypeDeclaration (org.drools.core.rule.TypeDeclaration)1 FunctionDescr (org.drools.drl.ast.descr.FunctionDescr)1 FunctionImportDescr (org.drools.drl.ast.descr.FunctionImportDescr)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1