KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > websale > ShipItem


1 package org.jbpm.websale;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.jbpm.context.exe.ContextInstance;
6 import org.jbpm.graph.def.ActionHandler;
7 import org.jbpm.graph.exe.ExecutionContext;
8 import org.jbpm.taskmgmt.def.Swimlane;
9 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
10 import org.jbpm.taskmgmt.exe.SwimlaneInstance;
11 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
12
13 public class ShipItem implements ActionHandler {
14
15   private static final long serialVersionUID = 1L;
16   
17   String JavaDoc swimlane;
18   String JavaDoc msg;
19
20   public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
21     TaskMgmtDefinition taskMgmtDefinition = executionContext.getProcessDefinition().getTaskMgmtDefinition();
22     TaskMgmtInstance taskMgmtInstance = executionContext.getTaskMgmtInstance();
23     ContextInstance contextInstance = executionContext.getContextInstance();
24     
25     Swimlane shipperSwimlane = taskMgmtDefinition.getSwimlane("shipper");
26     SwimlaneInstance shipperSwimlaneInstance = taskMgmtInstance.getInitializedSwimlaneInstance(executionContext, shipperSwimlane);
27
28     String JavaDoc actorId = shipperSwimlaneInstance.getActorId();
29     
30     String JavaDoc displayMsg = replace(msg, "${"+swimlane+"}", actorId);
31     displayMsg = replace(displayMsg, "${item}", (String JavaDoc)contextInstance.getVariable("item"));
32     displayMsg = replace(displayMsg, "${address}", (String JavaDoc)contextInstance.getVariable("address"));
33     
34     log.info("###############################################");
35     log.info("### "+displayMsg);
36     log.info("###############################################");
37     
38     executionContext.leaveNode();
39   }
40
41   static String JavaDoc replace(String JavaDoc msg, String JavaDoc pattern, String JavaDoc replacement) {
42     String JavaDoc replaced = null;
43     int pos = msg.indexOf(pattern);
44     if (pos!=-1) {
45       replaced = msg.substring(0,pos)
46                  +replacement
47                  +msg.substring(pos+pattern.length());
48     }
49     return replaced;
50   }
51   
52   private static final Log log = LogFactory.getLog(ShipItem.class);
53 }
54
Popular Tags