1 package org.andromda.cartridges.bpm4struts.metafacades;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.Iterator;
7 import java.util.LinkedHashMap;
8 import java.util.LinkedHashSet;
9 import java.util.List;
10 import java.util.Map;
11 import java.util.Set;
12 import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile;
13 import org.andromda.metafacades.uml.EventFacade;
14 import org.andromda.metafacades.uml.GuardFacade;
15 import org.andromda.metafacades.uml.PseudostateFacade;
16 import org.andromda.metafacades.uml.StateVertexFacade;
17 import org.andromda.utils.StringUtilsHelper;
18 import org.apache.commons.lang.StringUtils;
19
20
21
22
23
24
25 public class StrutsForwardLogicImpl
26 extends StrutsForwardLogic
27 {
28 private static final long serialVersionUID = 34L;
29
30
31
32
33 public StrutsForwardLogicImpl(
34 Object metaObject,
35 String context)
36 {
37 super(metaObject, context);
38 }
39
40
41
42
43 protected String handleGetGuardName()
44 {
45 final GuardFacade guard = this.getGuard();
46 return (guard == null) ? null : guard.getName();
47 }
48
49
50
51
52 protected boolean handleIsEnteringPage()
53 {
54 return this.isEnteringView();
55 }
56
57
58
59
60 protected String handleGetForwardName()
61 {
62 return StringUtilsHelper.toResourceMessageKey(this.resolveName());
63 }
64
65
66
67
68 protected String handleGetForwardPath()
69 {
70 String forwardPath = null;
71
72 final StateVertexFacade target = this.getTarget();
73 if (isEnteringPage())
74 {
75 forwardPath = ((StrutsJsp)target).getFullPath() + ".jsp";
76 }
77 else if (isEnteringFinalState())
78 {
79 forwardPath = ((StrutsFinalState)target).getFullPath();
80 }
81
82 return forwardPath;
83 }
84
85
86
87
88 protected String handleGetActionMethodName()
89 {
90 return StringUtilsHelper.lowerCamelCaseName(this.resolveName());
91 }
92
93
94
95
96 protected String handleGetTargetNameKey()
97 {
98 if (this.isEnteringPage())
99 {
100 return ((StrutsJsp)this.getTarget()).getTitleKey();
101 }
102 else if (this.isEnteringFinalState())
103 {
104 return ((StrutsUseCase)((StrutsFinalState)this.getTarget()).getTargetUseCase()).getTitleKey();
105 }
106 return null;
107 }
108
109
110
111
112
113
114 private String resolveName()
115 {
116 String forwardName = null;
117
118 final EventFacade trigger = this.getTrigger();
119 if (trigger != null) forwardName = trigger.getName();
120
121 if (StringUtils.isEmpty(forwardName)) forwardName = this.getName();
122
123 if (StringUtils.isEmpty(forwardName)) forwardName = this.getTarget().getName();
124
125 if (StringUtils.isEmpty(forwardName)) forwardName = "unknown";
126
127 return forwardName;
128 }
129
130
131
132
133 protected boolean handleIsExitingPage()
134 {
135 return this.isExitingView();
136 }
137
138
139
140
141 protected boolean handleIsSuccessMessagesPresent()
142 {
143 return !this.getSuccessMessages().isEmpty();
144 }
145
146
147
148
149 protected boolean handleIsWarningMessagesPresent()
150 {
151 return !this.getWarningMessages().isEmpty();
152 }
153
154
155
156
157
158
159
160
161 private Map getMessages(String taggedValue)
162 {
163 Map messages;
164
165 final Collection taggedValues = this.findTaggedValues(taggedValue);
166 if (taggedValues.isEmpty())
167 {
168 messages = Collections.emptyMap();
169 }
170 else
171 {
172 messages = new LinkedHashMap();
173
174 for (final Iterator iterator = taggedValues.iterator(); iterator.hasNext();)
175 {
176 final String value = (String)iterator.next();
177 messages.put(StringUtilsHelper.toResourceMessageKey(value), value);
178 }
179 }
180
181 return messages;
182 }
183
184
185
186
187 protected Map handleGetSuccessMessages()
188 {
189 return this.getMessages(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_SUCCESS_MESSAGE);
190 }
191
192
193
194
195 protected Map handleGetWarningMessages()
196 {
197 return this.getMessages(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_WARNING_MESSAGE);
198 }
199
200
201
202
203 protected Object handleGetStrutsActivityGraph()
204 {
205 return this.getFrontEndActivityGraph();
206 }
207
208
209
210
211
212
213 public List getActions()
214 {
215 final Set actions = new LinkedHashSet();
216 this.findActions(actions, new LinkedHashSet());
217 return new ArrayList(actions);
218 }
219
220
221
222
223
224
225
226
227
228
229
230 private final void findActions(
231 final Set actions,
232 final Set handledForwards)
233 {
234 if (!handledForwards.contains(this))
235 {
236 handledForwards.add(this);
237
238 if (this instanceof StrutsAction)
239 {
240 actions.add(this);
241 }
242 else
243 {
244 final StateVertexFacade vertex = getSource();
245 if (vertex instanceof StrutsJsp)
246 {
247 final StrutsJsp jsp = (StrutsJsp)vertex;
248 actions.addAll(jsp.getActions());
249 }
250 else if (vertex instanceof StrutsActionState)
251 {
252 final StrutsActionState actionState = (StrutsActionState)vertex;
253 actions.addAll(actionState.getContainerActions());
254 }
255 else if (vertex instanceof PseudostateFacade)
256 {
257 final PseudostateFacade pseudostate = (PseudostateFacade)vertex;
258 if (!pseudostate.isInitialState())
259 {
260 final Collection incomingForwards = pseudostate.getIncomings();
261 for (final Iterator forwardIterator = incomingForwards.iterator(); forwardIterator.hasNext();)
262 {
263 final StrutsForward forward = (StrutsForward)forwardIterator.next();
264 actions.addAll(forward.getActions());
265 }
266 }
267 }
268 }
269 }
270 }
271 }