org.springframework.webflow.engine.builder.xml
Class XmlFlowBuilder

java.lang.Object
  extended by org.springframework.webflow.engine.builder.BaseFlowBuilder
      extended by org.springframework.webflow.engine.builder.xml.XmlFlowBuilder
All Implemented Interfaces:
FlowBuilder, ResourceHolder

public class XmlFlowBuilder
extends BaseFlowBuilder
implements ResourceHolder

Flow builder that builds flows as defined in an XML document. The XML document should adhere to the following format:

     <?xml version="1.0" encoding="UTF-8"?>
     <flow xmlns="http://www.springframework.org/schema/webflow"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/webflow
                               http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
         <!-- Define your states here -->
     </flow>
 

Consult the web flow XML schema for more information on the XML-based flow definition format.

This builder will setup a flow-local bean factory for the flow being constructed. That flow-local bean factory will be populated with XML bean definitions contained in files referenced using the "import" element. The flow-local bean factory will use the bean factory defing this flow builder as a parent. As such, the flow can access artifacts in either its flow-local bean factory or in the parent bean factory hierarchy, e.g. the bean factory of the dispatcher.

Author:
Erwin Vervaet, Keith Donald

Field Summary
protected  org.springframework.core.io.Resource location
          The resource from which the document element being parsed was read.
 
Constructor Summary
XmlFlowBuilder(org.springframework.core.io.Resource location)
          Create a new XML flow builder parsing the document at the specified location.
XmlFlowBuilder(org.springframework.core.io.Resource location, FlowServiceLocator flowServiceLocator)
          Create a new XML flow builder parsing the document at the specified location, using the provided service locator to access externally managed flow artifacts.
 
Method Summary
 void buildEndActions()
          Builds any end actions to execute when the flow ends.
 void buildExceptionHandlers()
          Creates and adds all exception handlers to the flow built by this builder.
 void buildGlobalTransitions()
          Builds any transitions shared by all states of the flow.
 void buildInlineFlows()
          Builds any "in-line" flows encapsulated by the flow.
 void buildInputMapper()
          Builds the input mapper responsible for mapping flow input on start.
 void buildOutputMapper()
          Builds the output mapper responsible for mapping flow output on end.
 void buildStartActions()
          Builds any start actions to execute when the flow starts.
 void buildStates()
          Builds the states of the flow.
 void buildVariables()
          Builds any variables initialized by the flow when it starts.
protected  org.springframework.beans.factory.BeanFactory createLocalBeanFactory(Flow flow, org.springframework.core.io.Resource[] resources)
          Create a bean factory serving as a local flow service registry.
 void dispose()
          Shutdown the builder, releasing any resources it holds.
protected  org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Element ele, java.lang.String childEleName)
          Utility method that returns the first child element identified by its name.
protected  org.w3c.dom.Document getDocument()
          Returns the DOM document parsed from the XML file.
protected  org.w3c.dom.Element getDocumentElement()
          Returns the root document element.
protected  FlowArtifactFactory getFlowArtifactFactory()
          Returns the artifact factory of the flow service locator local to this builder.
protected  FlowServiceLocator getLocalFlowServiceLocator()
          Returns the flow service locator local to this builder.
 org.springframework.core.io.Resource getLocation()
          Returns the resource from which the document element was loaded.
 org.springframework.core.io.Resource getResource()
          Returns the flow definition resource held by this holder.
 void init(java.lang.String id, AttributeMap attributes)
          Initialize this builder.
protected  boolean nodeNameEquals(org.w3c.dom.Node node, java.lang.String desiredName)
          Namespace-aware equals comparison.
protected  void registerLocalBeans(Flow flow, org.springframework.beans.factory.config.ConfigurableBeanFactory beanFactory)
          Register beans in the bean factory local to the flow definition being built.
 void setDocumentLoader(DocumentLoader documentLoader)
          Sets the loader that will load the XML-based flow definition document.
 void setLocation(org.springframework.core.io.Resource location)
          Sets the resource from which the document element was loaded.
 java.lang.String toString()
           
 
Methods inherited from class org.springframework.webflow.engine.builder.BaseFlowBuilder
fromStringTo, fromStringTo, getFlow, getFlowServiceLocator, setFlow, setFlowServiceLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

location

protected org.springframework.core.io.Resource location
The resource from which the document element being parsed was read. Used as a location for relative resource lookup.

Constructor Detail

XmlFlowBuilder

public XmlFlowBuilder(org.springframework.core.io.Resource location)
Create a new XML flow builder parsing the document at the specified location.

Parameters:
location - the location of the XML-based flow definition resource

XmlFlowBuilder

public XmlFlowBuilder(org.springframework.core.io.Resource location,
                      FlowServiceLocator flowServiceLocator)
Create a new XML flow builder parsing the document at the specified location, using the provided service locator to access externally managed flow artifacts.

Parameters:
location - the location of the XML-based flow definition resource
flowServiceLocator - the locator for services needed by this builder to build its Flow
Method Detail

getLocation

public org.springframework.core.io.Resource getLocation()
Returns the resource from which the document element was loaded. This is used for location relative loading of other resources.


setLocation

public void setLocation(org.springframework.core.io.Resource location)
Sets the resource from which the document element was loaded. This is used for location relative loading of other resources.


setDocumentLoader

