1 package org.andromda.metafacades.emf.uml22;
2
3 import org.andromda.metafacades.uml.NameMasker;
4 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
5 import org.apache.commons.lang.StringUtils;
6 import org.eclipse.uml2.uml.EnumerationLiteral;
7 import org.eclipse.uml2.uml.OpaqueExpression;
8
9
10
11
12
13
14
15 public class EnumerationLiteralFacadeLogicImpl
16 extends EnumerationLiteralFacadeLogic
17 {
18 private static final long serialVersionUID = 3244584657700009965L;
19
20
21
22
23
24 public EnumerationLiteralFacadeLogicImpl(
25 final EnumerationLiteral metaObject,
26 final String context)
27 {
28 super(metaObject, context);
29 }
30
31
32
33
34 @Override
35 protected String handleGetName()
36 {
37 return this.getName(false);
38 }
39
40
41
42
43 @Override
44 protected String handleGetValue()
45 {
46 return this.getValue(false);
47 }
48
49
50
51
52 @Override
53 protected String handleGetName(final boolean modelName)
54 {
55 String name = super.handleGetName();
56 final String mask = String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.ENUMERATION_LITERAL_NAME_MASK));
57 if (!modelName && StringUtils.isNotBlank(mask))
58 {
59 name = NameMasker.mask(name, mask);
60 }
61 return name;
62 }
63
64
65
66
67 @Override
68 protected String handleGetValue(final boolean modelValue)
69 {
70 String value = null;
71 if (this.metaObject.getSpecification() != null && this.metaObject.getSpecification() instanceof OpaqueExpression)
72 {
73 final OpaqueExpression expression = (OpaqueExpression)this.metaObject.getSpecification();
74 if (expression.getBodies() != null && !expression.getBodies().isEmpty())
75 {
76 value = expression.getBodies().get(0);
77 }
78 }
79 if (value == null)
80 {
81 value = this.getName(modelValue);
82 }
83 return StringUtils.trimToEmpty(value);
84 }
85
86
87
88
89 @Override
90 protected String handleGetEnumerationValue() {
91 String value = this.getValue();
92 if (StringUtils.isEmpty(value))
93 {
94 value = "\"\"";
95 }
96 if (value.indexOf('"')<0)
97 {
98 value = '\"' + value + '\"';
99 }
100 return value;
101 }
102 }