1 package org.andromda.metafacades.emf.uml22;
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.Set;
8 import org.andromda.metafacades.uml.GeneralizableElementFacade;
9 import org.eclipse.uml2.uml.Classifier;
10 import org.eclipse.uml2.uml.Generalization;
11
12
13
14
15
16
17
18 public class GeneralizableElementFacadeLogicImpl
19 extends GeneralizableElementFacadeLogic
20 {
21 private static final long serialVersionUID = 34L;
22
23
24
25
26 public GeneralizableElementFacadeLogicImpl(
27 final Object metaObject,
28 final String context)
29 {
30 super(metaObject, context);
31 }
32
33
34
35
36 @Override
37 protected String handleGetGeneralizationList()
38 {
39 final StringBuilder list = new StringBuilder();
40 if (this.getGeneralizations() != null)
41 {
42 for (final Iterator<GeneralizableElementFacade> iterator = this.getGeneralizations().iterator(); iterator.hasNext();)
43 {
44 final GeneralizableElementFacade element = iterator.next();
45 list.append(element.getFullyQualifiedName());
46 if (iterator.hasNext())
47 {
48 list.append(", ");
49 }
50 }
51 }
52 return list.toString();
53 }
54
55
56
57
58 @Override
59 protected Classifier handleGetGeneralization()
60 {
61 Classifier parent = null;
62 final Collection<Generalization> generalizations = ((Classifier)this.metaObject).getGeneralizations();
63 if (generalizations != null && !generalizations.isEmpty())
64 {
65 parent = generalizations.iterator().next().getGeneral();
66 }
67 return parent;
68 }
69
70
71
72
73 @Override
74 protected Collection<Classifier> handleGetSpecializations()
75 {
76 return UmlUtilities.getSpecializations((Classifier)this.metaObject);
77 }
78
79
80
81
82 @Override
83 protected Collection<Classifier> handleGetGeneralizations()
84 {
85 final Collection<Classifier> parents = new LinkedHashSet<Classifier>();
86 final Collection<Generalization> generalizations = ((Classifier)this.metaObject).getGeneralizations();
87 if (generalizations != null && !generalizations.isEmpty())
88 {
89 for (Generalization general : generalizations)
90 {
91 parents.add(general.getGeneral());
92 }
93 }
94 return parents;
95 }
96
97
98
99
100 @Override
101 protected Collection<Generalization> handleGetGeneralizationLinks()
102 {
103 return ((Classifier)this.metaObject).getGeneralizations();
104 }
105
106
107
108
109 @Override
110 protected Set<GeneralizableElementFacade> handleGetAllSpecializations()
111 {
112 final Set<GeneralizableElementFacade> allSpecializations = new LinkedHashSet<GeneralizableElementFacade>();
113 if (this.getSpecializations() != null)
114 {
115 allSpecializations.addAll(this.getSpecializations());
116 for (GeneralizableElementFacade element : this.getSpecializations())
117 {
118 allSpecializations.addAll(element.getAllSpecializations());
119 }
120 }
121 return allSpecializations;
122 }
123
124
125
126
127 @Override
128 protected Collection<GeneralizableElementFacade> handleGetAllGeneralizations()
129 {
130 final Collection<GeneralizableElementFacade> generalizations = new ArrayList<GeneralizableElementFacade>();
131 for (GeneralizableElementFacade element : this.getGeneralizations())
132 {
133 generalizations.add(element);
134 generalizations.addAll(element.getAllGeneralizations());
135 }
136 return generalizations;
137 }
138
139
140
141
142 @Override
143 protected Object handleFindTaggedValue(
144 final String tagName,
145 final boolean follow)
146 {
147 Object value = this.findTaggedValue(tagName);
148 if (value == null && follow)
149 {
150 for (GeneralizableElementFacade element = this.getGeneralization(); element != null;
151 element = element.getGeneralization())
152 {
153 value = element.findTaggedValue(
154 tagName,
155 follow);
156 if (value != null)
157 {
158 break;
159 }
160 }
161 }
162 return value;
163 }
164
165
166
167
168 @Override
169 protected GeneralizableElementFacade handleGetGeneralizationRoot()
170 {
171 GeneralizableElementFacade generalizableElement = (GeneralizableElementFacade)THIS();
172
173 while (generalizableElement.getGeneralization() != null)
174 {
175 generalizableElement = generalizableElement.getGeneralization();
176 }
177
178 return generalizableElement;
179 }
180 }