Search in sources :

Example 1 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class KnowledgeBaseImpl method getFactType.

public FactType getFactType(String packageName, String typeName) {
    String name = packageName + "." + typeName;
    readLock();
    try {
        for (InternalKnowledgePackage pkg : this.pkgs.values()) {
            FactType type = pkg.getFactType(name);
            if (type != null) {
                return type;
            }
        }
        return null;
    } finally {
        readUnlock();
    }
}
Also used : InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) FactType(org.kie.api.definition.type.FactType)

Example 2 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class KnowledgeBaseImpl method processAllTypesDeclaration.

public void processAllTypesDeclaration(List<InternalKnowledgePackage> pkgs) {
    List<TypeDeclaration> allTypeDeclarations = new ArrayList<TypeDeclaration>();
    // Add all Type Declarations, this has to be done first incase packages cross reference each other during build process.
    for (InternalKnowledgePackage newPkg : pkgs) {
        // we have to do this before the merging, as it does some classloader resolving
        if (newPkg.getTypeDeclarations() != null) {
            allTypeDeclarations.addAll(newPkg.getTypeDeclarations().values());
        }
    }
    Collections.sort(allTypeDeclarations);
    String lastType = null;
    try {
        // add type declarations according to the global order
        for (TypeDeclaration newDecl : allTypeDeclarations) {
            lastType = newDecl.getTypeClassName();
            InternalKnowledgePackage newPkg = null;
            for (InternalKnowledgePackage kpkg : pkgs) {
                if (kpkg.getTypeDeclarations().containsKey(newDecl.getTypeName())) {
                    newPkg = kpkg;
                    break;
                }
            }
            processTypeDeclaration(newDecl, newPkg);
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("unable to resolve Type Declaration class '" + lastType + "'", e);
    }
}
Also used : ArrayList(java.util.ArrayList) TypeDeclaration(org.drools.core.rule.TypeDeclaration) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 3 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class KnowledgeBaseImpl method removeRule.

public void removeRule(final String packageName, final String ruleName) {
    enqueueModification(() -> {
        final InternalKnowledgePackage pkg = pkgs.get(packageName);
        if (pkg == null) {
            throw new IllegalArgumentException("Package name '" + packageName + "' does not exist for this Rule Base.");
        }
        RuleImpl rule = pkg.getRule(ruleName);
        if (rule == null) {
            throw new IllegalArgumentException("Rule name '" + ruleName + "' does not exist in the Package '" + packageName + "'.");
        }
        this.eventSupport.fireBeforeRuleRemoved(rule);
        this.reteooBuilder.removeRules(Collections.singletonList(rule));
        this.eventSupport.fireAfterRuleRemoved(rule);
        pkg.removeRule(rule);
        addReloadDialectDatas(pkg.getDialectRuntimeRegistry());
    });
}
Also used : RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 4 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class PhreakPropagationContext method getAccessibleProperties.

private List<String> getAccessibleProperties(InternalWorkingMemory workingMemory, Class<?> classType, String pkgName) {
    if (pkgName.equals("java.lang") || pkgName.equals("java.util")) {
        return Collections.EMPTY_LIST;
    }
    InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage(pkgName);
    TypeDeclaration tdecl = pkg != null ? pkg.getTypeDeclaration(classType) : null;
    return tdecl != null ? tdecl.getAccessibleProperties() : Collections.EMPTY_LIST;
}
Also used : TypeDeclaration(org.drools.core.rule.TypeDeclaration) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 5 with InternalKnowledgePackage

use of org.drools.core.definitions.InternalKnowledgePackage in project drools by kiegroup.

the class TraitField method inspectForTraitability.

private boolean inspectForTraitability(Object value, WorkingMemory wm) {
    InternalKnowledgePackage pack = wm.getKnowledgeBase().getPackage(value.getClass().getPackage().getName());
    if (pack != null) {
        TypeDeclaration decl = pack.getTypeDeclaration(value.getClass());
        if (decl != null) {
            return decl.getTypeClassDef().isFullTraiting();
        }
    }
    Traitable tbl = value.getClass().getAnnotation(Traitable.class);
    return tbl != null && tbl.logical();
}
Also used : TypeDeclaration(org.drools.core.rule.TypeDeclaration) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)97 Test (org.junit.Test)32 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)28 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)26 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)24 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)21 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)20 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)16 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)14 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)13 TypeDeclaration (org.drools.core.rule.TypeDeclaration)13 HashMap (java.util.HashMap)12 Pattern (org.drools.core.rule.Pattern)12 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)11 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)11 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)11 ClassObjectType (org.drools.core.base.ClassObjectType)10 ArrayList (java.util.ArrayList)9 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)9 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)8