1 package org.andromda.metafacades.uml14;
2
3 import java.util.Collection;
4 import java.util.LinkedHashSet;
5 import java.util.Set;
6 import org.andromda.metafacades.uml.ActivityGraphFacade;
7 import org.andromda.metafacades.uml.ClassifierFacade;
8 import org.andromda.metafacades.uml.UseCaseFacade;
9 import org.apache.commons.collections.Predicate;
10 import org.omg.uml.UmlPackage;
11 import org.omg.uml.behavioralelements.activitygraphs.ActionState;
12 import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
13 import org.omg.uml.behavioralelements.statemachines.CompositeState;
14 import org.omg.uml.behavioralelements.usecases.UseCase;
15 import org.omg.uml.foundation.core.ModelElement;
16
17
18
19
20
21 public class ModelFacadeLogicImpl
22 extends ModelFacadeLogic
23 {
24 private static final long serialVersionUID = 34L;
25
26
27
28
29
30 public ModelFacadeLogicImpl(
31 UmlPackage metaObject,
32 String context)
33 {
34 super(metaObject, context);
35 }
36
37
38
39
40 @Override
41 protected Object handleGetRootPackage()
42 {
43 Collection rootPackages = metaObject.getModelManagement().getModel().refAllOfType();
44 return rootPackages.iterator().next();
45 }
46
47
48
49
50 @Override
51 protected Collection handleGetAllActors()
52 {
53 return metaObject.getUseCases().getActor().refAllOfType();
54 }
55
56
57
58
59 @Override
60 protected Collection handleGetAllActionStates()
61 {
62 return metaObject.getActivityGraphs().getActionState().refAllOfType();
63 }
64
65
66
67
68 @Override
69 protected Collection handleGetAllUseCases()
70 {
71 return metaObject.getUseCases().getUseCase().refAllOfType();
72 }
73
74
75
76
77 @Override
78 protected Collection handleGetAllClasses()
79 {
80 return metaObject.getCore().getUmlClass().refAllOfType();
81 }
82
83
84
85
86 @Override
87 protected Collection handleGetAllObjectFlowStates()
88 {
89 return metaObject.getActivityGraphs().getObjectFlowState().refAllOfType();
90 }
91
92
93
94
95 @Override
96 protected UseCaseFacade handleFindUseCaseWithTaggedValueOrHyperlink(
97 String tag,
98 String value)
99 {
100 return (UseCaseFacade)shieldedElement(UML14MetafacadeUtils.findUseCaseWithTaggedValueOrHyperlink(tag, value));
101 }
102
103
104
105
106 @Override
107 protected ClassifierFacade handleFindClassWithTaggedValueOrHyperlink(
108 String tag,
109 String value)
110 {
111 return (ClassifierFacade)shieldedElement(UML14MetafacadeUtils.findClassWithTaggedValueOrHyperlink(tag, value));
112 }
113
114
115
116
117 @Override
118 protected ActivityGraphFacade handleFindActivityGraphByName(String name)
119 {
120 return (ActivityGraphFacade)shieldedElement(UML14MetafacadeUtils.findFirstActivityGraphWithName(name));
121 }
122
123
124
125
126 @Override
127 protected ActivityGraphFacade handleFindActivityGraphByNameAndStereotype(
128 String name,
129 String stereotypeName)
130 {
131 return (ActivityGraphFacade)shieldedElement(
132 UML14MetafacadeUtils.findFirstActivityGraphWithNameAndStereotype(name, stereotypeName));
133 }
134
135
136
137
138 @Override
139 protected UseCaseFacade handleFindUseCaseByName(String name)
140 {
141 return (UseCaseFacade)shieldedElement(UML14MetafacadeUtils.findFirstUseCaseWithName(name));
142 }
143
144
145
146
147 @Override
148 protected UseCaseFacade handleFindUseCaseWithNameAndStereotype(
149 String name,
150 String stereotypeName)
151 {
152 return (UseCaseFacade)shieldedElement(
153 UML14MetafacadeUtils.findFirstUseCaseWithNameAndStereotype(name, stereotypeName));
154 }
155
156
157
158
159 @Override
160 protected Collection handleFindFinalStatesWithNameOrHyperlink(UseCaseFacade useCase)
161 {
162 UseCase useCaseMetaClass = UML14MetafacadeUtils.getMetaClass(useCase);
163 return shieldedElements(UML14MetafacadeUtils.findFinalStatesWithNameOrHyperlink(useCaseMetaClass));
164 }
165
166
167
168
169 @Override
170 protected Collection handleGetAllActionStatesWithStereotype(
171 ActivityGraphFacade activityGraph,
172 String stereotypeName)
173 {
174 ActivityGraph activityGraphMetaClass = UML14MetafacadeUtils.getMetaClass(activityGraph);
175
176 CompositeState compositeState = (CompositeState)activityGraphMetaClass.getTop();
177 return filter(
178 compositeState.getSubvertex(),
179 new ActionStateWithStereotypeFilter(stereotypeName));
180 }
181
182
183
184
185 protected Collection handleGetAllTransitions()
186 {
187 return this.metaObject.getStateMachines().getTransition().refAllOfType();
188 }
189
190 private static final class ActionStateWithStereotypeFilter
191 implements Predicate
192 {
193 private String stereotypeName = null;
194
195 public ActionStateWithStereotypeFilter(final String stereotypeName)
196 {
197 this.stereotypeName = stereotypeName;
198 }
199
200 public boolean evaluate(final Object object)
201 {
202 return (object instanceof ActionState) &&
203 UML14MetafacadeUtils.isStereotypePresent((ModelElement)object, stereotypeName);
204 }
205 }
206
207 private Collection filter(
208 Collection collection,
209 Predicate collectionFilter)
210 {
211 final Set filteredCollection = new LinkedHashSet();
212 for (Object object : collection)
213 {
214 if (collectionFilter.evaluate(object))
215 {
216 filteredCollection.add(object);
217 }
218 }
219 return filteredCollection;
220 }
221 }