|
Spring Web Flow | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.webflow.core.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 drive 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 quintessential 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 occurrence 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. 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
analogous to a Java class, defining all the behavior of an application module. The core behaviors
start
, resume(RequestControlContext)
,
on event
,
end
, and
handleException(FlowExecutionException, RequestControlContext)
. Each method accepts 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 analogous to a java object that is an instance of a
class.
State
,
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.core.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 |
addVariable(FlowVariable variable)
Adds a flow variable. |
void |
addVariables(FlowVariable... variables)
Adds flow variables. |
boolean |
containsState(java.lang.String stateId)
Is a state with the provided id present in this flow? |
static Flow |
create(java.lang.String id,
AttributeMap<?> attributes)
Create a new flow with the given id and attributes. |
void |
destroy()
Destroy this flow definition, releasing any resources. |
void |
end(RequestControlContext context,
java.lang.String outcome,
MutableAttributeMap<?> output)
Inform this flow definition that an execution session of itself has ended. |
boolean |
equals(java.lang.Object o)
|
org.springframework.context.ApplicationContext |
getApplicationContext()
Returns a reference to application context hosting application objects and services used by this flow definition. |
java.lang.ClassLoader |
getClassLoader()
Returns the class loader used by this flow definition to load classes. |
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. |
TransitionDefinition |
getGlobalTransition(java.lang.String eventId)
Returns the transition that matches the event with the provided id. |
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. |
Mapper |
getInputMapper()
Returns the configured flow input mapper, or null if none. |
Mapper |
getOutputMapper()
Returns the configured flow output mapper, or null if none. |
java.lang.String[] |
getPossibleOutcomes()
Returns the outcomes that are possible for this flow to reach. |
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 |
getVariable(java.lang.String name)
Returns the flow variable with the given name. |
FlowVariable[] |
getVariables()
Returns the flow variables. |
boolean |
handleEvent(RequestControlContext context)
Handle the last event that occurred against an active session of this flow. |
boolean |
handleException(FlowExecutionException exception,
RequestControlContext context)
Handle an exception that occurred during an execution of this flow. |
int |
hashCode()
|
boolean |
inDevelopment()
Returns true if this flow definition is currently in development (running in development mode). |
void |
restoreVariables(RequestContext context)
|
void |
resume(RequestControlContext context)
Resume a paused session for this flow in its current view state. |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Sets a reference to the application context hosting application objects needed by this flow. |
void |
setInputMapper(Mapper inputMapper)
Sets the mapper to map flow input attributes. |
void |
setOutputMapper(Mapper 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 . |
void |
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.core.AnnotatedObject |
---|
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.core.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 static Flow create(java.lang.String id, AttributeMap<?> attributes)
id
- the flow idattributes
- the attributes
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
public java.lang.String[] getPossibleOutcomes()
FlowDefinition
getPossibleOutcomes
in interface FlowDefinition
public java.lang.ClassLoader getClassLoader()
FlowDefinition
getClassLoader
in interface FlowDefinition
public org.springframework.context.ApplicationContext getApplicationContext()
FlowDefinition
getApplicationContext
in interface FlowDefinition
public boolean inDevelopment()
FlowDefinition
inDevelopment
in interface FlowDefinition
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 getVariable(java.lang.String name)
name
- the name of the variablepublic FlowVariable[] getVariables()
public Mapper getInputMapper()
public void setInputMapper(Mapper inputMapper)
inputMapper
- the input mapperpublic ActionList getStartActionList()
public ActionList getEndActionList()
public Mapper getOutputMapper()
public void setOutputMapper(Mapper outputMapper)
outputMapper
- the output mapperpublic FlowExecutionExceptionHandlerSet getExceptionHandlerSet()
public TransitionSet getGlobalTransitionSet()
public TransitionDefinition getGlobalTransition(java.lang.String eventId)
eventId
- the event id
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
applicationContext
- the application contextpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void start(RequestControlContext context, MutableAttributeMap<?> input) throws FlowExecutionException
addVariable(FlowVariable)
) in flow scope.setInputMapper(Mapper)
).getStartActionList()
).setStartState(State)
)
context
- the flow execution control contextinput
- eligible input into the session
FlowExecutionException
- when an exception occurs starting the flowpublic void resume(RequestControlContext context) throws FlowExecutionException
context
- the flow execution control context
FlowExecutionException
- when an exception occurs during the resume operationpublic boolean handleEvent(RequestControlContext context)
context
- the flow execution control contextpublic void end(RequestControlContext context, java.lang.String outcome, MutableAttributeMap<?> output) throws FlowExecutionException
getEndActionList()
).setOutputMapper(Mapper)
).
context
- the flow execution control contextoutcome
- the logical flow outcome that will be returned by the session, generally the id of the terminating
end stateoutput
- initial output produced by the session that is eligible for modification by this method
FlowExecutionException
- when an exception occurs ending this flowpublic void destroy()
FlowDefinition
destroy
in interface FlowDefinition
public boolean handleException(FlowExecutionException exception, RequestControlContext context) throws FlowExecutionException
exception
- the exception that occurredcontext
- the flow execution control context
FlowExecutionException
public void restoreVariables(RequestContext context)
public java.lang.String toString()
toString
in class java.lang.Object
|
Spring Web Flow | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |