1 package org.andromda.metafacades.emf.uml22;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6 import org.andromda.metafacades.uml.ModelElementFacade;
7 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
8 import org.apache.commons.collections.CollectionUtils;
9 import org.apache.commons.lang.ObjectUtils;
10 import org.apache.log4j.Logger;
11 import org.eclipse.uml2.uml.Class;
12 import org.eclipse.uml2.uml.Element;
13 import org.eclipse.uml2.uml.Package;
14 import org.eclipse.uml2.uml.internal.impl.BehaviorImpl;
15 import org.eclipse.uml2.uml.internal.impl.ClassImpl;
16 import org.eclipse.uml2.uml.internal.impl.ComponentImpl;
17 import org.eclipse.uml2.uml.internal.impl.NodeImpl;
18 import org.eclipse.uml2.uml.internal.impl.StereotypeImpl;
19
20
21
22
23
24
25
26
27 public class PackageFacadeLogicImpl
28 extends PackageFacadeLogic
29 {
30 private static final long serialVersionUID = 34L;
31
32
33
34
35 public PackageFacadeLogicImpl(
36 final Package metaObject,
37 final String context)
38 {
39 super(metaObject, context);
40 }
41
42
43
44
45 private static final Logger LOGGER = Logger.getLogger(PackageFacadeLogicImpl.class);
46
47
48
49
50 @Override
51 protected ModelElementFacade handleFindModelElement(
52 final String fullyQualifiedName)
53 {
54 Object modelElement = null;
55 if (PackageFacadeLogicImpl.LOGGER.isDebugEnabled())
56 {
57 PackageFacadeLogicImpl.LOGGER.debug("Looking for >> " + fullyQualifiedName);
58 }
59 modelElement =
60 UmlUtilities.findByFullyQualifiedName(
61 this.metaObject.eResource().getResourceSet(),
62 fullyQualifiedName,
63 ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
64 true);
65 if (modelElement==null)
66 {
67
68 modelElement =
69 UmlUtilities.findByFullyQualifiedName(
70 this.metaObject.eResource().getResourceSet(),
71 fullyQualifiedName,
72 ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
73 false);
74 }
75 if (PackageFacadeLogicImpl.LOGGER.isDebugEnabled())
76 {
77 PackageFacadeLogicImpl.LOGGER.debug("Found: '" + modelElement + '\'');
78 }
79 return (ModelElementFacade)this.shieldedElement(modelElement);
80 }
81
82
83
84
85
86
87 @Override
88 protected Collection<Class> handleGetClasses()
89 {
90 final List<Class> classes = new ArrayList<Class>();
91 for (Element element : this.metaObject.getOwnedElements())
92 {
93
94
95 if ((element instanceof ClassImpl)
96 && !(element instanceof BehaviorImpl || element instanceof ComponentImpl || element instanceof NodeImpl || element instanceof StereotypeImpl))
97 {
98 classes.add((Class)element);
99 }
100 }
101 return classes;
102 }
103
104
105
106
107 @Override
108 protected Collection<Package> handleGetSubPackages()
109 {
110 return this.metaObject.getNestedPackages();
111 }
112
113
114
115
116 @Override
117 protected Collection<? extends ModelElementFacade> handleGetModelElements()
118 {
119 return CollectionUtils.collect(UmlUtilities.findModel(this.metaObject)
120 .allOwnedElements(), UmlUtilities.ELEMENT_TRANSFORMER);
121 }
122
123
124
125
126 @Override
127 protected Collection<? extends ModelElementFacade> handleGetOwnedElements()
128 {
129 return CollectionUtils.collect(
130 this.metaObject.getOwnedMembers(),
131 UmlUtilities.ELEMENT_TRANSFORMER);
132 }
133
134
135
136
137 @Override
138 protected String handleGetTablePrefix()
139 {
140
141 return "";
142 }
143 }