public void setDocumentLoader(DocumentLoader documentLoader)
Sets the loader that will load the XML-based flow definition document. Optional, defaults to DefaultDocumentLoader.

Parameters:
documentLoader - the document loader

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

init

public void init(java.lang.String id,
                 AttributeMap attributes)
          throws FlowBuilderException
Description copied from interface: FlowBuilder
Initialize this builder. This could cause the builder to open a stream to an externalized resource representing the flow definition, for example.

Specified by:
init in interface FlowBuilder
Specified by:
init in class BaseFlowBuilder
Parameters:
id - the identifier to assign to the flow
attributes - custom attributes to assign to the flow
Throws:
FlowBuilderException - an exception occured building the flow

buildVariables

public void buildVariables()
                    throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds any variables initialized by the flow when it starts.

Specified by:
buildVariables in interface FlowBuilder
Overrides:
buildVariables in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildInputMapper

public void buildInputMapper()
                      throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds the input mapper responsible for mapping flow input on start.

Specified by:
buildInputMapper in interface FlowBuilder
Overrides:
buildInputMapper in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildStartActions

public void buildStartActions()
                       throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds any start actions to execute when the flow starts.

Specified by:
buildStartActions in interface FlowBuilder
Overrides:
buildStartActions in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildInlineFlows

public void buildInlineFlows()
                      throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds any "in-line" flows encapsulated by the flow.

Specified by:
buildInlineFlows in interface FlowBuilder
Overrides:
buildInlineFlows in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildStates

public void buildStates()
                 throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds the states of the flow.

Specified by:
buildStates in interface FlowBuilder
Specified by:
buildStates in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildGlobalTransitions

public void buildGlobalTransitions()
                            throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds any transitions shared by all states of the flow.

Specified by:
buildGlobalTransitions in interface FlowBuilder
Overrides:
buildGlobalTransitions in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildEndActions

public void buildEndActions()
                     throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds any end actions to execute when the flow ends.

Specified by:
buildEndActions in interface FlowBuilder
Overrides:
buildEndActions in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildOutputMapper

public void buildOutputMapper()
                       throws FlowBuilderException
Description copied from interface: FlowBuilder
Builds the output mapper responsible for mapping flow output on end.

Specified by:
buildOutputMapper in interface FlowBuilder
Overrides:
buildOutputMapper in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building the flow

buildExceptionHandlers

public void buildExceptionHandlers()
                            throws FlowBuilderException
Description copied from interface: FlowBuilder
Creates and adds all exception handlers to the flow built by this builder.

Specified by:
buildExceptionHandlers in interface FlowBuilder
Overrides:
buildExceptionHandlers in class BaseFlowBuilder
Throws:
FlowBuilderException - an exception occured building this flow

dispose

public void dispose()
Description copied from interface: FlowBuilder
Shutdown the builder, releasing any resources it holds. A new flow construction process should start with another call to the FlowBuilder.init(String, AttributeMap) method.

Specified by:
dispose in interface FlowBuilder
Overrides:
dispose in class BaseFlowBuilder

getResource

public org.springframework.core.io.Resource getResource()
Description copied from interface: ResourceHolder
Returns the flow definition resource held by this holder.

Specified by:
getResource in interface ResourceHolder

getDocument

protected org.w3c.dom.Document getDocument()
Returns the DOM document parsed from the XML file.


getDocumentElement

protected org.w3c.dom.Element getDocumentElement()
Returns the root document element.


getLocalFlowServiceLocator

protected FlowServiceLocator getLocalFlowServiceLocator()
Returns the flow service locator local to this builder.


getFlowArtifactFactory

protected FlowArtifactFactory getFlowArtifactFactory()
Returns the artifact factory of the flow service locator local to this builder.


getChildElementByTagName

protected org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Element ele,
                                                       java.lang.String childEleName)
Utility method that returns the first child element identified by its name.

Parameters:
ele - the DOM element to analyze
childEleName - the child element name to look for
Returns:
the org.w3c.dom.Element instance, or null if none found

nodeNameEquals

protected boolean nodeNameEquals(org.w3c.dom.Node node,
                                 java.lang.String desiredName)
Namespace-aware equals comparison. Returns true if either Node.getLocalName() or Node.getNodeName() equals desiredName, otherwise returns false.


createLocalBeanFactory

protected org.springframework.beans.factory.BeanFactory createLocalBeanFactory(Flow flow,
                                                                               org.springframework.core.io.Resource[] resources)
Create a bean factory serving as a local flow service registry.

Parameters:
flow - the current flow definition being built
resources - the file resources to assemble the bean factory from; typically XML-based
Returns:
the bean factory
Since:
1.0.4

registerLocalBeans

protected void registerLocalBeans(Flow flow,
                                  org.springframework.beans.factory.config.ConfigurableBeanFactory beanFactory)
Register beans in the bean factory local to the flow definition being built.

Subclasses may override this metod to customize the population of the bean factory local to the flow definition being built; for example, to register mock implementations of services in a test environment.

Parameters:
flow - the current flow definition being built
beanFactory - the bean factory; register local beans with it using SingletonBeanRegistry.registerSingleton(String, Object)
Since:
1.0.4


Copyright © 2004-2007. All Rights Reserved.