1 package org.andromda.cartridges.java.metafacades;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import org.andromda.metafacades.uml.ClassifierFacade;
6 import org.andromda.metafacades.uml.GeneralizableElementFacade;
7 import org.andromda.metafacades.uml.ModelElementFacade;
8 import org.andromda.metafacades.uml.ParameterFacade;
9 import org.andromda.metafacades.uml.TemplateParameterFacade;
10 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
11 import org.apache.commons.lang.BooleanUtils;
12 import org.apache.commons.lang.ObjectUtils;
13 import org.apache.commons.lang.StringUtils;
14
15
16
17
18
19
20
21 public class JavaClassLogicImpl
22 extends JavaClassLogic
23 {
24 private static final long serialVersionUID = 34L;
25
26
27
28
29 public JavaClassLogicImpl(
30 Object metaObject,
31 String context)
32 {
33 super(metaObject, context);
34 }
35
36
37
38
39
40
41
42
43 public String getName(boolean fault)
44 {
45 String name = super.getName();
46 if (fault && this.hasStereotype("WebFault"))
47 {
48 name = name.replace("Exception", "Fault");
49 if (!name.contains("Fault"))
50 {
51 name += "Fault";
52 }
53 }
54 return name;
55 }
56
57
58
59
60
61 public Object getType()
62 {
63
64
65
66
67
68 return this.metaObject;
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 @Override
90 protected String handleGetInterfaceImplementationName()
91 {
92 return this.getInterfaceImplementionName().replaceAll(
93 "\\{0\\}",
94 this.getName());
95 }
96
97
98
99
100
101
102 private String getInterfaceImplementionName()
103 {
104 return String.valueOf(this.getConfiguredProperty(JavaGlobals.INTERFACE_IMPLEMENTATION_NAME_PATTERN));
105 }
106
107
108
109
110
111 @Override
112 protected String handleGetFullyQualifiedInterfaceImplementationName()
113 {
114 final StringBuilder fullName = new StringBuilder();
115 final String packageName = this.getPackageName();
116 if (StringUtils.isNotBlank(packageName))
117 {
118 fullName.append(packageName).append('.');
119 }
120 return fullName.append(this.getInterfaceImplementationName()).toString();
121 }
122
123
124
125
126
127 @Override
128 protected boolean handleIsAbstractInterfaceImplementation()
129 {
130 boolean abstractImplementation = !this.getOperations().isEmpty();
131 if (!abstractImplementation)
132 {
133 for (GeneralizableElementFacade generalizableElementFacade : this.getAllGeneralizations())
134 {
135 final ClassifierFacade classifier = (ClassifierFacade) generalizableElementFacade;
136 abstractImplementation = !classifier.getOperations().isEmpty();
137 if (abstractImplementation)
138 {
139 break;
140 }
141 }
142 }
143 return abstractImplementation;
144 }
145
146
147
148
149
150
151 protected String handleGetTemplateParams()
152 {
153 String fullName = "";
154 if (this.isTemplateParametersPresent() &&
155 BooleanUtils.toBoolean(
156 ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING))))
157 {
158
159 final StringBuilder buffer = new StringBuilder();
160
161
162 buffer.append(fullName);
163
164
165 buffer.append('<');
166
167
168
169 final Collection<TemplateParameterFacade> templateParameters = this.getTemplateParameters();
170 for (Iterator<TemplateParameterFacade> parameterIterator = templateParameters.iterator(); parameterIterator.hasNext();)
171 {
172 final ModelElementFacade modelElement =
173 (parameterIterator.next()).getParameter();
174
175
176
177 if (modelElement instanceof ParameterFacade)
178 {
179 buffer.append(((ParameterFacade)modelElement).getType().getFullyQualifiedName());
180 }
181 else
182 {
183 buffer.append(modelElement.getFullyQualifiedName());
184 }
185
186 if (parameterIterator.hasNext())
187 {
188 buffer.append(", ");
189 }
190 }
191
192
193 buffer.append('>');
194
195
196 fullName = buffer.toString();
197 }
198 return fullName;
199 }
200 }