View Javadoc

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