org.speakright.core
Class ModelBinder

java.lang.Object
  extended by org.speakright.core.ModelBinder
All Implemented Interfaces:
IModelBinder

public class ModelBinder
extends java.lang.Object
implements IModelBinder

ModelBinder binds user input to values in the model. When a flow object executes it can add bindings for slots in the SML that the speech platform will return. If the speech platform returns user input, the bindings are used to assign the user input data to values(s) in the model.

For example, a flow might ask the user for a city name, and tell SpeakRight to bind the SML slot "city" to the model value City (that is, M.City()).

Author:
Ian Rae

Field Summary
 java.util.ArrayList m_L
           
 IModel m_model
           
 
Constructor Summary
ModelBinder()
          used for serialization
ModelBinder(IModel m)
          Constructor
 
Method Summary
 void addBinding(IFlow flow, java.lang.String slotName, java.lang.String propName)
          adds a binding.
 void bind(IFlow current, SRResults results)
          Looks for and applies any data binding.
 boolean failed(SRError parent)
          extracts any errors that the model binder logged.
 java.util.ArrayList getBindings()
          Gets list of BindingSpec objects.
 IModel getModel()
          Get the model object.
 java.lang.String getModelValue(java.lang.String modelVar)
          Get the value of the given model variable.
 void injectModel(IFlow flow)
          A type-agnostic way to assign a model to a flow object.
 void setBindings(java.util.ArrayList bindingL)
          Sets list of BindingSpec objects.
 void setModel(IModel model)
          Set the model object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_model

public IModel m_model

m_L

public java.util.ArrayList m_L
Constructor Detail

ModelBinder

public ModelBinder(IModel m)
Constructor

Parameters:
m - the application's model object.

ModelBinder

public ModelBinder()
used for serialization

Method Detail

failed

public boolean failed(SRError parent)
Description copied from interface: IModelBinder
extracts any errors that the model binder logged.

Specified by:
failed in interface IModelBinder
Parameters:
parent - error object to copy error info into.
Returns:
true if any errors have occured.

getModel

public IModel getModel()
Description copied from interface: IModelBinder
Get the model object. Each instance of a SpeakRight application has a singleton model. This method is used for serialization.

Specified by:
getModel in interface IModelBinder
Returns:
the model object.

setModel

public void setModel(IModel model)
Description copied from interface: IModelBinder
Set the model object. This method is used after restoring the SpeakRight persistent state from the previous HTTP request.

Specified by:
setModel in interface IModelBinder
Parameters:
model - the application instance's model

injectModel

public void injectModel(IFlow flow)
A type-agnostic way to assign a model to a flow object. Flow classes can either have a model or not. If they do, the SpeakRight convention is that the model be a field called M. injectModel finds M and assigns it to the binder's model.

The injection is not done until the flow is executed. Flow objects must only reference their M field from within getFirst, getNext, execute, or an event handler.

injectModel uses reflection to find and assign to M. This frees SpeakRight from having to know about the application-defined Model class.

Specified by:
injectModel in interface IModelBinder
Parameters:
flow - the flow to inject the model into.

addBinding

public void addBinding(IFlow flow,
                       java.lang.String slotName,
                       java.lang.String propName)
adds a binding. addBinding must only be called from within a flow's execute method. More than one binding can be added if the VoiceXML will be collecting multi-value SML.

Specified by:
addBinding in interface IModelBinder
Parameters:
flow - the flow object currently executing.
slotName - the SML slot name that will contain the user input value to be bound
propName - the model property name to bind the data to.

bind

public void bind(IFlow current,
                 SRResults results)
Looks for and applies any data binding.

Specified by:
bind in interface IModelBinder
Parameters:
current - the flow whose results are in results
results - the results from executing current's VoiceXML page.

getModelValue

public java.lang.String getModelValue(java.lang.String modelVar)
Get the value of the given model variable. A SpeakRight model (generated by MGen) uses a consistent approach where each model variable has a field which is-a IModelItem (having get,set, and clear methods)

Specified by:
getModelValue in interface IModelBinder
Parameters:
modelVar - name of the model variable (eg. "city")
Returns:
model variable's value, as a string.

getBindings

public java.util.ArrayList getBindings()
Gets list of BindingSpec objects. This method is used for SR persistence across HTTP requests.

Specified by:
getBindings in interface IModelBinder
Returns:

setBindings

public void setBindings(java.util.ArrayList bindingL)
Sets list of BindingSpec objects. This method is used for SR persistence across HTTP requests.

Specified by:
setBindings in interface IModelBinder