1 package org.andromda.cartridges.bpm4struts.metafacades;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.LinkedHashSet;
7 import java.util.List;
8 import java.util.Set;
9 import org.andromda.metafacades.uml.FrontEndAction;
10 import org.andromda.metafacades.uml.FrontEndUseCase;
11 import org.andromda.metafacades.uml.TransitionFacade;
12 import org.andromda.metafacades.uml.UMLProfile;
13 import org.andromda.metafacades.uml.UseCaseFacade;
14 import org.apache.commons.lang.StringUtils;
15
16
17
18
19
20
21
22 public class StrutsFinalStateLogicImpl
23 extends StrutsFinalStateLogic
24 {
25 private static final long serialVersionUID = 34L;
26
27
28
29
30 public StrutsFinalStateLogicImpl(
31 Object metaObject,
32 String context)
33 {
34 super(metaObject, context);
35 }
36
37
38
39
40 public String getName()
41 {
42 String name = super.getName();
43
44 if (name == null)
45 {
46 final UseCaseFacade useCase = this.getTargetUseCase();
47 if (useCase != null)
48 {
49 name = useCase.getName();
50 }
51 }
52
53 return name;
54 }
55
56
57
58
59 protected String handleGetFullPath()
60 {
61 String fullPath = null;
62
63 final StrutsUseCase useCase = (StrutsUseCase)this.getTargetUseCase();
64 if (useCase == null)
65 {
66
67 final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_EXTERNAL_HYPERLINK);
68 if (taggedValue == null)
69 {
70 String name = getName();
71 if (StringUtils.isNotBlank(name) && ((name.charAt(0) == '/') || name.startsWith("http://")))
72 {
73 fullPath = name;
74 }
75 }
76 else
77 {
78 fullPath = String.valueOf(taggedValue);
79 }
80 }
81 else
82 {
83 fullPath = useCase.getActionPath() + ".do";
84 }
85 return fullPath;
86 }
87
88
89
90
91
92
93
94 public FrontEndUseCase getTargetUseCase()
95 {
96 FrontEndUseCase targetUseCase = null;
97
98
99 final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_MODEL_HYPERLINK);
100 if (taggedValue != null)
101 {
102 if (taggedValue instanceof StrutsActivityGraph)
103 {
104 targetUseCase = (FrontEndUseCase)((StrutsActivityGraph)taggedValue).getUseCase();
105 }
106 else if (taggedValue instanceof StrutsUseCase)
107 {
108 targetUseCase = (FrontEndUseCase)taggedValue;
109 }
110 }
111
112
113 if (targetUseCase == null)
114 {
115 final String name = super.getName();
116 if (StringUtils.isNotBlank(name))
117 {
118 UseCaseFacade useCase = getModel().findUseCaseByName(name);
119 if (useCase instanceof FrontEndUseCase)
120 {
121 targetUseCase = (FrontEndUseCase)useCase;
122 }
123 }
124 }
125 return targetUseCase;
126 }
127
128
129
130
131
132
133 public List<FrontEndAction> getActions()
134 {
135 return handleGetActions();
136 }
137
138
139
140
141
142
143
144
145 protected List<FrontEndAction> handleGetActions()
146 {
147 Set<FrontEndAction> actions = new LinkedHashSet<FrontEndAction>();
148 Collection<TransitionFacade> incomings = this.getIncomings();
149
150 for (final Iterator<TransitionFacade> incomingIterator = incomings.iterator(); incomingIterator.hasNext();)
151 {
152 StrutsForward forward = (StrutsForward)incomingIterator.next();
153 actions.addAll(forward.getActions());
154 }
155 return new ArrayList<FrontEndAction>(actions);
156 }
157 }