[jbpm-dev] build a process with groovy

Tom Baeyens tbaeyens at redhat.com
Thu Apr 16 06:46:52 EDT 2009


indeed funny.
but can you also explain the purpose ?

regards, tom.


chen jian wrote:
> I wrote a very easy groovy class to build a pvm process, it's funny.
> 
>     * class:
> 
> 
> import groovy.util.BuilderSupport;
> 
> /**
>  * ProcessBuilder
>  * @author Kent Chen
>  *
>  */
> public class ProcessBuilder extends BuilderSupport {
>     def processDefinition
>     def unsuredFlows = []
>    
>     def createNode(Object name) {
>         return createNode(name, null, null)
>     }
> 
>     def createNode(Object name, Object value) {
>         return createNode(name, null, value)
>     }
> 
>     def createNode(Object name, Map attributes) {
>         return createNode(name, attributes, null)
>     }
> 
>     def createNode(Object name, Map attributes, Object value) {
>         if(name == "process"){
>             processDefinition = new ProcessDefinitionImpl(name:value)
>             return processDefinition
>         }
>        
>         if(name == "activity"){
>             def activity = new ActivityImpl(name:attributes.name 
> <http://attributes.name>,activityBehaviour:attributes.activityBehaviour)
>             processDefinition.addActivity(activity)
>             return activity
>         }
>        
>         if(name == "transition"){
>             def transition = current.createOutgoingTransition()
>             transition.name <http://transition.name> = attributes.name 
> <http://attributes.name>
>             unsuredFlows.add(new 
> UnsuredFlow(transition:transition,to:attributes.to <http://attributes.to>))
>             return "transition"
>         }
>        
>         if(name == "initial"){
>             return "initial"
>         }
>        
>         return name;
>     }
> 
>     def void setParent(Object parent, Object child) {
>     }
> 
>     def void nodeCompleted(Object parent, Object node) {
>         if(node == "initial"){
>             processDefinition.setInitial(parent)
>         }
>        
>         if(parent == null){
>             for(unsuredFlow in unsuredFlows){
>                 def activity = 
> processDefinition.findActivity(unsuredFlow.to)
>                 activity.addIncomingTransition(unsuredFlow.transition)
>             }
>         }
>     }
> }
> 
> class UnsuredFlow {
>     TransitionImpl transition
>     String to
> }
> 
>     * usage:
> 
> def builder = new ProcessBuilder()
>         builder.process("helloProcess"){
>             activity(name:"1",activityBehaviour:new TakeBehaviour()){
>                 initial()
>                 transition(name:"t1",to:"2")
>                 transition(name:"t2",to:"3")
>             }
>             activity(name:"2",activityBehaviour:new WaitState())
>             activity(name:"3",activityBehaviour:new WaitState()){ 
>                 transition(name:"t3",to:"4") 
>             }
>             activity(name:"4",activityBehaviour:new WaitState())
>         }
>        
>         def processInstance = 
> builder.processDefinition.startProcessInstance()
>         processInstance.signal("t2");
>         processInstance.signal();
>         processInstance.signal();
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> jbpm-dev mailing list
> jbpm-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jbpm-dev

-- 
regards, tom.




More information about the jbpm-dev mailing list