1 package org.andromda.metafacades.emf.uml22;
2
3 import org.andromda.metafacades.uml.ClassifierFacade;
4 import org.andromda.metafacades.uml.NameMasker;
5 import org.andromda.metafacades.uml.TypeMappings;
6 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
7 import org.andromda.metafacades.uml.UMLMetafacadeUtils;
8 import org.andromda.metafacades.uml.UMLProfile;
9 import org.andromda.utils.StringUtilsHelper;
10 import org.apache.commons.lang.BooleanUtils;
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.commons.lang.StringUtils;
13 import org.eclipse.uml2.uml.AggregationKind;
14 import org.eclipse.uml2.uml.Association;
15 import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
16 import org.eclipse.uml2.uml.Type;
17
18
19
20
21
22
23
24
25 public class AssociationEndFacadeLogicImpl
26 extends AssociationEndFacadeLogic
27 {
28 private static final long serialVersionUID = 34L;
29
30
31
32
33 public AssociationEndFacadeLogicImpl(
34 final AssociationEnd metaObjectIn,
35 final String context)
36 {
37 super(metaObjectIn, context);
38 }
39
40
41
42
43 @Override
44 protected boolean handleIsOne2One()
45 {
46 return !this.isMany() && !this.getOtherEnd().isMany();
47 }
48
49
50
51
52 @Override
53 protected boolean handleIsOne2Many()
54 {
55 return !this.isMany() && this.getOtherEnd().isMany();
56 }
57
58
59
60
61 @Override
62 protected boolean handleIsMany2One()
63 {
64 return this.isMany() && !this.getOtherEnd().isMany();
65 }
66
67
68
69
70 @Override
71 protected boolean handleIsMany2Many()
72 {
73 return this.isMany() && this.getOtherEnd().isMany();
74 }
75
76
77
78
79 @Override
80 protected boolean handleIsAggregation()
81 {
82 return UmlUtilities.getOppositeAssociationEnd(this.metaObject).getAggregation().equals(AggregationKind.SHARED_LITERAL);
83 }
84
85
86
87
88 @Override
89 protected boolean handleIsComposition()
90 {
91 return UmlUtilities.getOppositeAssociationEnd(this.metaObject).getAggregation().equals(AggregationKind.COMPOSITE_LITERAL);
92 }
93
94
95
96
97
98 @Override
99 public boolean handleIsLeaf()
100 {
101 return this.metaObject.isLeaf();
102 }
103
104
105
106
107 @Override
108 protected boolean handleIsOrdered()
109 {
110 return this.metaObject.isOrdered();
111 }
112
113
114
115
116 @Override
117 protected boolean handleIsReadOnly()
118 {
119 return this.metaObject.isReadOnly();
120 }
121
122
123
124
125 @Override
126 protected boolean handleIsNavigable()
127 {
128 return this.metaObject.isNavigable();
129 }
130
131
132
133
134
135 @Override
136 public boolean handleIsUnique()
137 {
138 return this.metaObject.isUnique();
139 }
140
141
142
143
144 @Override
145 protected String handleGetName()
146 {
147 String name = super.handleGetName();
148
149
150 if (StringUtils.isBlank(name))
151 {
152 final ClassifierFacade type = this.getType();
153 if (type != null)
154 {
155 name = StringUtils.uncapitalize(StringUtils.trimToEmpty(type.getName()));
156 }
157 }
158 if (this.isMany() && this.isPluralizeAssociationEndNames())
159 {
160 name = StringUtilsHelper.pluralize(name);
161 }
162 final String nameMask =
163 String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.CLASSIFIER_PROPERTY_NAME_MASK));
164 return NameMasker.mask(
165 name,
166 nameMask);
167 }
168
169
170
171
172
173
174 private boolean isPluralizeAssociationEndNames()
175 {
176 final Object value = this.getConfiguredProperty(UMLMetafacadeProperties.PLURALIZE_ASSOCIATION_END_NAMES);
177 return value != null && Boolean.valueOf(String.valueOf(value)).booleanValue();
178 }
179
180
181
182
183 @Override
184 protected String handleGetGetterName()
185 {
186 return UMLMetafacadeUtils.getGetterPrefix(this.getType()) + StringUtils.capitalize(this.handleGetName());
187 }
188
189
190
191
192 @Override
193 protected String handleGetSetterName()
194 {
195 return "set" + StringUtils.capitalize(this.handleGetName());
196 }
197
198
199
200
201 @Override
202 protected String handleGetAdderName()
203 {
204 return "add" + StringUtils.capitalize(this.handleGetName());
205 }
206
207
208
209
210 @Override
211 protected String handleGetRemoverName()
212 {
213 return "remove" + StringUtils.capitalize(this.handleGetName());
214 }
215
216
217
218
219 @Override
220 protected boolean handleIsBidirectional()
221 {
222 return isNavigable() && getOtherEnd().isNavigable();
223 }
224
225
226
227
228 @Override
229 protected String handleGetGetterSetterTypeName()
230 {
231 String name = null;
232 if (this.getUpper() > 1 || this.getUpper() == LiteralUnlimitedNatural.UNLIMITED)
233 {
234 final TypeMappings mappings = this.getLanguageMappings();
235 if (mappings != null)
236 {
237
238 name = mappings.getTo(this.isOrdered() ? UMLProfile.LIST_TYPE_NAME : UMLProfile.COLLECTION_TYPE_NAME);
239 }
240
241
242 if (this.getType() != null && BooleanUtils.toBoolean(
243 ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING))))
244 {
245 String type = this.getType().getFullyQualifiedName();
246
247
248
249
250
251
252
253 name += '<' + type + '>';
254
255 }
256 }
257 if (name == null && this.getType() != null)
258 {
259 name = this.getType().getFullyQualifiedName();
260 }
261 return name;
262 }
263
264
265
266
267 @Override
268 protected boolean handleIsMany()
269 {
270
271
272 return this.getUpper() > 1 || this.getUpper() == LiteralUnlimitedNatural.UNLIMITED
273 || (this.getType() != null && (this.getType().isArrayType() || this.getType().isCollectionType()));
274 }
275
276
277
278
279 @Override
280 protected boolean handleIsRequired()
281 {
282 return (this.getLower() > 0);
283 }
284
285
286
287
288 @Override
289 protected boolean handleIsChild()
290 {
291 return this.getOtherEnd() != null && this.getOtherEnd().isComposition();
292 }
293
294
295
296
297 @Override
298 protected AssociationEnd handleGetOtherEnd()
299 {
300 return UmlUtilities.getOppositeAssociationEnd(this.metaObject);
301 }
302
303
304
305
306 @Override
307 protected Association handleGetAssociation()
308 {
309 return this.metaObject.getAssociation();
310 }
311
312
313
314
315 @Override
316 protected String handleGetAggregationKind()
317 {
318 return this.metaObject.getAggregation().name();
319 }
320
321
322
323
324 @Override
325 protected Type handleGetType()
326 {
327
328 return this.metaObject.getType();
329 }
330
331
332
333
334 @Override
335 public Object getValidationOwner()
336 {
337 return this.getType();
338 }
339
340
341
342
343
344 @Override
345 protected int handleGetUpper()
346 {
347
348 return UmlUtilities.parseMultiplicity(this.metaObject.getUpperValue(), 1);
349 }
350
351
352
353
354
355 @Override
356 protected int handleGetLower()
357 {
358
359 return UmlUtilities.parseLowerMultiplicity(this.metaObject.getLowerValue(), this.getType(), "1");
360 }
361
362
363
364
365
366 @Override
367 protected String handleGetDefault()
368 {
369 return this.metaObject.getDefault();
370 }
371
372
373
374
375
376
377 @Override
378 protected String handleGetVisibility()
379 {
380 String visibility = super.handleGetVisibility();
381 if (visibility==null || visibility.equals("private"))
382 {
383 visibility = "public";
384 }
385 return visibility;
386 }
387
388
389
390
391 @Override
392 protected boolean handleIsDerived()
393 {
394 return this.metaObject.isDerived();
395 }
396
397
398
399
400 @Override
401 protected boolean handleIsStatic()
402 {
403 return this.metaObject.isStatic();
404 }
405 }