org.speakright.core
Class SRRunner

java.lang.Object
  extended by org.speakright.core.SRRunner

public class SRRunner
extends java.lang.Object

The main class in SpeakRight. This class is the runtime for a single instance (that is a single phone call). It takes an application flow object (which has sub-flows) and executes it, but asynchronously. Begin by calling start. Then call getContent to get the generated VoiceXML page. Send it off the the voicexml engine. Then passivate this object until the HTTP reply from the voicexml engine arrives. When it does, activate this object and call proceed, then call getContent to get the generated VoiceXML page. Send it off the the voicexml engine. Repeat until isFinished is true. This class wraps SRInstance to provide a safe public API.

Author:
IanRaeLaptop

Field Summary
static java.lang.String SPEAKRIGHT_VERSION
           
 
Constructor Summary
SRRunner()
           
 
Method Summary
 IFlow ApplicationFlow()
          Get the outermost flow object, that was passed to start.
 boolean failed(SRError parent)
          extracts any errors that this SRInstance object logged.
 void finishActivation()
          MUST be called after activating (restoring this object using serialization).
 void generateFinPage()
          Generate the final page for the application.
 java.lang.String getContent()
          Get the content (the VoiceXML page).
 SRInstance getImpl()
          For advance use only.
 boolean isFailed()
          Has an error ocurred yet.
 boolean isFinished()
          Has the application finished.
 boolean isPaused()
          Is the application paused.
 boolean isStarted()
          Has start been called.
 java.lang.String language()
          Get the current language
 SRLocations locations()
          Get the locations object, which holds directory and paths used by SpeakRight, such as the 'project dir'.
 void log(java.lang.String message)
          Log to SpeakRight's logger (currently is log4j)
 void prepareToPassivate()
          When saving state in a servlet, we're going to just save the whoe SRInstance object in the HttpSession.
 void proceed(SRResults results)
          Continue execution, using the given results that we returned by the voicexml platform to determine what flow is executed next.
 void registerPromptFile(java.lang.String path)
          Register a prompt file, for the duration of the call.
 void restoreModelBinder(IModelBinder binder)
           
 void resume()
          Resume (after pausing).
 boolean runAll(IFlow flow)
          used for unit tests only.
 void setContentLogging(java.lang.String dir)
           
 void setExtensionFactory(ISRExtensionFactory factory)
          Set the extension point factory.
 void setGrammarBaseUrl(java.lang.String url)
          Set the URL of grammar files.
 void setLanguage(java.lang.String lang)
          Set the current language.
 void setModelBinder(IModel model, IModelBinder binder)
           
 void setPromptBaseUrl(java.lang.String url)
          Set the URL of audio files.
 void setReturnUrl(java.lang.String url)
          Set the return url, which is used in the submit VoiceXML tag to POST the results of a page back.
 boolean start(IFlow flow)
          Start the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPEAKRIGHT_VERSION

public static final java.lang.String SPEAKRIGHT_VERSION
See Also:
Constant Field Values
Constructor Detail

SRRunner

public SRRunner()
Method Detail

getImpl

public SRInstance getImpl()
For advance use only.

Returns:

prepareToPassivate

public void prepareToPassivate()
When saving state in a servlet, we're going to just save the whoe SRInstance object in the HttpSession. But we need to clear the transient fields since they are not needed and are not serializable.


finishActivation

public void finishActivation()
MUST be called after activating (restoring this object using serialization). It re-initializes the SRInstance transient fields.


registerPromptFile

public void registerPromptFile(java.lang.String path)
Register a prompt file, for the duration of the call.

Parameters:
path -

setReturnUrl

public void setReturnUrl(java.lang.String url)
Set the return url, which is used in the submit VoiceXML tag to POST the results of a page back. For a java servlet, the return url is simply the servlet's URL.

Parameters:
url -

setGrammarBaseUrl

public void setGrammarBaseUrl(java.lang.String url)
Set the URL of grammar files. Any grammar urls in the app that are relative urls will have this url pre-pended.

Parameters:
url - usually a url within the java web application, such as "http://somecompany.com/speechapp1/grammar"

setPromptBaseUrl

public void setPromptBaseUrl(java.lang.String url)
Set the URL of audio files. Any audio urls in the app that are relative urls will have this url pre-pended.

Parameters:
url - usually a url within the java web application, such as "http://somecompany.com/speechapp1/audio"

log

public void log(java.lang.String message)
Log to SpeakRight's logger (currently is log4j)

Parameters:
message -

failed

public boolean failed(SRError parent)
extracts any errors that this SRInstance object logged.

Parameters:
parent - error object to copy error info into.
Returns:
true if any errors have occured.

ApplicationFlow

public IFlow ApplicationFlow()
Get the outermost flow object, that was passed to start.

Returns:

setExtensionFactory

public void setExtensionFactory(ISRExtensionFactory factory)
Set the extension point factory. This method is optional because SRInstance initializes itself to use a default factory. Use this method when you have created your own factory.

Parameters:
factory -

language

public java.lang.String language()
Get the current language

Returns:
language, such as "en-us"

setLanguage

public void setLanguage(java.lang.String lang)
Set the current language.

Parameters:
s - language, such as "en-us"

locations

public SRLocations locations()
Get the locations object, which holds directory and paths used by SpeakRight, such as the 'project dir'.

Returns:

isFailed

public boolean isFailed()
Has an error ocurred yet.

Returns:
true if error has ocurred.

start

public boolean start(IFlow flow)
Start the application.

Parameters:
flow - the application flow object.
Returns:
whether app was started successfully.

getContent

public java.lang.String getContent()
Get the content (the VoiceXML page). MUST be called immediately after start or proceed

Returns:
the generated voicexml page.

generateFinPage

public void generateFinPage()
Generate the final page for the application. This page terminates the call and the VoiceXML session.


resume

public void resume()
Resume (after pausing). Only used by async transactions (IFlow.onComplete).


isPaused

public boolean isPaused()
Is the application paused. Only used by async transactions (IFlow.onComplete)

Returns:

proceed

public void proceed(SRResults results)
Continue execution, using the given results that we returned by the voicexml platform to determine what flow is executed next.

Parameters:
results - results from the voicexml platform. These are the results of executing the previous page.

isFinished

public boolean isFinished()
Has the application finished.

Returns:
true if fin

isStarted

public boolean isStarted()
Has start been called.

Returns:
true if started.

setModelBinder

public void setModelBinder(IModel model,
                           IModelBinder binder)

restoreModelBinder

public void restoreModelBinder(IModelBinder binder)

setContentLogging

public void setContentLogging(java.lang.String dir)

runAll

public boolean runAll(IFlow flow)
used for unit tests only.

Parameters:
flow -
Returns: