Search in sources :

Example 1 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class TypeDeclarationConfigurator method buildFieldAccessors.

protected void buildFieldAccessors(final TypeDeclaration type, final PackageRegistry pkgRegistry) throws SecurityException, IllegalArgumentException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
    ClassDefinition cd = type.getTypeClassDef();
    ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
    for (FieldDefinition attrDef : cd.getFieldsDefinitions()) {
        ClassFieldAccessor accessor = store.getAccessor(cd.getDefinedClass().getName(), attrDef.getName());
        attrDef.setReadWriteAccessor(accessor);
    }
}
Also used : ClassFieldAccessor(org.drools.core.base.ClassFieldAccessor) FieldDefinition(org.drools.core.factmodel.FieldDefinition) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) ClassDefinition(org.drools.core.factmodel.ClassDefinition)

Example 2 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class BetaNodeBuilder method build.

public BetaNode build() {
    NodeFactory nFactory = buildContext.getComponentFactory().getNodeFactoryService();
    EntryPointNode epn = buildContext.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next();
    ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(leftType), buildContext);
    LeftInputAdapterNode leftInput = nFactory.buildLeftInputAdapterNode(buildContext.getNextId(), otn, buildContext);
    ObjectSource rightInput = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(rightType), buildContext);
    ReteTesterHelper reteTesterHelper = new ReteTesterHelper();
    Pattern pattern = new Pattern(0, new ClassObjectType(leftType));
    // BetaNodeFieldConstraint betaConstraint = null;
    BetaConstraints betaConstraints = null;
    if (constraintFieldName != null) {
        ClassFieldAccessorStore store = (ClassFieldAccessorStore) reteTesterHelper.getStore();
        InternalReadAccessor extractor = store.getReader(leftType, leftFieldName);
        Declaration declr = new Declaration(leftVariableName, extractor, pattern);
        betaConstraints = new SingleBetaConstraints(reteTesterHelper.getBoundVariableConstraint(rightType, constraintFieldName, declr, constraintOperator), buildContext.getKnowledgeBase().getConfiguration());
    } else {
        betaConstraints = new EmptyBetaConstraints();
    }
    switch(nodeType) {
        case NodeTypeEnums.JoinNode:
            return new JoinNode(0, leftInput, rightInput, betaConstraints, buildContext);
        case NodeTypeEnums.NotNode:
            return new NotNode(0, leftInput, rightInput, betaConstraints, buildContext);
        case NodeTypeEnums.ExistsNode:
            return new ExistsNode(0, leftInput, rightInput, betaConstraints, buildContext);
    }
    throw new IllegalStateException("Unable to build Node");
}
Also used : Pattern(org.drools.core.rule.Pattern) SingleBetaConstraints(org.drools.core.common.SingleBetaConstraints) NotNode(org.drools.core.reteoo.NotNode) BetaConstraints(org.drools.core.common.BetaConstraints) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) SingleBetaConstraints(org.drools.core.common.SingleBetaConstraints) ClassObjectType(org.drools.core.base.ClassObjectType) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) ExistsNode(org.drools.core.reteoo.ExistsNode) EntryPointNode(org.drools.core.reteoo.EntryPointNode) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) EmptyBetaConstraints(org.drools.core.common.EmptyBetaConstraints) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) ObjectSource(org.drools.core.reteoo.ObjectSource) Declaration(org.drools.core.rule.Declaration) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 3 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class BooleanClassFieldExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    this.reader = store.getReader(TestBean.class, "booleanAttr");
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) TestBean(org.drools.core.base.TestBean) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) Before(org.junit.Before)

Example 4 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class CharClassFieldExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    this.reader = store.getReader(TestBean.class, "charAttr");
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) TestBean(org.drools.core.base.TestBean) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) Before(org.junit.Before)

Example 5 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class DoubleClassFieldExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    this.reader = store.getReader(TestBean.class, "doubleAttr");
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) TestBean(org.drools.core.base.TestBean) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) Before(org.junit.Before)

Aggregations

ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)20 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)17 Before (org.junit.Before)11 TestBean (org.drools.core.base.TestBean)9 ClassObjectType (org.drools.core.base.ClassObjectType)6 Pattern (org.drools.core.rule.Pattern)6 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)5 Declaration (org.drools.core.rule.Declaration)4 IOException (java.io.IOException)2 ObjectInput (java.io.ObjectInput)2 ObjectOutput (java.io.ObjectOutput)2 WorkingMemory (org.drools.core.WorkingMemory)2 ClassFieldAccessor (org.drools.core.base.ClassFieldAccessor)2 ClassFieldReader (org.drools.core.base.ClassFieldReader)2 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 ClassDefinition (org.drools.core.factmodel.ClassDefinition)2 FieldDefinition (org.drools.core.factmodel.FieldDefinition)2 PackageClassLoader (org.drools.core.rule.JavaDialectRuntimeData.PackageClassLoader)2