1 package org.andromda.cartridges.jbpm.metafacades;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import org.andromda.metafacades.uml.ActivityGraphFacade;
6 import org.andromda.metafacades.uml.EventFacade;
7 import org.andromda.metafacades.uml.StateFacade;
8 import org.andromda.metafacades.uml.StateMachineFacade;
9 import org.andromda.metafacades.uml.TransitionFacade;
10 import org.andromda.utils.StringUtilsHelper;
11 import org.apache.commons.lang.StringUtils;
12
13
14
15
16
17
18 public class JBpmHandlerLogicImpl
19 extends JBpmHandlerLogic
20 {
21 private static final long serialVersionUID = 34L;
22
23
24
25
26 public JBpmHandlerLogicImpl(Object metaObject, String context)
27 {
28 super(metaObject, context);
29 }
30
31
32
33
34 protected boolean handleIsContainedInBusinessProcess()
35 {
36 return this.getOwner().getStateMachineContext() instanceof ActivityGraphFacade &&
37 ((ActivityGraphFacade)this.getOwner().getStateMachineContext()).getUseCase()
38 instanceof JBpmProcessDefinition;
39 }
40
41
42
43
44 protected boolean handleIsAssignmentHandler()
45 {
46 boolean assignmentHandler = false;
47
48 final List actions = internalJBpmActions();
49 for (int i = 0; i < actions.size() && !assignmentHandler; i++)
50 {
51 final JBpmAction action = (JBpmAction)actions.get(i);
52 assignmentHandler = action.isTask();
53 }
54
55 return assignmentHandler;
56 }
57
58
59
60
61 protected boolean handleIsActionHandler()
62 {
63 boolean actionHandler = false;
64
65 final List actions = internalJBpmActions();
66 for (int i = 0; i < actions.size() && !actionHandler; i++)
67 {
68 final JBpmAction action = (JBpmAction)actions.get(i);
69 actionHandler =
70 action.isAfterSignal() || action.isBeforeSignal() || action.isNodeEnter() || action.isNodeLeave() ||
71 action.isTimer();
72 }
73
74 return actionHandler;
75 }
76
77 private List<EventFacade> internalActions = null;
78
79 private List<EventFacade> internalJBpmActions()
80 {
81 if (this.internalActions == null)
82 {
83 internalActions = new ArrayList<EventFacade>();
84 final StateMachineFacade stateMachine = getOwner().getStateMachineContext();
85 if (stateMachine instanceof ActivityGraphFacade)
86 {
87 final ActivityGraphFacade graph = (ActivityGraphFacade)stateMachine;
88 for (final StateFacade state : graph.getStates())
89 {
90 for (final EventFacade event : state.getDeferrableEvents())
91 {
92 if (event instanceof JBpmAction)
93 {
94 final JBpmAction action = (JBpmAction)event;
95 if (this.equals(action.getOperation()))
96 {
97 internalActions.add(event);
98 }
99 }
100 }
101 }
102
103 for (final TransitionFacade transition : graph.getTransitions())
104 {
105 final EventFacade event = transition.getTrigger();
106 if (event != null)
107 {
108 if (event instanceof JBpmAction)
109 {
110 final JBpmAction action = (JBpmAction)event;
111 if (this.equals(action.getOperation()))
112 {
113 internalActions.add(event);
114 }
115 }
116 }
117 }
118 }
119 }
120
121 return internalActions;
122 }
123
124
125
126
127 protected String handleGetHandlerPackageName()
128 {
129 return this.getOwner().getPackageName();
130 }
131
132
133
134
135 protected String handleGetHandlerFullPath()
136 {
137 return StringUtils.replace(this.getClazz(), ".", "/");
138 }
139
140
141
142
143 protected String handleGetHandlerClassName()
144 {
145 return StringUtilsHelper.upperCamelCaseName(this.getName());
146 }
147
148
149
150
151 protected String handleGetClazz()
152 {
153 String handlerClass = null;
154
155 final StringBuilder clazzBuffer = new StringBuilder();
156 if (StringUtils.isNotBlank(this.getHandlerPackageName()))
157 {
158 clazzBuffer.append(this.getHandlerPackageName());
159 clazzBuffer.append('.');
160 }
161 clazzBuffer.append(this.getHandlerClassName());
162 handlerClass = clazzBuffer.toString();
163
164 return handlerClass;
165 }
166 }