|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface IFlow
IFlow is the basic building block of SpeakRight. A flow object generates VoiceXML pages, and also manages control flow in the application. In MVC terms, a flow object is both a view and a controller. Flow objects are similar to controls in a GUI application; they encapsulate some user interface behaviour.
IFlow objects can contain child IFlow objects (called sub-flows). Everything from the lowest-level prompt-block to a complete SpeakRight application is an IFlow. IFlow classes are Serializable so that SpeakRight can save & restore state between HTTP requests. Mark any fields transient that you don't want to be persisted.
| Method Summary | |
|---|---|
IFlowRenderer |
createRenderer()
|
void |
execute(IExecutionContext context)
Generates a VoiceXML page, which is sent to the speech platform for execution. |
int |
executionCount()
The number of times this flow has been executed (in the current activation). |
Grammar |
fixupGrammar(Grammar gram)
Callback that lets a flow object do any adjustments on grammars. |
java.lang.String |
fixupPrompt(java.lang.String item)
Callback that lets a flow object do any adjustments on prompt text. |
IFlow |
getFirst(IFlowContext context)
Gets the first sub-flow to be executed. |
IFlow |
getNext(IFlow current,
SRResults results)
Gets the next flow object to be executed. |
IFlow |
getSubFlowAfter(IFlow subFlow)
Return the next sub-flow after subFlow. |
java.lang.String |
name()
Name of the flow object, used for logging and (optionally) as a means of finding flow objects. |
void |
onBegin(IFlowContext context)
The first method called when a flow is executed. |
IFlow |
onCatch(IFlow current,
SRResults results,
java.lang.String eventName,
ThrowEvent event)
Event handler for custom events. |
boolean |
onComplete()
Do any side-effects that should be done when the flow finishes, such as updating a database. |
IFlow |
onDisconnect(IFlow current,
SRResults results)
Event handler for a disconnect event. |
void |
onEnd(IFlowContext context)
The last method called when a flow is executed. |
IFlow |
onNoInput(IFlow current,
SRResults results)
Event handler for the no-input event. |
IFlow |
onPlatformError(IFlow current,
SRResults results)
Event handler for a error returned by the speech platform. |
IFlow |
onTransferFailed(IFlow current,
SRResults results)
Event handler for a failed transfer. |
IFlow |
onValidateFailed(IFlow current,
SRResults results)
Event handler for validation failed. |
java.lang.String |
promptGroup()
The prompt group prefix applies to prompt ids. |
void |
setExecutionCount(int count)
Used internally by SRInstance. |
void |
setPromptGroup(java.lang.String groupPrefix)
Set the prompt group prefix. |
boolean |
shouldExecute()
Used for optional sub-flows. |
boolean |
validateInput(java.lang.String input,
SRResults results)
Validates user input. |
| Method Detail |
|---|
java.lang.String name()
Name should be a descriptive single word, such as "AskFlightNumber". Question flows should begin with a verb such as "Ask", and output flows should begin with a verb such as "Say".
If the name is not specified by the developer, a flow's default name is the class name, for example, org.foobar.flightapp.AskFlightNumber. Names do not need to be unique.
void execute(IExecutionContext context)
Execute may choose to generate no content; this is called an "empty" flow object. Execute may also choose to generate a flow event. This is used for error conditions where the application can't proceed and needs to jump to a different flow. For example, Execute may want to access a web service to play weather information. If the web service is down, a flow event can be thrown.
context - Contains the page renderer.IFlow getFirst(IFlowContext context)
Returning null is not allowed. Some exceptions to this exist; BasicFlow supports "optional" sub-flows where a sub-flow returns null from getFirst to indicate that it doesn't wish to run. However the outer flow object (BasicFlow) ensures that its getFirst never returns null.
getFirst may be called more than once per activation (see BasicFlow).
IFlow getNext(IFlow current,
SRResults results)
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.
void onBegin(IFlowContext context)
void onEnd(IFlowContext context)
IFlow onDisconnect(IFlow current,
SRResults results)
The SRApp class provides a default implementation that returns an ExitEvent.
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.
IFlow onNoInput(IFlow current,
SRResults results)
No-Input only applies if the VoiceXML has active grammars. An output only page does not generate this event.
SRApp provides a default implementation that transfers the call to the operator. In some cases, No-Input is a valid event. For example, a flow object that reads a long weather bulletin may be listening for "stop" or "cancel". If the caller listens to the whole bulletin without speaking, a No-Input will be returned. The application ignores the No-Input by overriding onNoInput in the flow object, and having it return its normal getNext value.
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.
IFlow onValidateFailed(IFlow current,
SRResults results)
The default implementation of onValidateFailed is to return this, which causes
the flow object to be executed again. The ExecutionCount field can
be used to detect re-execution, and generate a retry prompt. FlowBase provides
the default implemenation.
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.
IFlow onCatch(IFlow current,
SRResults results,
java.lang.String eventName,
ThrowEvent event)
Event handling in SpeakRight involves a search up the flow stack. First the currently
executing flow (current) is checked. If its event handler returns non-null
then the event has been handled. Otherwise the next flow object on the flow stack is checked,
up to the outermost flow object (the application flow object).
It is an error for an event not to be caught. SRApp provides default handlers for
all events.
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
IFlow onTransferFailed(IFlow current,
SRResults results)
The SRApp class provides a default implementation that transfers the call to an operator.
current - the currently executing flow object.results - the results of current's execution. In this case results will
contain a TransferFailed result code.
IFlow onPlatformError(IFlow current,
SRResults results)
The SRApp class provides a default implementation that transfers the call to an operator.
current - the currently executing flow object.results - the results of current's execution. In this case results will
contain a PlatformFailed result code.
boolean validateInput(java.lang.String input,
SRResults results)
FlowBase provides the default implementation, which simply returns true.
input - String value of the user input. For simple, single-value inputs, input
is sufficient. For more complicated user inputs, use the SML in results.results - Results containing the user input, including the SML, confidence vales, and
NBest information.
boolean onComplete()
IFlowRenderer createRenderer()
java.lang.String fixupPrompt(java.lang.String item)
item - the tts prompt item to be adjusted
Grammar fixupGrammar(Grammar gram)
gram - a grammar object
int executionCount()
void setExecutionCount(int count)
java.lang.String promptGroup()
For example, consider a SROLogin class that defines a common login behaviour. It has a prompt id "id:loginFailed" with a default prompt in its prompt XML file. If we use SROLogin several times in our app, we may want to customize the loginFailed prompt each time. Prompt groups allow this. If our first login flow object uses a prompt group of "logon", then the two-stage lookup is: first lookup "id:logon.loginFailed", then "id:loginFailed". Then in our application prompt XML file we'ld add a prompt for "login.loginFailed". Prompt groups are flexible because we can add to the application XML file at any time, without any code changes needed.
void setPromptGroup(java.lang.String groupPrefix)
groupPrefix - the prompt group prefix, or "*" which means uses the IFlow's name().IFlow getSubFlowAfter(IFlow subFlow)
subFlow -
boolean shouldExecute()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||