org.speakright.core.flows
Class BranchFlow

java.lang.Object
  extended by org.speakright.core.FlowBase
      extended by org.speakright.core.flows.BranchFlow
All Implemented Interfaces:
java.io.Serializable, IFlow

public abstract class BranchFlow
extends FlowBase

BranchFlow provides branching of the callflow based on an application-defined condition. Derived classes override the branch method to supply the branching logic. Sub-flows can jump back to the branch flow later by 'throwing' a GotoBranchEvent.

Branch flows can loop forever if m_loopForever is set in the constructor. That is, when the sub-flows end the branch flow executes again.

Author:
Ian Rae
See Also:
Serialized Form

Nested Class Summary
static class BranchFlow.GotoBranchEvent
          An event class used to jump back from a sub-flow to a branch flow.
 
Field Summary
protected  boolean m_loopForever
           
 
Constructor Summary
BranchFlow()
           
 
Method Summary
protected abstract  IFlow branch()
          Derived classes MUST override this and return a flow object to execute.
 IFlow getFirst(IFlowContext context)
          Do the branching, as determined by branch()
 IFlow getNext(IFlow current, SRResults results)
          If m_loopForever set then return this, else null.
 IFlow onCatch(IFlow current, SRResults results, java.lang.String eventName, ThrowEvent event)
          Catch a GotoBranchEvent that is targeted at this object, that is, the event's m_branchName matches our name.
protected abstract  void onCatchGotoBranchEvent(BranchFlow.GotoBranchEvent ev)
          Process the caught GotoBranchEvent.
 
Methods inherited from class org.speakright.core.FlowBase
createRenderer, execute, executionCount, fixupGrammar, fixupPrompt, getSubFlowAfter, log, logError, name, onBegin, onComplete, onDisconnect, onEnd, onNoInput, onPlatformError, onTransferFailed, onValidateFailed, promptGroup, setExecutionCount, setName, setPromptGroup, shouldExecute, validateInput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_loopForever

protected boolean m_loopForever
Constructor Detail

BranchFlow

public BranchFlow()
Method Detail

getFirst

public IFlow getFirst(IFlowContext context)
Do the branching, as determined by branch()

Specified by:
getFirst in interface IFlow
Overrides:
getFirst in class FlowBase
Returns:
an IFlow object to be executed.

branch

protected abstract IFlow branch()
Derived classes MUST override this and return a flow object to execute.

Returns:
the flow object to execute. Cannot return null.

getNext

public IFlow getNext(IFlow current,
                     SRResults results)
If m_loopForever set then return this, else null.

Specified by:
getNext in interface IFlow
Overrides:
getNext in class FlowBase
Parameters:
current - the currently executing flow object. More precisely, current is the flow object that this object most recently returned from getFirst or getNext.
results - the results of current's execution by the speech platform. Results contains user input and/or events such as disconnect or platform-error.
Returns:
the next flow to run, or null which means this flow object is finished.

onCatch

public IFlow onCatch(IFlow current,
                     SRResults results,
                     java.lang.String eventName,
                     ThrowEvent event)
Catch a GotoBranchEvent that is targeted at this object, that is, the event's m_branchName matches our name. If we catch the event then onCatchGotoBranchEvent is invoked.

Specified by:
onCatch in interface IFlow
Overrides:
onCatch in class FlowBase
Parameters:
current - the currently executing flow object.
results - the results of current's execution.
eventName - name of the event. most event handling can be done using just the name.
event - event object. advanced event handling may require the actual event object
Returns:
the next flow to run, or null which means this flow object does not handle this event.

onCatchGotoBranchEvent

protected abstract void onCatchGotoBranchEvent(BranchFlow.GotoBranchEvent ev)
Process the caught GotoBranchEvent. The event's m_action usually contains data that is used to adjust the condition used by branch(). This lets the sub-flow that threw the event to control which branch is taken.

Parameters:
ev - the caught event.