1 package org.andromda.metafacades.uml14;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import org.andromda.metafacades.uml.NameMasker;
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.StringUtils;
11 import org.omg.uml.behavioralelements.statemachines.Event;
12 import org.omg.uml.foundation.core.Classifier;
13 import org.omg.uml.foundation.core.Operation;
14 import org.omg.uml.foundation.core.Parameter;
15 import org.omg.uml.foundation.datatypes.Expression;
16 import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum;
17
18
19
20
21
22 public class ParameterFacadeLogicImpl
23 extends ParameterFacadeLogic
24 {
25 private static final long serialVersionUID = 34L;
26
27
28
29
30 public ParameterFacadeLogicImpl(
31 Parameter metaObject,
32 String context)
33 {
34 super(metaObject, context);
35 }
36
37
38
39
40
41
42 @Override
43 protected String handleGetName()
44 {
45 final String nameMask = String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.PARAMETER_NAME_MASK));
46 String name = NameMasker.mask(
47 super.handleGetName(),
48 nameMask);
49
50
51
52
53
54
55
56
57
58 return name;
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 @Override
76 protected String handleGetGetterName()
77 {
78 return UMLMetafacadeUtils.getGetterPrefix(this.getType(), this.getLower()) + StringUtilsHelper.capitalize(this.getName());
79 }
80
81
82
83
84 @Override
85 protected String handleGetSetterName()
86 {
87 return "set" + StringUtilsHelper.capitalize(this.getName());
88 }
89
90
91
92
93 public Object getValidationOwner()
94 {
95 Object owner = this.getOperation();
96
97 if (owner == null)
98 {
99 owner = this.getEvent();
100 }
101
102 return owner;
103 }
104
105
106
107
108
109 @Override
110 public String handleGetDefaultValue()
111 {
112 String defaultValue = null;
113 final Expression expression = this.metaObject.getDefaultValue();
114
115 if (expression != null)
116 {
117 defaultValue = expression.getBody();
118 }
119
120
121 if (StringUtils.isNotBlank(defaultValue) && defaultValue != null)
122 {
123 String typeName = this.metaObject.getType().getName();
124 if ("String".equals(typeName) && defaultValue.indexOf('"')<0)
125 {
126 defaultValue = '"' + defaultValue + '"';
127 }
128 else if (("char".equals(typeName) || "Character".equals(typeName))
129 && defaultValue.indexOf('\'')<0)
130 {
131 defaultValue = "'" + defaultValue.charAt(0) + '\'';
132 }
133
134 }
135 if (defaultValue==null) defaultValue="";
136 return defaultValue;
137 }
138
139
140
141
142 @Override
143 public boolean handleIsDefaultValuePresent()
144 {
145 return StringUtils.isNotBlank(this.getDefaultValue());
146 }
147
148
149
150
151
152 protected String handleGetGetterSetterTypeName()
153 {
154 if (this.getType()==null)
155 {
156 return "";
157 }
158 else
159 {
160
161 return this.getType().getFullyQualifiedName();
162 }
163 }
164
165
166
167
168 @Override
169 protected String handleGetGetterSetterTypeNameImpl()
170 {
171 return getGetterSetterTypeName();
172 }
173
174
175
176
177 @Override
178 protected Classifier handleGetType()
179 {
180 return this.metaObject.getType();
181 }
182
183
184
185
186
187
188 @Override
189 public String handleGetEffect()
190 {
191 return "NONE";
192 }
193
194
195
196
197
198
199 @Override
200 public boolean handleIsException()
201 {
202 return false;
203 }
204
205
206
207
208
209
210 @Override
211 protected boolean handleIsOrdered()
212 {
213 return false;
214 }
215
216
217
218
219 @Override
220 public boolean handleIsReturn()
221 {
222 return ParameterDirectionKindEnum.PDK_RETURN.equals(this.metaObject.getKind());
223 }
224
225
226
227
228 @Override
229 protected boolean handleIsRequired()
230 {
231 return !this.hasStereotype(UMLProfile.STEREOTYPE_NULLABLE);
232 }
233
234
235
236
237
238 @Override
239 protected boolean handleIsUnique()
240 {
241 return !this.hasStereotype(UMLProfile.STEREOTYPE_UNIQUE);
242 }
243
244
245
246
247 @Override
248 protected Operation handleGetOperation()
249 {
250 Operation parameterOperation = null;
251 final Collection<Operation> allOperations = UML14MetafacadeUtils.getModel().getCore().getOperation().refAllOfType();
252 for (final Iterator iterator = allOperations.iterator(); iterator.hasNext() && parameterOperation == null;)
253 {
254 final Operation operation = (Operation)iterator.next();
255 if (operation.getParameter().contains(this.metaObject))
256 {
257 parameterOperation = operation;
258 }
259 }
260 return parameterOperation;
261 }
262
263
264
265
266 @Override
267 protected Event handleGetEvent()
268 {
269 Event parameterEvent = null;
270 final Collection<Event> allEvents = UML14MetafacadeUtils.getModel().getStateMachines().getEvent().refAllOfType();
271 for (final Iterator<Event> iterator = allEvents.iterator(); iterator.hasNext() && parameterEvent == null;)
272 {
273 final Event event = iterator.next();
274 if (event.getParameter().contains(this.metaObject))
275 {
276 parameterEvent = event;
277 }
278 }
279 return parameterEvent;
280 }
281
282
283
284
285 @Override
286 protected boolean handleIsReadable()
287 {
288 return this.isInParameter() || this.isInoutParameter();
289 }
290
291
292
293
294 @Override
295 protected boolean handleIsWritable()
296 {
297 return this.isOutParameter() || this.isInoutParameter();
298 }
299
300
301
302
303 @Override
304 protected boolean handleIsInParameter()
305 {
306 return ParameterDirectionKindEnum.PDK_IN.equals(this.metaObject.getKind());
307 }
308
309
310
311
312 @Override
313 protected boolean handleIsOutParameter()
314 {
315 return ParameterDirectionKindEnum.PDK_OUT.equals(this.metaObject.getKind());
316 }
317
318
319
320
321 @Override
322 protected boolean handleIsInoutParameter()
323 {
324 return ParameterDirectionKindEnum.PDK_INOUT.equals(this.metaObject.getKind());
325 }
326
327
328
329
330
331
332
333
334 protected boolean handleIsMany()
335 {
336 boolean isMany = false;
337 if (null!=this.getType())
338 {
339 isMany = this.getType().isArrayType();
340 }
341 return isMany;
342 }
343
344
345
346
347
348
349
350 protected int handleGetUpper()
351 {
352 if (this.isMany())
353 {
354 return -1;
355 }
356 return 1;
357 }
358
359
360
361
362
363
364 protected int handleGetLower()
365 {
366 if (!this.hasStereotype("Nullable")
367 && this.getType().isPrimitive())
368 {
369 return 1;
370 }
371 return 0;
372 }
373
374
375
376
377
378
379 @SuppressWarnings("unused")
380 private boolean isPluralizeParameterNames()
381 {
382 final Object value = this.getConfiguredProperty(UMLMetafacadeProperties.PLURALIZE_PARAMETER_NAMES);
383 return value != null && Boolean.valueOf(String.valueOf(value));
384 }
385 }