Search in sources :

Example 61 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.

the class KnowledgeBaseImpl method removeObjectsGeneratedFromResource.

public boolean removeObjectsGeneratedFromResource(Resource resource) {
    boolean modified = false;
    for (InternalKnowledgePackage pkg : pkgs.values()) {
        List<RuleImpl> rulesToBeRemoved = pkg.getRulesGeneratedFromResource(resource);
        if (!rulesToBeRemoved.isEmpty()) {
            this.reteooBuilder.removeRules(rulesToBeRemoved);
            // in order to allow the correct flushing of all outstanding staged tuples
            for (RuleImpl rule : rulesToBeRemoved) {
                pkg.removeRule(rule);
            }
        }
        List<Function> functionsToBeRemoved = pkg.removeFunctionsGeneratedFromResource(resource);
        for (Function function : functionsToBeRemoved) {
            internalRemoveFunction(pkg.getName(), function.getName());
        }
        List<Process> processesToBeRemoved = pkg.removeProcessesGeneratedFromResource(resource);
        for (Process process : processesToBeRemoved) {
            processes.remove(process.getId());
        }
        List<TypeDeclaration> removedTypes = pkg.removeTypesGeneratedFromResource(resource);
        boolean resourceTypePackageSomethingRemoved = pkg.removeFromResourceTypePackageGeneratedFromResource(resource);
        modified |= !rulesToBeRemoved.isEmpty() || !functionsToBeRemoved.isEmpty() || !processesToBeRemoved.isEmpty() || !removedTypes.isEmpty() || resourceTypePackageSomethingRemoved;
    }
    return modified;
}
Also used : Function(org.drools.core.rule.Function) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Process(org.kie.api.definition.process.Process) TypeDeclaration(org.drools.core.rule.TypeDeclaration) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 62 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.

the class KnowledgeBaseImpl method checkSuperClasses.

private TypeDeclarationCandidate checkSuperClasses(Class<?> clazz) {
    TypeDeclaration typeDeclaration = null;
    Class<?> current = clazz.getSuperclass();
    int score = 0;
    while (typeDeclaration == null && current != null) {
        score++;
        typeDeclaration = this.classTypeDeclaration.get(current.getName());
        current = current.getSuperclass();
    }
    TypeDeclarationCandidate candidate = null;
    if (typeDeclaration != null) {
        candidate = new TypeDeclarationCandidate();
        candidate.candidate = typeDeclaration;
        candidate.score = score;
    }
    return candidate;
}
Also used : TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 63 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.

the class KnowledgeBaseImpl method checkInterfaces.

private TypeDeclarationCandidate checkInterfaces(Class<?> clazz, TypeDeclarationCandidate baseline, int level) {
    TypeDeclarationCandidate candidate = null;
    if (baseline == null || level < baseline.score) {
        // search
        TypeDeclaration typeDeclaration;
        for (Class<?> ifc : clazz.getInterfaces()) {
            typeDeclaration = this.classTypeDeclaration.get(ifc.getName());
            if (typeDeclaration != null) {
                candidate = new TypeDeclarationCandidate();
                candidate.candidate = typeDeclaration;
                candidate.score = level;
                break;
            } else {
                candidate = checkInterfaces(ifc, baseline, level + 1);
            }
        }
    } else {
        candidate = baseline;
    }
    return candidate;
}
Also used : TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 64 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.

the class KnowledgePackageImpl method getFactType.

public FactType getFactType(final String typeName) {
    if (typeName == null || (this.name != null && !typeName.startsWith(this.name + "."))) {
        return null;
    }
    // in case the package name is != null, remove the package name from the
    // beginning of the type name
    String key = this.name == null ? typeName : typeName.substring(this.name.length() + 1);
    TypeDeclaration decl = this.typeDeclarations.get(key);
    if (decl == null) {
        return null;
    } else {
        if (decl.isDefinition() || decl.isGeneratedFact()) {
            return decl.getTypeClassDef();
        } else {
            throw new UnsupportedOperationException("KieBase.getFactType should only be used to retrieve declared beans. Class " + typeName + " exists outside DRL ");
        }
    }
}
Also used : TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 65 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.

the class MapCore method getTypeDeclaration.

public static TypeDeclaration getTypeDeclaration() {
    String[] mcInterfaces = new String[MapCore.class.getInterfaces().length];
    int j = 0;
    for (Class intf : MapCore.class.getInterfaces()) {
        mcInterfaces[j++] = intf.getName();
    }
    ClassDefinition mcClassDef = new ClassDefinition(MapCore.class.getName(), MapCore.class.getSuperclass().getName(), mcInterfaces);
    mcClassDef.setTraitable(true);
    mcClassDef.setDefinedClass(MapCore.class);
    mcClassDef.setAbstrakt(false);
    TypeDeclaration mapCoreType = new TypeDeclaration(MapCore.class.getName());
    mapCoreType.setKind(TypeDeclaration.Kind.CLASS);
    mapCoreType.setTypeClass(MapCore.class);
    mapCoreType.setTypeClassDef(mcClassDef);
    return mapCoreType;
}
Also used : TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Aggregations

TypeDeclaration (org.drools.core.rule.TypeDeclaration)72 Test (org.junit.Test)15 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)12 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)11 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)10 ClassDefinition (org.drools.core.factmodel.ClassDefinition)9 ClassObjectType (org.drools.core.base.ClassObjectType)7 TypeDeclarationDescr (org.drools.compiler.lang.descr.TypeDeclarationDescr)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TypeDeclarationError (org.drools.compiler.compiler.TypeDeclarationError)4 AbstractClassTypeDeclarationDescr (org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr)4 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 ObjectType (org.drools.core.spi.ObjectType)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)3 TypeFieldDescr (org.drools.compiler.lang.descr.TypeFieldDescr)3 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)3