1 package org.andromda.metafacades.uml14;
2
3 import java.util.Collection;
4 import org.andromda.metafacades.uml.AttributeFacade;
5 import org.andromda.metafacades.uml.ClassifierFacade;
6 import org.andromda.metafacades.uml.NameMasker;
7 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
8 import org.apache.commons.collections.CollectionUtils;
9 import org.apache.commons.collections.Predicate;
10 import org.apache.commons.lang.BooleanUtils;
11 import org.apache.commons.lang.StringUtils;
12 import org.omg.uml.foundation.core.Classifier;
13
14
15
16
17
18
19
20 public class EnumerationFacadeLogicImpl
21 extends EnumerationFacadeLogic
22 {
23 private static final long serialVersionUID = -3790826922365025369L;
24
25
26
27
28
29 public EnumerationFacadeLogicImpl(Classifier metaObject, String context)
30 {
31 super(metaObject, context);
32 }
33
34
35
36
37
38
39 @Override
40 protected String handleGetName()
41 {
42 final String nameMask = String.valueOf(
43 this.getConfiguredProperty(UMLMetafacadeProperties.ENUMERATION_NAME_MASK));
44 return NameMasker.mask(super.handleGetName(), nameMask);
45 }
46
47
48
49
50 @Override
51 protected Collection<AttributeFacade> handleGetLiterals()
52 {
53 Collection<AttributeFacade> literals = this.getAttributes();
54 CollectionUtils.filter(
55 literals,
56 new Predicate()
57 {
58 public boolean evaluate(Object object)
59 {
60 boolean isLiteral = true;
61 final AttributeFacade attribute = (AttributeFacade)object;
62 if (attribute.isEnumerationMember())
63 {
64 isLiteral = false;
65 }
66 return isLiteral;
67 }
68 }
69 );
70 return literals;
71 }
72
73
74
75
76 @Override
77 protected Collection<AttributeFacade> handleGetMemberVariables()
78 {
79 Collection<AttributeFacade> variables = super.getAttributes();
80 CollectionUtils.filter(
81 variables,
82 new Predicate()
83 {
84 public boolean evaluate(Object object)
85 {
86 boolean isMember = false;
87 final AttributeFacade attribute = (AttributeFacade)object;
88 if (attribute.isEnumerationMember())
89 {
90 isMember = true;
91 }
92 return isMember;
93 }
94 }
95 );
96 return variables;
97 }
98
99
100
101
102 @Override
103 protected String handleGetFromOperationSignature()
104 {
105 final StringBuilder signature = new StringBuilder(this.getFromOperationName());
106 final ClassifierFacade type = this.getLiteralType();
107 if (type != null)
108 {
109 signature.append('(');
110 signature.append(type.getFullyQualifiedName());
111 signature.append(" value)");
112 }
113 return signature.toString();
114 }
115
116
117
118
119 @Override
120 protected boolean handleIsTypeSafe()
121 {
122 return BooleanUtils.toBoolean(
123 String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.TYPE_SAFE_ENUMS_ENABLED)));
124 }
125
126
127
128
129 @Override
130 protected String handleGetFromOperationName()
131 {
132 final StringBuilder name = new StringBuilder("from");
133 final ClassifierFacade type = this.getLiteralType();
134 if (type != null)
135 {
136 name.append(StringUtils.capitalize(type.getName()));
137 }
138 return name.toString();
139 }
140
141
142
143
144 @Override
145 protected ClassifierFacade handleGetLiteralType()
146 {
147 ClassifierFacade type = null;
148 final Collection<AttributeFacade> literals = this.getLiterals();
149 if (literals != null && !literals.isEmpty())
150 {
151 type = ((AttributeFacade)literals.iterator().next()).getType();
152
153
154
155
156
157 }
158 return type;
159 }
160 }