|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.webflow.engine.AnnotatedObject
org.springframework.webflow.engine.Flow
public class Flow
A single flow definition. A Flow definition is a reusable, self-contained controller module that provides the blue print for a user dialog or conversation. Flows typically orchestrate controlled navigations within web applications to guide users through fulfillment of a business process/goal that takes place over a series of steps, modeled as states.
A simple Flow definition could do nothing more than execute an action and display a view all in one request. A more elaborate Flow definition may be long-lived and execute across a series of requests, invoking many possible paths, actions, and subflows.
Especially in Intranet applications there are often "controlled navigations" where the user is not free to do what he or she wants but must follow the guidelines provided by the system to complete a process that is transactional in nature (the quinessential example would be a 'checkout' flow of a shopping cart application). This is a typical use case appropriate to model as a flow.
Structurally a Flow is composed of a set of states. A State
is a point in a flow where a behavior is
executed; for example, showing a view, executing an action, spawning a subflow, or terminating the flow. Different
types of states execute different behaviors in a polymorphic fashion.
Each TransitionableState
type has one or more transitions that when executed move a flow to another state.
These transitions define the supported paths through the flow.
A state transition is triggered by the occurence of an event. An event is something that happens the flow should respond to, for example a user input event like ("submit") or an action execution result event like ("success"). When an event occurs in a state of a Flow that event drives a state transition that decides what to do next.
Each Flow has exactly one start state. A start state is simply a marker noting the state executions of this Flow definition should start in. The first state added to the flow will become the start state by default.
Flow definitions may have one or more flow exception handlers. A FlowExecutionExceptionHandler
can execute
custom behavior in response to a specific exception (or set of exceptions) that occur in a state of one of this
flow's executions.
Instances of this class are typically built by FlowBuilder
implementations but may also be directly instantiated.
This class and the rest of the Spring Web Flow (SWF) engine have been designed with minimal dependencies on other libraries. Spring Web Flow is usable in a standalone fashion (as well as in the context of other frameworks like Spring MVC, Struts, or JSF, for example). The engine system is fully usable outside an HTTP servlet environment, for example in portlets, tests, or standalone applications. One of the major architectural benefits of Spring Web Flow is the ability to design reusable, high-level controller modules that may be executed in any environment.
Note: flows are singleton definition objects so they should be thread-safe. You can think a flow definition as
analagous somewhat to a Java class, defining all the behavior of an application module. The core behaviors
start
, on event
,
and end
each accept a request context
that allows for this flow to access execution state in a thread safe manner. A flow execution is what models a
running instance of this flow definition, somewhat analgous to a java object that is an instance of a class.
State
,
TransitionableState
,
ActionState
,
ViewState
,
SubflowState
,
EndState
,
DecisionState
,
Transition
,
FlowExecutionExceptionHandler
Field Summary | |
---|---|
protected org.apache.commons.logging.Log |
logger
Logger, can be used in subclasses. |
Fields inherited from class org.springframework.webflow.engine.AnnotatedObject |
---|
CAPTION_PROPERTY, DESCRIPTION_PROPERTY |
Constructor Summary | |
---|---|
Flow(java.lang.String id)
Construct a new flow definition with the given id. |
Method Summary | |
---|---|
protected void |
add(State state)
Add given state definition to this flow definition. |
void |
addInlineFlow(Flow flow)
Adds an inline flow to this flow. |
void |
addVariable(FlowVariable variable)
Adds a flow variable. |
void |
addVariables(FlowVariable[] variables)
Adds flow variables. |
boolean |
containsInlineFlow(java.lang.String id)
Tests if this flow contains an in-line flow with the specified id. |
boolean |
containsState(java.lang.String stateId)
Is a state with the provided id present in this flow? |
void |
end(RequestControlContext context,
MutableAttributeMap output)
Inform this flow definition that an execution session of itself has ended. |
boolean |
equals(java.lang.Object o)
|
ActionList |
getEndActionList()
Returns the list of actions executed by this flow when an execution of the flow ends. |
FlowExecutionExceptionHandlerSet |
getExceptionHandlerSet()
Returns the set of exception handlers, allowing manipulation of how exceptions are handled when thrown during flow execution. |
TransitionSet |
getGlobalTransitionSet()
Returns the set of transitions eligible for execution by this flow if no state-level transition is matched. |
java.lang.String |
getId()
Returns the unique id of this flow. |
Flow |
getInlineFlow(java.lang.String id)
Returns the inline flow with the provided id, or null if no such inline flow exists. |
int |
getInlineFlowCount()
Returns the count of registered inline flows. |
java.lang.String[] |
getInlineFlowIds()
Returns the list of inline flow ids. |
Flow[] |
getInlineFlows()
Returns the list of inline flows. |
org.springframework.binding.mapping.AttributeMapper |
getInputMapper()
Returns the configured flow input mapper, or null if none. |
org.springframework.binding.mapping.AttributeMapper |
getOutputMapper()
Returns the configured flow output mapper, or null if none. |
ActionList |
getStartActionList()
Returns the list of actions executed by this flow when an execution of the flow starts. |
StateDefinition |
getStartState()
Return this flow's starting point. |
StateDefinition |
getState(java.lang.String stateId)
Returns the state definition with the specified id. |
int |
getStateCount()
Returns the number of states defined in this flow. |
java.lang.String[] |
getStateIds()
Convenience accessor that returns an ordered array of the String ids for the state definitions
associated with this flow definition. |
State |
getStateInstance(java.lang.String stateId)
Lookup the identified state instance of this flow. |
TransitionableState |
getTransitionableState(java.lang.String stateId)
Return the TransitionableState with given stateId . |
FlowVariable[] |
getVariables()
Returns the flow variables. |
ViewSelection |
handleException(FlowExecutionException exception,
RequestControlContext context)
Handle an exception that occured during an execution of this flow. |
int |
hashCode()
|
ViewSelection |
onEvent(RequestControlContext context)
Inform this flow definition that an event was signaled in the current state of an active flow execution. |
protected void |
setId(java.lang.String id)
Set the unique id of this flow. |
void |
setInputMapper(org.springframework.binding.mapping.AttributeMapper inputMapper)
Sets the mapper to map flow input attributes. |
void |
setOutputMapper(org.springframework.binding.mapping.AttributeMapper outputMapper)
Sets the mapper to map flow output attributes. |
void |
setStartState(State state)
Set the start state for this flow to the state provided; any state may be the start state. |
void |
setStartState(java.lang.String stateId)
Set the start state for this flow to the state with the provided stateId ; a state must exist by
the provided stateId . |
ViewSelection |
start(RequestControlContext context,
MutableAttributeMap input)
Start a new session for this flow in its start state. |
java.lang.String |
toString()
|
Methods inherited from class org.springframework.webflow.engine.AnnotatedObject |
---|
getAttributeMap, getAttributes, getCaption, getDescription, setCaption, setDescription |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.springframework.webflow.definition.Annotated |
---|
getAttributes, getCaption, getDescription |
Field Detail |
---|
protected final org.apache.commons.logging.Log logger
Constructor Detail |
---|
public Flow(java.lang.String id)
id
- the flow identifierMethod Detail |
---|
public java.lang.String getId()
FlowDefinition
getId
in interface FlowDefinition
public StateDefinition getStartState()
FlowDefinition
getStartState
in interface FlowDefinition
public StateDefinition getState(java.lang.String stateId)
FlowDefinition
getState
in interface FlowDefinition
stateId
- the state id
protected void setId(java.lang.String id)
protected void add(State state) throws java.lang.IllegalArgumentException
state
- the state to add
java.lang.IllegalArgumentException
- when the state cannot be added to the flow; for instance if another state shares
the same id as the one provided or if given state already belongs to another flowpublic int getStateCount()
public boolean containsState(java.lang.String stateId)
stateId
- the state id
public void setStartState(java.lang.String stateId) throws java.lang.IllegalArgumentException
stateId
; a state must exist by
the provided stateId
.
stateId
- the id of the new start state
java.lang.IllegalArgumentException
- when no state exists with the id you providedpublic void setStartState(State state) throws java.lang.IllegalArgumentException
state
- the new start state
java.lang.IllegalArgumentException
- given state has not been added to this flowpublic TransitionableState getTransitionableState(java.lang.String stateId) throws java.lang.IllegalArgumentException, java.lang.ClassCastException
TransitionableState
with given stateId
.
stateId
- id of the state to look up
java.lang.IllegalArgumentException
- if the identified state cannot be found
java.lang.ClassCastException
- when the identified state is not transitionablepublic State getStateInstance(java.lang.String stateId) throws java.lang.IllegalArgumentException
stateId
- the state id
java.lang.IllegalArgumentException
- if the identified state cannot be foundpublic java.lang.String[] getStateIds()
ids
for the state definitions
associated with this flow definition.
public void addVariable(FlowVariable variable)
variable
- the variablepublic void addVariables(FlowVariable[] variables)
variables
- the variablespublic FlowVariable[] getVariables()
public org.springframework.binding.mapping.AttributeMapper getInputMapper()
public void setInputMapper(org.springframework.binding.mapping.AttributeMapper inputMapper)
inputMapper
- the input mapperpublic ActionList getStartActionList()
public ActionList getEndActionList()
public org.springframework.binding.mapping.AttributeMapper getOutputMapper()
public void setOutputMapper(org.springframework.binding.mapping.AttributeMapper outputMapper)
outputMapper
- the output mapperpublic FlowExecutionExceptionHandlerSet getExceptionHandlerSet()
public void addInlineFlow(Flow flow)
flow
- the inline flow to addpublic java.lang.String[] getInlineFlowIds()
public Flow[] getInlineFlows()
public int getInlineFlowCount()
public boolean containsInlineFlow(java.lang.String id)
id
- the inline flow id
public Flow getInlineFlow(java.lang.String id) throws java.lang.IllegalArgumentException
null
if no such inline flow exists.
id
- the inline flow id
java.lang.IllegalArgumentException
- when an invalid flow id is providedpublic TransitionSet getGlobalTransitionSet()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public ViewSelection start(RequestControlContext context, MutableAttributeMap input) throws FlowExecutionException
addVariable(FlowVariable)
) in flow scope.setInputMapper(AttributeMapper)
).getStartActionList()
).setStartState(State)
)
context
- the flow execution control contextinput
- eligible input into the session
FlowExecutionException
- when an exception occurs starting the flowpublic ViewSelection onEvent(RequestControlContext context) throws FlowExecutionException
RequestContext.getLastEvent()
).
context
- the flow execution control context
FlowExecutionException
- when an exception occurs processing the eventpublic void end(RequestControlContext context, MutableAttributeMap output) throws FlowExecutionException
getEndActionList()
).setOutputMapper(AttributeMapper)
).
context
- the flow execution control contextoutput
- initial output produced by the session that is eligible for modification by this method
FlowExecutionException
- when an exception occurs ending this flowpublic ViewSelection handleException(FlowExecutionException exception, RequestControlContext context) throws FlowExecutionException
exception
- the exception that occuredcontext
- the flow execution control context
null
if no handler matched or returned a non-null view
selection
FlowExecutionException
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |