use of org.drools.core.common.ObjectTypeConfigurationRegistry in project drools by kiegroup.
the class SimpleBeliefSystem method getObjectTypeConf.
private ObjectTypeConf getObjectTypeConf(BeliefSet beliefSet) {
InternalFactHandle fh = beliefSet.getFactHandle();
ObjectTypeConfigurationRegistry reg;
ObjectTypeConf typeConf;
reg = ep.getObjectTypeConfigurationRegistry();
typeConf = reg.getObjectTypeConf(ep.getEntryPoint(), fh.getObject());
return typeConf;
}
use of org.drools.core.common.ObjectTypeConfigurationRegistry in project drools by kiegroup.
the class TraitTest method testTMSConsistencyWithNonTraitableBeans.
@Test(timeout = 10000)
public void testTMSConsistencyWithNonTraitableBeans() {
String s1 = "package org.drools.test;\n" + "import org.drools.compiler.Person; \n" + "import org.drools.core.factmodel.traits.Traitable; \n" + "" + "declare Person @Traitable end \n" + "" + "rule \"Init\"\n" + "when\n" + "then\n" + " insertLogical( new Person( \"x\", 18 ) );\n" + "end\n" + "\n" + "declare trait Student\n" + " age : int\n" + " name : String\n" + "end\n" + "\n" + "rule \"Trait\"\n" + "when\n" + " $p : Person( )\n" + "then\n" + " don( $p, Student.class, true );\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ByteArrayResource(s1.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
TraitFactory.setMode(mode, ksession.getKieBase());
ksession.fireAllRules();
FactHandle personHandle = ksession.getFactHandles(new ClassObjectFilter(Person.class)).iterator().next();
InternalFactHandle h = ((InternalFactHandle) personHandle);
ObjectTypeConfigurationRegistry reg = h.getEntryPoint().getObjectTypeConfigurationRegistry();
ObjectTypeConf conf = reg.getObjectTypeConf(h.getEntryPoint().getEntryPoint(), ((InternalFactHandle) personHandle).getObject());
assertTrue(conf.isTMSEnabled());
ksession.dispose();
}
use of org.drools.core.common.ObjectTypeConfigurationRegistry in project drools by kiegroup.
the class TraitHelper method makeTraitable.
private <K> TraitableBean makeTraitable(K core, TraitFactory builder, boolean logical, Activation activation) {
boolean needsWrapping = !(core instanceof TraitableBean);
ClassDefinition coreDef = lookupClassDefinition(core);
TraitableBean<K, ? extends TraitableBean> inner = needsWrapping ? builder.asTraitable(core, coreDef) : (TraitableBean<K, ? extends TraitableBean>) core;
if (needsWrapping) {
InternalFactHandle h = (InternalFactHandle) lookupFactHandle(core);
WorkingMemoryEntryPoint ep = h != null ? h.getEntryPoint() : ((StatefulKnowledgeSessionImpl) workingMemory).getEntryPoint("DEFAULT");
ObjectTypeConfigurationRegistry reg = ep.getObjectTypeConfigurationRegistry();
ObjectTypeConf coreConf = reg.getObjectTypeConf(ep.getEntryPoint(), core);
ObjectTypeConf innerConf = reg.getObjectTypeConf(ep.getEntryPoint(), inner);
if (coreConf.isTMSEnabled()) {
innerConf.enableTMS();
}
if (inner._getFieldTMS() != null && inner._getFieldTMS().needsInit()) {
inner._getFieldTMS().init(workingMemory);
}
} else {
TraitFieldTMS ftms = inner._getFieldTMS();
if (ftms != null) {
FactHandle handle = lookupFactHandle(inner);
if (handle == null) {
handle = this.workingMemory.insert(inner, false, activation.getRule(), activation.getTuple().getTupleSink());
}
if (ftms.needsInit()) {
ftms.init(workingMemory);
}
}
}
return inner;
}
use of org.drools.core.common.ObjectTypeConfigurationRegistry in project drools by kiegroup.
the class JTMSBeliefSystem method getObjectTypeConf.
private ObjectTypeConf getObjectTypeConf(BeliefSet<M> jtmsBeliefSet) {
InternalFactHandle fh = jtmsBeliefSet.getFactHandle();
ObjectTypeConfigurationRegistry reg;
ObjectTypeConf typeConf;
reg = ep.getObjectTypeConfigurationRegistry();
typeConf = reg.getObjectTypeConf(ep.getEntryPoint(), fh.getObject());
return typeConf;
}
Aggregations