org.jbpm.pvm
Class ProcessFactory

java.lang.Object
  extended by org.jbpm.pvm.ProcessFactory

public class ProcessFactory
extends java.lang.Object

factory for process definitions.

Use this factory as a fluent interface for building a process definition. To use it in this way, start with instantiating a ProcessFactory object. Then a number of methods can be invoked concatenated with dots cause all the methods return the same process factory object. When done, end that sequence with done() to get the constructed ProcessDefinition.

The idea is that this results into a more compact and more readable code to build process definitions as opposed to including xml inline. For example :

     ProcessDefinition processDefinition = ProcessFactory.build()
         .initial().behaviour(new WaitState())
           .transition("normal").to("a")
           .transition("shortcut").to("c")
         .node("a").behaviour(new WaitState())
           .transition().to("b")
         .node("b").behaviour(new WaitState())
           .transition().to("c")
         .node("c").behaviour(new WaitState())
     .done();
 

If more control is needed over the creation of the process definition objects, then consider using the concrete implementation classes from package org.jbpm.pvm.impl directly. The implementation code of this class might be a good guide to get you on your way.

Author:
Tom Baeyens

Nested Class Summary
 class ProcessFactory.DestinationReference
           
 
Field Summary
protected  CompositeElementImpl compositeElement
           
protected  java.util.Stack<CompositeElementImpl> compositeElementStack
           
protected  java.util.List<ProcessFactory.DestinationReference> destinationReferences
           
protected  EventImpl event
           
protected  EventListenerReference eventListenerReference
           
protected  ExceptionHandlerImpl exceptionHandler
           
protected  NodeImpl node
           
protected  ObservableElementImpl observableElement
           
protected  ProcessDefinitionImpl processDefinition
           
protected  TransitionImpl transition
           
 
Constructor Summary
protected ProcessFactory()
          start building a process definition without a name.
protected ProcessFactory(java.lang.String processName)
          start building a process definition with the given name.
protected ProcessFactory(java.lang.String processName, ProcessDefinitionImpl processDefinition)
          start building a process definition with the given name.
 
Method Summary
 ProcessFactory asyncExecute()
          sets the asyncExecute property on the current node.
 ProcessFactory asyncLeave()
          sets the asyncLeave property on the current node.
 ProcessFactory asyncSignal()
          sets the asyncSignal property on the current node.
 ProcessFactory asyncTake()
          sets the takeAsync property on the current transition This method requires a current transition.
 ProcessFactory behaviour(Activity activity)
          sets the behaviour on the current node.
static ProcessFactory build()
          starts building a process definition
static ProcessFactory build(java.lang.String processName)
          starts building a process definition
static ProcessFactory build(java.lang.String processName, ProcessDefinitionImpl processDefinition)
          starts populating a given process definition
 ProcessFactory compositeEnd()
          ends a block in which nested nodes are created.
 ProcessFactory compositeNode()
          starts a block in which nested nodes can be created.
 ProcessFactory compositeNode(java.lang.String nodeName)
          starts a block in which nested nodes can be created.
 ProcessDefinition done()
          extract the process definition from the factory.
 ProcessFactory event(java.lang.String eventName)
          creates the given event on the current process element.
 ProcessFactory exceptionHandler(java.lang.Class<? extends java.lang.Exception> exceptionClass)
          creates an exception handler for the given exception class on the current process element; until the exceptionHandlerEnd().
 ProcessFactory exceptionHandlerEnd()
           
 ProcessFactory guardCondition(Condition condition)
          sets the guard condition on the current transition.
 ProcessFactory initial()
          marks the last created node as the initial node in the process.
protected  ProcessDefinitionImpl instantiateProcessDefinition()
          to be overwritten by specific process language factories
 ProcessFactory listener(Activity activity)
          adds an action to the current event.
 ProcessFactory listener(Descriptor descriptor)
          adds an action to the current event.
 ProcessFactory listener(java.lang.String expression)
          adds an action to the current event.
 ProcessFactory needsPrevious()
          sets the property needsPrevious on the current node.
 ProcessFactory node()
          creates a node in the current parent.
 ProcessFactory node(java.lang.String nodeName)
          creates a named node.
 ProcessFactory propagationDisabled()
          disables propagated events.
 ProcessFactory property(Descriptor descriptor)
          adds a configuration to the current process element
 ProcessFactory property(java.lang.String name, java.lang.String stringValue)
          adds a string-valued configuration to the current process element
 ProcessFactory to(java.lang.String destination)
          sets the destination node on the current transition.
 ProcessFactory transactional()
           
 ProcessFactory transition()
          creates a transition on the current node.
 ProcessFactory transition(java.lang.String transitionName)
          creates a named transition on the current node.
 ProcessFactory waitCondition(Condition condition)
          sets the wait condition on the current transition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

processDefinition

protected ProcessDefinitionImpl processDefinition

node

protected NodeImpl node

transition

protected TransitionImpl transition

destinationReferences

protected java.util.List<ProcessFactory.DestinationReference> destinationReferences

observableElement

protected ObservableElementImpl observableElement

event

protected EventImpl event

