Search in sources :

Example 6 with TypeDeclaration

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

the class NamedEntryPoint method update.

public void update(FactHandle handle, Object object, String... modifiedProperties) {
    Class modifiedClass = object.getClass();
    TypeDeclaration typeDeclaration = kBase.getOrCreateExactTypeDeclaration(modifiedClass);
    BitMask mask = typeDeclaration.isPropertyReactive() ? calculatePositiveMask(modifiedClass, asList(modifiedProperties), typeDeclaration.getAccessibleProperties()) : AllSetBitMask.get();
    update((InternalFactHandle) handle, object, mask, modifiedClass, null);
}
Also used : BitMask(org.drools.core.util.bitmask.BitMask) AllSetBitMask(org.drools.core.util.bitmask.AllSetBitMask) TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 7 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration 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 8 with TypeDeclaration

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

the class KnowledgePackageImpl method removeTypesGeneratedFromResource.

public List<TypeDeclaration> removeTypesGeneratedFromResource(Resource resource) {
    List<TypeDeclaration> typesToBeRemoved = getTypesGeneratedFromResource(resource);
    if (!typesToBeRemoved.isEmpty()) {
        JavaDialectRuntimeData dialect = (JavaDialectRuntimeData) getDialectRuntimeRegistry().getDialectData("java");
        for (TypeDeclaration type : typesToBeRemoved) {
            if (type.getTypeClassName() != null) {
                // the type declaration might not have been built up to actual class, if an error was found first
                // in this case, no accessor would have been wired
                classFieldAccessorStore.removeType(type);
                dialect.remove(type.getTypeClassName());
                if (typeResolver != null) {
                    typeResolver.registerClass(type.getTypeClassName(), null);
                }
            }
            removeTypeDeclaration(type.getTypeName());
        }
        dialect.reload();
    }
    return typesToBeRemoved;
}
Also used : JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 9 with TypeDeclaration

use of org.drools.core.rule.TypeDeclaration 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)

Example 10 with TypeDeclaration

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

the class TraitRegistry method init.

private void init() {
    TypeDeclaration thingType = new TypeDeclaration(Thing.class.getName());
    thingType.setKind(TypeDeclaration.Kind.TRAIT);
    thingType.setTypeClass(Thing.class);
    ClassDefinition def = new ClassDefinition();
    def.setClassName(thingType.getTypeClass().getName());
    def.setDefinedClass(Thing.class);
    addTrait(def);
    ClassDefinition individualDef = new ClassDefinition();
    individualDef.setClassName(Entity.class.getName());
    individualDef.setDefinedClass(Entity.class);
    individualDef.setInterfaces(new String[] { Serializable.class.getName(), TraitableBean.class.getName() });
    individualDef.setTraitable(true);
    addTraitable(individualDef);
    ClassDefinition mapcoreDef = new ClassDefinition();
    mapcoreDef.setClassName(MapCore.class.getName());
    mapcoreDef.setDefinedClass(MapCore.class);
    mapcoreDef.setInterfaces(new String[] { Serializable.class.getName(), TraitableBean.class.getName(), CoreWrapper.class.getName() });
    mapcoreDef.setTraitable(true);
    addTraitable(mapcoreDef);
    ClassDefinition logicalMapcoreDef = new ClassDefinition();
    logicalMapcoreDef.setClassName(LogicalMapCore.class.getName());
    logicalMapcoreDef.setDefinedClass(LogicalMapCore.class);
    logicalMapcoreDef.setInterfaces(new String[] { Serializable.class.getName(), TraitableBean.class.getName(), CoreWrapper.class.getName() });
    logicalMapcoreDef.setTraitable(true, true);
    addTraitable(logicalMapcoreDef);
}
Also used : Serializable(java.io.Serializable) MapCore(org.drools.core.factmodel.MapCore) ClassDefinition(org.drools.core.factmodel.ClassDefinition) 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