org.speakright.core.flows
Class SRApp

java.lang.Object
  extended by org.speakright.core.FlowBase
      extended by org.speakright.core.flows.BasicFlow
          extended by org.speakright.core.flows.SRApp
All Implemented Interfaces:
java.io.Serializable, IFlow
Direct Known Subclasses:
App, InteractiveTester.App2, TestSRApp.TestApp1, TestSRApp.TestApp2, TestSRApp.TestApp3, TestWebServlet2.MyApp, TestYesNo.YesNoApp

public class SRApp
extends BasicFlow

The base class for the outermost "app" flow object. It is the application, and it creates sub-flows that make up the callflow. Sub-flows can of course create their own sub-flows, creating a tree of flow objects with the "app" flow object at the root of the tree. Flow objects share data using a model, which is a field named M in each flow object class. The model contains application-defined data that needs to be shared among the flow objects. This class must handle all possible events, since it's an error for an event to bubble up the flow stack without being handled. Also implements a default fail approach of transferring to an "operator" -- a live person who can help the caller.

Author:
IanRaeLaptop
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.speakright.core.flows.BasicFlow
m_L
 
Constructor Summary
SRApp()
           
SRApp(java.lang.String name)
           
 
Method Summary
protected  IFlow createGoodbye()
          Return the final flow object, that is executed after the main loop exits.
protected  LoopFlow createMainLoop()
           
protected  IFlow createWelcome()
          Return the first flow object, which is usually a welcome prompt.
protected  LoopFlow getMainLoop()
          Get the loop flow returned by createMainLoop.
protected  void initMainLoop(LoopFlow flow)
          Return the main loop sub-flow.
protected  boolean isAppEvent(ThrowEvent event, java.lang.String eventName)
          Called from onCatch to determine if we're catching a given app-event
 void onBegin(IFlowContext context)
          Invokes getWelcome, getMainLoop, and getGoodbye.
 IFlow onCatch(IFlow current, SRResults results, java.lang.String eventName, ThrowEvent event)
          The default implementation of onCatch is to transfer to the operator.
 IFlow onDisconnect(IFlow current, SRResults results)
          The default implementation of onDisconnect is to transfer to the operator.
 IFlow onNoInput(IFlow current, SRResults results)
          The default implementation of onNoInput is to transfer to the operator.
 IFlow onPlatformError(IFlow current, SRResults results)
          The default implementation of onPlatformError is to transfer to the operator.
 IFlow onTransferFailed(IFlow current, SRResults results)
          The default implementation of onTransferFailed is to transfer to the operator.
 IFlow onValidateFailed(IFlow current, SRResults results)
          The default implementation of onValidateFailed is to transfer to the operator.
protected  IFlow transferToOperator()
          Transfer the call to the operator.
 
Methods inherited from class org.speakright.core.flows.BasicFlow
add, addPromptFlow, findSubFlow, getFirst, getNext, getSubFlowAfter, SubFlowCount
 
Methods inherited from class org.speakright.core.FlowBase
createRenderer, execute, executionCount, fixupGrammar, fixupPrompt, log, logError, name, onComplete, onEnd, promptGroup, setExecutionCount, setName, setPromptGroup, shouldExecute, validateInput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SRApp

public SRApp()

SRApp

public SRApp(java.lang.String name)
Method Detail

onBegin

public void onBegin(IFlowContext context)
Invokes getWelcome, getMainLoop, and getGoodbye. If you override this method you MUST call super.OnBegin

Specified by:
onBegin in interface IFlow
Overrides:
onBegin in class FlowBase

createWelcome

protected IFlow createWelcome()
Return the first flow object, which is usually a welcome prompt. Can return an entire sub-flow for welcome + login. This method is optional. The default version returns null. If you don't override this method then you must manually build the flow objects yourself in the constructure.

Returns:

createMainLoop

protected LoopFlow createMainLoop()

initMainLoop

protected void initMainLoop(LoopFlow flow)
Return the main loop sub-flow. Most apps have an infinite loop that presents a main menu. You can use the loop param passed in, or create one yourself. Populate it with flow objects and return the loop object. This method is optional. The default version returns null. If you don't override this method then you must manually build the flow objects yourself in the constructure.


getMainLoop

protected LoopFlow getMainLoop()
Get the loop flow returned by createMainLoop. Applications may want to re-run the main loop, perhaps as part of catching an event. They can call this method to get the main loop object.

Returns:

createGoodbye

protected IFlow createGoodbye()
Return the final flow object, that is executed after the main loop exits. This final flow object usually is a goodbye prompt. This method is optional. The default version returns null. If you don't override this method then you must manually build the flow objects yourself in the constructure.

Returns:

isAppEvent

protected boolean isAppEvent(ThrowEvent event,
                             java.lang.String eventName)
Called from onCatch to determine if we're catching a given app-event

Parameters:
event -
eventName - name of the app event
Returns:
true if event matches eventName

transferToOperator

protected IFlow transferToOperator()
Transfer the call to the operator. Since there is no standard way to do this (what DN? blind or bridged? etc) The default implementation is to do nothing. Override this method and provide your own transfer.

Returns:

onDisconnect

public IFlow onDisconnect(IFlow current,
                          SRResults results)
The default implementation of onDisconnect is to transfer to the operator.

Specified by:
onDisconnect in interface IFlow
Overrides:
onDisconnect in class FlowBase
Parameters:
current - the currently executing flow object.
results - the results of current's execution. In this case results will contain a Disconnect result code. User input may be present, if the caller spoke before hanging up. Some applications may want to process this final utterance before terminating.
Returns:
the next flow to run, or null which means this flow object does not handle this event.

onNoInput

public IFlow onNoInput(IFlow current,
                       SRResults results)
The default implementation of onNoInput is to transfer to the operator.

Specified by:
onNoInput in interface IFlow
Overrides:
onNoInput in class FlowBase
Parameters:
current - the currently executing flow object.
results - the results of current's execution. In this case results will contain a Disconnect result code. User input may be present, if the caller spoke before hanging up. Some applications may want to process this final utterance before terminating.
Returns:
the next flow to run, or null which means this flow object does not handle this event.

onCatch

public IFlow onCatch(IFlow current,
                     SRResults results,
                     java.lang.String eventName,
                     ThrowEvent event)
The default implementation of onCatch is to transfer to the operator.

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.

onPlatformError

public IFlow onPlatformError(IFlow current,
                             SRResults results)
The default implementation of onPlatformError is to transfer to the operator.

Specified by:
onPlatformError in interface IFlow
Overrides:
onPlatformError in class FlowBase
Parameters:
current - the currently executing flow object.
results - the results of current's execution. In this case results will contain a PlatformFailed result code.
Returns:
the next flow to run, or null which means this flow object does not handle this event.

onTransferFailed

public IFlow onTransferFailed(IFlow current,
                              SRResults results)
The default implementation of onTransferFailed is to transfer to the operator.

Specified by:
onTransferFailed in interface IFlow
Overrides:
onTransferFailed in class FlowBase
Parameters:
current - the currently executing flow object.
results - the results of current's execution. In this case results will contain a TransferFailed result code.
Returns:
the next flow to run, or null which means this flow object does not handle this event.

onValidateFailed

public IFlow onValidateFailed(IFlow current,
                              SRResults results)
The default implementation of onValidateFailed is to transfer to the operator.

Specified by:
onValidateFailed in interface IFlow
Overrides:
onValidateFailed in class FlowBase
Parameters:
current - the currently executing flow object.
results - the results of current's execution. In this case results will contain the user input that failed validation.
Returns:
the next flow to run, or null which means this flow object does not handle this event.