eventListenerReference

protected EventListenerReference eventListenerReference

exceptionHandler

protected ExceptionHandlerImpl exceptionHandler

compositeElement

protected CompositeElementImpl compositeElement

compositeElementStack

protected java.util.Stack<CompositeElementImpl> compositeElementStack
Constructor Detail

ProcessFactory

protected ProcessFactory()
start building a process definition without a name.


ProcessFactory

protected ProcessFactory(java.lang.String processName)
start building a process definition with the given name.


ProcessFactory

protected ProcessFactory(java.lang.String processName,
                         ProcessDefinitionImpl processDefinition)
start building a process definition with the given name.

Method Detail

build

public static ProcessFactory build()
starts building a process definition


build

public static ProcessFactory build(java.lang.String processName)
starts building a process definition


build

public static ProcessFactory build(java.lang.String processName,
                                   ProcessDefinitionImpl processDefinition)
starts populating a given process definition


instantiateProcessDefinition

protected ProcessDefinitionImpl instantiateProcessDefinition()
to be overwritten by specific process language factories


initial

public ProcessFactory initial()
marks the last created node as the initial node in the process.


node

public ProcessFactory node()
creates a node in the current parent. The current parent is either the process definition or a composite node in case method compositeNode(String) was called previously.


node

public ProcessFactory node(java.lang.String nodeName)
creates a named node. The current parent is either the process definition or a composite node in case method compositeNode(String) was called previously.


behaviour

public ProcessFactory behaviour(Activity activity)
sets the behaviour on the current node. A current node is required.


asyncExecute

public ProcessFactory asyncExecute()
sets the asyncExecute property on the current node. A current node is required.


asyncLeave

public ProcessFactory asyncLeave()
sets the asyncLeave property on the current node. A current node is required.


asyncSignal

public ProcessFactory asyncSignal()
sets the asyncSignal property on the current node. A current node is required.


needsPrevious

public ProcessFactory needsPrevious()
sets the property needsPrevious on the current node. A current node is required.


compositeNode

public ProcessFactory compositeNode()
starts a block in which nested nodes can be created. This block can be ended with compositeEnd(). A current node is required.


compositeNode

public ProcessFactory compositeNode(java.lang.String nodeName)
starts a block in which nested nodes can be created. This block can be ended with compositeEnd(). A current node is required.


compositeEnd

public ProcessFactory compositeEnd()
ends a block in which nested nodes are created. This method requires that a nested node block was started before with compositeNode(String)


transition

public ProcessFactory transition()
creates a transition on the current node. This method requires a current node


transition

public ProcessFactory transition(java.lang.String transitionName)
creates a named transition on the current node. This method requires a current node


asyncTake

public ProcessFactory asyncTake()
sets the takeAsync property on the current transition This method requires a current transition.


to

public ProcessFactory to(java.lang.String destination)
sets the destination node on the current transition. This method requires a current transition.


waitCondition

public ProcessFactory waitCondition(Condition condition)
sets the wait condition on the current transition. This method requires a current transition.


guardCondition

public ProcessFactory guardCondition(Condition condition)
sets the guard condition on the current transition. This method requires a current transition.


event

public ProcessFactory event(java.lang.String eventName)
creates the given event on the current process element. This method requires a process element. A process element is either a process definition or a node. This method doesn't need to be called for transitions. If you have exception handlers and listeners on an event, make sure that you put the invocations of exceptionHandler(Class) first.


exceptionHandler

public ProcessFactory exceptionHandler(java.lang.Class<? extends java.lang.Exception> exceptionClass)
creates an exception handler for the given exception class on the current process element; until the exceptionHandlerEnd(). Subsequent invocations of listeners or transitions will have the created exception handler as a target. DONT'T FORGET TO CLOSE THE EXCEPTION HANDLER WITH exceptionHandlerEnd.


exceptionHandlerEnd

public ProcessFactory exceptionHandlerEnd()

transactional

public ProcessFactory transactional()

listener

public ProcessFactory listener(Descriptor descriptor)
adds an action to the current event. The current event was either created by event(String) or by a transition(). Subsequent invocations of exceptionHandler(Class) will be associated to this event listener.


listener

public ProcessFactory listener(Activity activity)
adds an action to the current event. The current event was either created by event(String) or by a transition(). Subsequent invocations of exceptionHandler(Class) will be associated to this event listener.


listener

public ProcessFactory listener(java.lang.String expression)
adds an action to the current event. The current event was either created by event(String) or by a transition(). Subsequent invocations of exceptionHandler(Class) will be associated to this event listener.


propagationDisabled

public ProcessFactory propagationDisabled()
disables propagated events. This means that this action will only be executed if the event is fired on the actual process element of the event. The current action will not be executed if an event is fired on one of the children of the process element to which this event relates.


property

public ProcessFactory property(java.lang.String name,
                               java.lang.String stringValue)
adds a string-valued configuration to the current process element


property

public ProcessFactory property(Descriptor descriptor)
adds a configuration to the current process element


done

public ProcessDefinition done()
extract the process definition from the factory. This should be the last method in the chain of subsequent invoked methods on this factory object.