rtnLeftTuple = child;
}
}
}
RuleTerminalNode oldRtn = null;
if (rtnLeftTuple != null) {
oldRtn = (RuleTerminalNode) rtnLeftTuple.getSink();
}
ConditionalExecution conditionalExecution = branchEvaluator.evaluate(leftTuple, wm, cbm.context);
RuleTerminalNode newRtn = null;
boolean breaking = false;
if (conditionalExecution != null) {
newRtn = (RuleTerminalNode) conditionalExecution.getSink().getFirstLeftTupleSink();
breaking = conditionalExecution.isBreaking();
}
// Handle conditional branches
if (oldRtn != null) {
if (newRtn == null) {
// old exits, new does not, so delete
if ( rtnLeftTuple.getMemory() != null ) {
executor.removeLeftTuple(rtnLeftTuple);
}
PhreakRuleTerminalNode.doLeftDelete(wm, executor, rtnLeftTuple);
} else if (newRtn == oldRtn) {
// old and new on same branch, so update
PhreakRuleTerminalNode.doLeftTupleUpdate(newRtn, executor, (InternalAgenda) wm.getAgenda(), salienceInt, salience, rtnLeftTuple, wm) ;
} else {
// old and new on different branches, delete one and insert the other
if ( rtnLeftTuple.getMemory() != null ) {
executor.removeLeftTuple(rtnLeftTuple);
}
PhreakRuleTerminalNode.doLeftDelete(wm, executor, rtnLeftTuple);
rtnLeftTuple = newRtn.createLeftTuple(leftTuple,
newRtn,
leftTuple.getPropagationContext(), true);
PhreakRuleTerminalNode.doLeftTupleInsert( newRtn, executor, (InternalAgenda) wm.getAgenda(),
executor.getRuleAgendaItem(), salienceInt, salience, rtnLeftTuple, wm) ;
}
} else if (newRtn != null) {
// old does not exist, new exists, so insert
rtnLeftTuple = newRtn.createLeftTuple(leftTuple, newRtn,
leftTuple.getPropagationContext(), true);
PhreakRuleTerminalNode.doLeftTupleInsert( newRtn, executor, (InternalAgenda) wm.getAgenda(),
executor.getRuleAgendaItem(), salienceInt, salience, rtnLeftTuple, wm) ;
}