use of org.drools.tms.beliefsystem.BeliefSystem in project drools by kiegroup.
the class TruthMaintenanceSystemKnowledgeHelper method bolster.
@Override
public InternalFactHandle bolster(final Object object, final Object value) {
if (object == null || !activation.isMatched()) {
return null;
}
InternalFactHandle handle = getFactHandleFromWM(object);
NamedEntryPoint ep = (NamedEntryPoint) reteEvaluator.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId());
ObjectTypeConf otc = ep.getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(ep.getEntryPoint(), object);
BeliefSet beliefSet = null;
if (handle == null) {
handle = RuntimeComponentFactory.get().getFactHandleFactoryService().newFactHandle(object, otc, reteEvaluator, ep);
}
if (handle.getEqualityKey() == null) {
handle.setEqualityKey(new TruthMaintenanceSystemEqualityKey(handle, EqualityKey.STATED));
} else {
beliefSet = ((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).getBeliefSet();
}
BeliefSystem beliefSystem = value instanceof BeliefSystemMode ? ((BeliefSystemMode) value).getBeliefSystem() : ((TruthMaintenanceSystemImpl) TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem(toStatefulKnowledgeSession())).getBeliefSystem();
if (beliefSet == null) {
beliefSet = beliefSystem.newBeliefSet(handle);
((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).setBeliefSet(beliefSet);
}
return beliefSystem.insert(beliefSystem.asMode(value), activation.getRule(), (TruthMaintenanceSystemActivation) activation, object, beliefSet, activation.getPropagationContext(), otc).getFactHandle();
}
use of org.drools.tms.beliefsystem.BeliefSystem in project drools by kiegroup.
the class TruthMaintenanceSystemImpl method addLogicalDependency.
private InternalFactHandle addLogicalDependency(final InternalFactHandle handle, final Object object, final Object value, final TruthMaintenanceSystemActivation activation, final ObjectTypeConf typeConf, final boolean read) {
BeliefSystem beliefSystem = defaultBeliefSystem;
if (value instanceof Mode & !(value instanceof SimpleMode)) {
BeliefSystemMode mode = (BeliefSystemMode) value;
beliefSystem = mode.getBeliefSystem();
}
BeliefSet beliefSet = ((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).getBeliefSet();
if (beliefSet == null) {
beliefSet = beliefSystem.newBeliefSet(handle);
((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).setBeliefSet(beliefSet);
}
final LogicalDependency node = beliefSystem.newLogicalDependency(activation, beliefSet, object, value);
activation.getRule().setHasLogicalDependency(true);
activation.addLogicalDependency(node);
if (read) {
// used when deserialising
beliefSystem.read(node, beliefSet, activation.getPropagationContext(), typeConf);
} else {
beliefSet = beliefSystem.insert(node, beliefSet, activation.getPropagationContext(), typeConf);
}
return beliefSet.getFactHandle();
}
Aggregations