1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
package org.argouml.model.euml; |
14 | |
|
15 | |
import java.util.ArrayList; |
16 | |
import java.util.Collection; |
17 | |
import java.util.HashSet; |
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.argouml.model.ModelManagementHelper; |
21 | |
import org.eclipse.emf.ecore.EObject; |
22 | |
import org.eclipse.uml2.uml.Classifier; |
23 | |
import org.eclipse.uml2.uml.Collaboration; |
24 | |
import org.eclipse.uml2.uml.Element; |
25 | |
import org.eclipse.uml2.uml.Model; |
26 | |
import org.eclipse.uml2.uml.NamedElement; |
27 | |
import org.eclipse.uml2.uml.Namespace; |
28 | |
import org.eclipse.uml2.uml.PackageableElement; |
29 | |
import org.eclipse.uml2.uml.VisibilityKind; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
class ModelManagementHelperEUMLImpl implements ModelManagementHelper { |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
private EUMLModelImplementation modelImpl; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public ModelManagementHelperEUMLImpl( |
48 | 0 | EUMLModelImplementation implementation) { |
49 | 0 | modelImpl = implementation; |
50 | 0 | } |
51 | |
|
52 | |
public Collection getAllBehavioralFeatures(Object ns) { |
53 | 0 | return modelImpl.getCoreHelper().getAllBehavioralFeatures(ns); |
54 | |
} |
55 | |
|
56 | |
@SuppressWarnings("unchecked") |
57 | |
public Collection getAllContents(Object element) { |
58 | 0 | if (!(element instanceof Element)) { |
59 | 0 | throw new IllegalArgumentException( |
60 | |
"The argument must be instance of Element"); |
61 | |
} |
62 | 0 | Collection result = new HashSet(); |
63 | 0 | if (element instanceof Collaboration) { |
64 | |
|
65 | |
} |
66 | 0 | if (element instanceof Classifier) { |
67 | 0 | result.addAll(((Classifier) element).allFeatures()); |
68 | |
} |
69 | 0 | if (element instanceof Namespace) { |
70 | 0 | result.addAll(((Namespace) element).getMembers()); |
71 | |
} |
72 | 0 | if (element instanceof org.eclipse.uml2.uml.Package) { |
73 | 0 | result.addAll(((org.eclipse.uml2.uml.Package) element).getPackagedElements()); |
74 | 0 | org.eclipse.uml2.uml.Package p = ((org.eclipse.uml2.uml.Package) element).getNestingPackage(); |
75 | 0 | while (p != null) { |
76 | 0 | for (PackageableElement e : p.getPackagedElements()) { |
77 | 0 | if (e.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { |
78 | 0 | result.add(e); |
79 | |
} |
80 | |
} |
81 | 0 | p = p.getNestingPackage(); |
82 | |
} |
83 | |
} |
84 | 0 | return result; |
85 | |
} |
86 | |
|
87 | |
public Collection getAllImportedElements(Object pack) { |
88 | |
|
89 | 0 | return null; |
90 | |
} |
91 | |
|
92 | |
public Collection getAllModelElementsOfKind(Object nsa, Object type) { |
93 | 0 | if (!(nsa instanceof Element)) { |
94 | 0 | return new ArrayList<Element>(); |
95 | |
} |
96 | 0 | Class theType = null; |
97 | 0 | if (type instanceof String) { |
98 | |
try { |
99 | 0 | theType = Class.forName((String) type); |
100 | 0 | } catch (ClassNotFoundException e) { |
101 | 0 | throw new IllegalArgumentException(e); |
102 | 0 | } |
103 | 0 | } else if (type instanceof Class) { |
104 | 0 | theType = (Class) type; |
105 | |
} else { |
106 | 0 | throw new IllegalArgumentException( |
107 | |
"type must be instance of Class or String"); |
108 | |
} |
109 | 0 | if (!Element.class.isAssignableFrom(theType)) { |
110 | 0 | throw new IllegalArgumentException( |
111 | |
"type must represent an Element"); |
112 | |
} |
113 | |
|
114 | 0 | Collection<Element> result = new ArrayList<Element>(); |
115 | |
|
116 | 0 | for (Element element : ((Namespace) nsa).allOwnedElements()) { |
117 | 0 | if (theType.isAssignableFrom(element.getClass())) { |
118 | 0 | result.add(element); |
119 | |
} |
120 | |
} |
121 | |
|
122 | 0 | return result; |
123 | |
} |
124 | |
|
125 | |
public Collection getAllModelElementsOfKind(Object nsa, String kind) { |
126 | 0 | return getAllModelElementsOfKind(nsa, kind); |
127 | |
} |
128 | |
|
129 | |
public Collection getAllModelElementsOfKindWithModel(Object model, |
130 | |
Object type) { |
131 | 0 | if (!(model instanceof Model)) { |
132 | 0 | throw new IllegalArgumentException( |
133 | |
"model must be instance of Model"); |
134 | |
} |
135 | 0 | if (!(type instanceof Class)) { |
136 | 0 | throw new IllegalArgumentException( |
137 | |
"type must be instance of java.lang.Class"); |
138 | |
} |
139 | 0 | Class kind = (Class) type; |
140 | 0 | Collection ret = getAllModelElementsOfKind(model, kind); |
141 | 0 | if (kind.isAssignableFrom(model.getClass())) { |
142 | 0 | ret = new ArrayList(ret); |
143 | 0 | if (!ret.contains(model)) { |
144 | 0 | ret.add(model); |
145 | |
} |
146 | |
} |
147 | 0 | return ret; |
148 | |
} |
149 | |
|
150 | |
public Collection getAllNamespaces(Object ns) { |
151 | 0 | return getAllModelElementsOfKind(ns, Namespace.class); |
152 | |
} |
153 | |
|
154 | |
public Collection getAllPossibleImports(Object pack) { |
155 | |
|
156 | 0 | return null; |
157 | |
} |
158 | |
|
159 | |
public Collection getAllSubSystems(Object ns) { |
160 | |
|
161 | 0 | return null; |
162 | |
} |
163 | |
|
164 | |
public Collection getAllSurroundingNamespaces(Object element) { |
165 | 0 | if (!(element instanceof NamedElement)) { |
166 | 0 | throw new IllegalArgumentException( |
167 | |
"element must be instance of NamedElement"); |
168 | |
} |
169 | 0 | return ((NamedElement) element).allNamespaces(); |
170 | |
} |
171 | |
|
172 | |
@SuppressWarnings("unchecked") |
173 | |
public Collection getContents(Object element) { |
174 | 0 | if (!(element instanceof Element)) { |
175 | 0 | throw new IllegalArgumentException( |
176 | |
"element must be instance of Element"); |
177 | |
} |
178 | 0 | Collection result = new HashSet(); |
179 | 0 | if (element instanceof Namespace) { |
180 | 0 | result.addAll(((Namespace) element).getOwnedMembers()); |
181 | 0 | result.addAll(((Namespace) element).getImportedMembers()); |
182 | |
} |
183 | 0 | if (element instanceof org.eclipse.uml2.uml.Package) { |
184 | 0 | result.addAll(((org.eclipse.uml2.uml.Package) element).getPackagedElements()); |
185 | |
} |
186 | 0 | return result; |
187 | |
} |
188 | |
|
189 | |
|
190 | |
public Object getElement(List<String> path) { |
191 | 0 | return getElement(path, null); |
192 | |
} |
193 | |
|
194 | |
public Object getElement(List<String> path, Object theRootNamespace) { |
195 | |
|
196 | 0 | return null; |
197 | |
} |
198 | |
|
199 | |
public List<String> getPathList(Object element) { |
200 | |
|
201 | 0 | List<String> path = new ArrayList<String>(); |
202 | 0 | path.add(modelImpl.getFacade().getName(element)); |
203 | 0 | return path; |
204 | |
} |
205 | |
|
206 | |
public List<Object> getRootElements(Object model) { |
207 | 0 | if (model instanceof EObject) { |
208 | 0 | List<Object> contents = new ArrayList<Object>(); |
209 | 0 | contents.addAll(((EObject) model).eResource().getContents()); |
210 | 0 | if (!contents.contains(model)) { |
211 | 0 | contents.add(model); |
212 | |
} |
213 | 0 | return contents; |
214 | |
} |
215 | 0 | throw new IllegalArgumentException( |
216 | |
"model must be instance of EObject"); |
217 | |
} |
218 | |
|
219 | |
public boolean isCyclicOwnership(Object parent, Object child) { |
220 | |
|
221 | 0 | return false; |
222 | |
} |
223 | |
|
224 | |
public void removeImportedElement(Object handle, Object me) { |
225 | |
|
226 | 0 | } |
227 | |
|
228 | |
public void setAlias(Object handle, String alias) { |
229 | |
|
230 | 0 | } |
231 | |
|
232 | |
public void setImportedElements(Object pack, Collection imports) { |
233 | |
|
234 | 0 | } |
235 | |
|
236 | |
public void setSpecification(Object handle, boolean isSpecification) { |
237 | |
|
238 | 0 | } |
239 | |
|
240 | |
public boolean isReadOnly(Object element) { |
241 | |
|
242 | 0 | return false; |
243 | |
} |
244 | |
|
245 | |
} |