View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.bpm;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.lifecycle.Disposable;
11  import org.mule.api.lifecycle.Initialisable;
12  import org.mule.api.lifecycle.InitialisationException;
13  import org.mule.component.AbstractComponent;
14  import org.mule.config.i18n.MessageFactory;
15  
16  /**
17   * A service backed by the execution of a business process such as jBPM. 
18   */
19  public class ProcessComponent extends AbstractComponent
20  {
21      // Created internally
22      protected Process process;
23      
24      /** The underlying BPMS */
25      protected BPMS bpms;
26  
27      /** The logical name of the process.  This is used to look up the running process instance from the BPMS. */
28      private String name;
29      
30      /** The resource containing the process definition.  This will be used to deploy the process to the BPMS. */
31      private String resource;
32  
33      /** This field will be used to correlate messages with processes. */
34      private String processIdField;
35  
36      @Override
37      protected void doInitialise() throws InitialisationException
38      {
39          if (bpms == null)
40          {
41              try
42              {
43                  bpms = muleContext.getRegistry().lookupObject(BPMS.class);
44              }
45              catch (Exception e)
46              {
47                  throw new InitialisationException(e, this);
48              }
49          }
50          if (bpms == null)
51          {
52              throw new InitialisationException(MessageFactory.createStaticMessage("The bpms property must be set for this component."), this);
53          }
54          if (bpms instanceof Initialisable)
55          {
56              ((Initialisable) bpms).initialise();
57          }
58          
59          process = new Process(bpms, name, resource, flowConstruct, muleContext);
60          process.initialise();
61  
62          // Inject a callback so that the BPMS may generate messages within Mule.
63          bpms.setMessageService(process);        
64      }
65      
66      @Override
67      protected void doDispose()
68      {
69          if (bpms instanceof Disposable)
70          {
71              ((Disposable) bpms).dispose();
72          }
73  
74          process.dispose();
75          process = null;
76      }
77  
78      @Override
79      protected Object doInvoke(MuleEvent event) throws Exception
80      {
81          return process.processAction(event);
82      }
83  
84      protected Process getProcess()
85      {
86          return process;
87      }
88  
89      public String getName()
90      {
91          return name;
92      }
93  
94      public void setName(String name)
95      {
96          this.name = name;
97      }
98  
99      public void setResource(String resource)
100     {
101         this.resource = resource;
102     }
103 
104     public String getResource()
105     {
106         return resource;
107     }
108     
109     public String getProcessIdField()
110     {
111         return processIdField;
112     }
113 
114     public void setProcessIdField(String processIdField)
115     {
116         this.processIdField = processIdField;
117     }
118 
119     public BPMS getBpms()
120     {
121         return bpms;
122     }
123 
124     public void setBpms(BPMS bpms)
125     {
126         this.bpms = bpms;
127     }
128 }
129 
130