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.ClassifierFacade;
7 import org.andromda.metafacades.uml.ModelElementFacade;
8 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
9 import org.andromda.utils.StringUtilsHelper;
10 import org.apache.commons.lang.StringUtils;
11 import org.apache.commons.lang.SystemUtils;
12 import org.apache.log4j.Logger;
13 import org.eclipse.uml2.uml.Classifier;
14 import org.eclipse.uml2.uml.ClassifierTemplateParameter;
15 import org.eclipse.uml2.uml.Comment;
16 import org.eclipse.uml2.uml.NamedElement;
17 import org.eclipse.uml2.uml.ParameterableElement;
18 import org.eclipse.uml2.uml.TemplateParameter;
19
20
21
22
23
24
25
26 public class TemplateParameterFacadeLogicImpl
27 extends TemplateParameterFacadeLogic
28 {
29
30
31
32 private static final Logger LOGGER = Logger.getLogger(TemplateParameterFacadeLogicImpl.class);
33 private static final long serialVersionUID = 3750035061795880358L;
34
35
36
37
38
39 public TemplateParameterFacadeLogicImpl(
40 final ClassifierTemplateParameter metaObject,
41 final String context)
42 {
43 super(metaObject, context);
44 }
45
46
47
48
49 @Override
50 protected ParameterableElement handleGetParameter()
51 {
52 return this.metaObject.getOwnedParameteredElement();
53 }
54
55
56
57
58 @Override
59 protected ParameterableElement handleGetDefaultElement()
60 {
61 return this.metaObject.getDefault();
62 }
63
64
65
66
67
68
69
70
71
72 @Override
73 public final String handleGetName()
74 {
75
76 final NamedElement type = (NamedElement) this.metaObject.getOwnedParameteredElement();
77
78 return type.getName();
79 }
80
81
82
83
84
85 @Override
86 public final ClassifierFacade handleGetType()
87 {
88 ClassifierFacade getType2r = null;
89 ClassifierTemplateParameter param = (ClassifierTemplateParameter)this.metaObject;
90 ParameterableElement element = this.metaObject.getOwnedParameteredElement();
91
92 Classifier type = param.getConstrainingClassifier(this.getName());
93 if (type==null && param.getConstrainingClassifiers()!=null && param.getConstrainingClassifiers().size()>0)
94 {
95 type = param.getConstrainingClassifiers().get(0);
96 }
97 if (type == null && element instanceof Classifier)
98 {
99 type = (Classifier)element;
100 }
101
102
103
104
105 final Object result = this.shieldedElement(type);
106 try
107 {
108 getType2r = (ClassifierFacade)result;
109 }
110 catch (ClassCastException ex)
111 {
112
113 TemplateParameterFacadeLogicImpl.LOGGER.warn("incorrect metafacade cast for TemplateParameterFacadeLogicImpl.getType ClassifierFacade " + handleGetParameter() + ": " + result);
114 }
115
116
117
118
119 return getType2r;
120 }
121
122
123
124
125
126 @Override
127 public final String handleGetGetterSetterTypeName()
128 {
129 String type = null;
130
131
132
133 if (this.handleGetType() != null)
134 {
135 type = this.getType().getFullyQualifiedName();
136 }
137 else
138 {
139 type = "java.lang.Class";
140 }
141 return type;
142 }
143
144
145
146
147
148 @Override
149 public final String handleGetFullyQualifiedName()
150 {
151 String name = this.handleGetName();
152 final String className = ((NamedElement)this.metaObject.getOwner().getOwner()).getName();
153 if (className != null)
154 {
155 name = className + '.' + name;
156 }
157 final String pkg = this.metaObject.getNearestPackage().getName();
158 if (pkg != null)
159 {
160 name = pkg + '.' + name;
161 }
162 return name;
163 }
164
165
166
167
168 public final int getLower()
169 {
170 int lower = 0;
171 final ClassifierFacade type = this.getType();
172 if (type != null && type.isPrimitive())
173 {
174 lower = 1;
175 }
176 return lower;
177 }
178
179
180
181
182
183
184 public final String handleGetGetterName()
185 {
186 return "get" + StringUtils.capitalize(this.getName());
187 }
188
189
190
191
192 public final String handleGetSetterName()
193 {
194 return "set" + StringUtils.capitalize(this.getName());
195 }
196
197
198
199
200 @Override
201 public final List<Classifier> handleGetConstrainingClassifiers()
202 {
203 TemplateParameter param = this.metaObject;
204
205 if (param instanceof ClassifierTemplateParameter)
206 {
207 return ((ClassifierTemplateParameter)param).getConstrainingClassifiers();
208 }
209 else
210 {
211 return new ArrayList<Classifier>();
212 }
213 }
214
215
216
217
218
219 @Override
220 protected ModelElementFacade handleGetOwner()
221 {
222 return (ModelElementFacade)this.shieldedElement(this.metaObject.getOwner());
223 }
224
225
226
227
228 @Override
229 protected String handleGetDocumentation(String indent)
230 {
231 return this.handleGetDocumentation(
232 indent,
233 100 - indent.length());
234 }
235
236
237
238
239 @Override
240 protected String handleGetDocumentation(String indent, int lineLength)
241 {
242
243
244 return this.handleGetDocumentation(
245 indent,
246 lineLength,
247 false);
248 }
249
250
251
252
253 @Override
254 protected String handleGetDocumentation(String indent, int lineLength, boolean htmlStyle)
255 {
256 final StringBuilder documentation = new StringBuilder();
257
258 if (lineLength < 1)
259 {
260 lineLength = Integer.MAX_VALUE;
261 }
262
263
264 Collection<Comment> comments = this.metaObject.getOwnedComments();
265 if (comments == null || comments.isEmpty())
266 {
267 comments = this.metaObject.getParameteredElement().getOwnedComments();
268 }
269 if (comments == null || comments.isEmpty())
270 {
271 comments = this.metaObject.getSignature().getOwnedComments();
272 }
273 if (comments != null && !comments.isEmpty())
274 {
275 for (final Comment comment : comments)
276 {
277 String commentString = StringUtils.trimToEmpty(comment.getBody());
278 documentation.append(StringUtils.trimToEmpty(commentString));
279 documentation.append(SystemUtils.LINE_SEPARATOR);
280 }
281 }
282
283
284 if (StringUtils.isBlank(documentation.toString()))
285 {
286 if (Boolean.valueOf((String)this.getConfiguredProperty(UMLMetafacadeProperties.TODO_FOR_MISSING_DOCUMENTATION)))
287 {
288 String todoTag = (String)this.getConfiguredProperty(UMLMetafacadeProperties.TODO_TAG);
289 documentation.append(todoTag).append(": Model Documentation for " + this.handleGetFullyQualifiedName());
290 }
291 }
292
293 return StringUtilsHelper.format(
294 StringUtils.trimToEmpty(documentation.toString()),
295 indent,
296 lineLength,
297 htmlStyle);
298 }
299
300
301
302
303 @Override
304 public String getValidationName()
305 {
306 return this.getName();
307 }
308
309
310
311
312 @Override
313 public ModelElementFacade getValidationOwner()
314 {
315 return (ModelElementFacade)this.shieldedElement(this.metaObject.getOwner());
316 }
317 }