1
2
3
4
5 package gboat2.serviceflow.util;
6
7 import gboat2.serviceflow.Activator;
8 import gboat2.serviceflow.service.IEntryActionHandler;
9 import gboat2.serviceflow.service.IExitActionHandler;
10 import gboat2.serviceflow.service.IHandlerRegister;
11
12 import java.util.List;
13 import java.util.Map;
14
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceReference;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20
21
22
23
24
25
26
27
28
29 public class WorkflowUtil {
30
31 private static Logger logger = LoggerFactory.getLogger(WorkflowUtil.class);
32
33
34
35
36
37
38
39
40
41
42 public static void onEntryAction(String processId, String businessObjectId, String nodeName, Map<String, Object> params) {
43 try {
44 logger.info("on Entry Action! businessObjectId:" + businessObjectId + ",nodeName:" + nodeName);
45 BundleContext context = Activator.LOCAL_BUNDLE.getBundleContext();
46 ServiceReference sr = context.getServiceReference(IHandlerRegister.class.getName());
47 if (sr != null) {
48 IHandlerRegister register = (IHandlerRegister) context.getService(sr);
49 if (register != null) {
50 List<IEntryActionHandler> handlers = register.getEntryActionHandlers();
51 if (handlers.size() == 0) {
52 logger.warn("no IEntryActionHanlder is registed.");
53 }
54 for (IEntryActionHandler handler : handlers) {
55 try {
56 if(handler.accept(processId, businessObjectId, nodeName, params)){
57 logger.info("trigger " + handler.getClass().getName() + " ... ");
58 handler.action(processId, businessObjectId, nodeName, params);
59 }
60 } catch (Exception e) {
61 logger.error("error while call hanlder{"+handler.getClass().getName()+"}", e);
62 }
63 }
64 } else {
65 logger.error("IHandlerRegister cann't find in gboat2.serviceflow.It must be there.");
66 }
67 } else {
68 logger.error("IHandlerRegister cann't find in gboat2.serviceflow.It must be there.");
69 }
70 } catch (Exception e) {
71 logger.error("WorkflowUtil onEntryAction Exception!!!", e);
72 }
73 }
74
75
76
77
78
79
80
81
82
83
84 public static void onExitAction(String processId, String businessObjectId, String nodeName, Map<String, Object> params) {
85 logger.info("on Exit Action ! businessObjectId:" + businessObjectId + ",nodeName:" + nodeName);
86 BundleContext context = Activator.LOCAL_BUNDLE.getBundleContext();
87 ServiceReference sr = context.getServiceReference(IHandlerRegister.class.getName());
88 if (sr != null) {
89 IHandlerRegister register = (IHandlerRegister) context.getService(sr);
90 if (register != null) {
91 List<IExitActionHandler> handlers = register.getExitActionHandlers();
92 if (handlers.size() == 0) {
93 logger.warn("no IExitActionHanlder is registed.");
94 }
95 for (IExitActionHandler handler : handlers) {
96 try {
97 if(handler.accept(processId, businessObjectId, nodeName, params)){
98 logger.info("trigger " + handler.getClass().getName() + " ... ");
99 handler.action(processId, businessObjectId,nodeName,params);
100 }
101 } catch (Exception e) {
102 logger.error("error while call hanlder{"+handler.getClass().getName()+"}", e);
103 }
104 }
105 } else {
106 logger.error("IHandlerRegister cann't find in gboat2.serviceflow.It must be there.");
107 }
108 } else {
109 logger.error("IHandlerRegister cann't find in gboat2.serviceflow.It must be there.");
110 }
111 }
112 }