1 package org.andromda.cartridges.spring.metafacades;
2
3 import java.util.Collection;
4 import org.andromda.metafacades.uml.ClassifierFacade;
5 import org.andromda.metafacades.uml.EntityQueryOperation;
6 import org.andromda.metafacades.uml.FilteredCollection;
7 import org.andromda.metafacades.uml.OperationFacade;
8 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
9 import org.apache.commons.lang.ObjectUtils;
10 import org.apache.commons.lang.StringUtils;
11
12
13
14
15
16
17 public class SpringManageableEntityLogicImpl
18 extends SpringManageableEntityLogic
19 {
20 private static final long serialVersionUID = 34L;
21
22
23
24
25
26
27 public SpringManageableEntityLogicImpl (Object metaObject, String context)
28 {
29 super (metaObject, context);
30 }
31
32
33
34
35 private String getNamespaceProperty()
36 {
37 return (String)getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR);
38 }
39
40
41
42
43 protected String handleGetDaoReferenceName()
44 {
45 return StringUtils.uncapitalize(getName()) + "Dao";
46 }
47
48
49
50
51 protected String handleGetManageableDaoName()
52 {
53 return getName() + "ManageableDao";
54 }
55
56
57
58
59 protected String handleGetFullyQualifiedManageableDaoName()
60 {
61 return getManageablePackageName() + getNamespaceProperty() + getManageableDaoName();
62 }
63
64
65
66
67 protected String handleGetManageableDaoFullPath()
68 {
69 return StringUtils.replace(this.getFullyQualifiedManageableDaoName(), getNamespaceProperty(), "/");
70 }
71
72
73
74
75 protected String handleGetManageableDaoBaseName()
76 {
77 return getManageableDaoName() + "Base";
78 }
79
80
81
82
83 protected String handleGetFullyQualifiedManageableDaoBaseName()
84 {
85 return getManageablePackageName() + getNamespaceProperty() + getManageableDaoBaseName();
86 }
87
88
89
90
91 protected String handleGetManageableDaoBaseFullPath()
92 {
93 return StringUtils.replace(this.getFullyQualifiedManageableDaoBaseName(), this.getNamespaceProperty(), "/");
94 }
95
96
97
98
99 protected String handleGetManageableServiceBaseName()
100 {
101 return getManageableServiceName() + "Base";
102 }
103
104
105
106
107 protected String handleGetFullyQualifiedManageableServiceBaseName()
108 {
109 return getManageablePackageName() + getNamespaceProperty() + getManageableServiceBaseName();
110 }
111
112
113
114
115 protected String handleGetManageableServiceBaseFullPath()
116 {
117 return StringUtils.replace(this.getFullyQualifiedManageableServiceBaseName(), this.getNamespaceProperty(), "/");
118 }
119
120
121
122
123 protected String handleGetManageableValueObjectFullPath()
124 {
125 return StringUtils.replace(this.getFullyQualifiedManageableValueObjectName(), this.getNamespaceProperty(), "/");
126 }
127
128
129
130
131 protected String handleGetManageableValueObjectClassName()
132 {
133 return getName() + this.getConfiguredProperty(SpringGlobals.CRUD_VALUE_OBJECT_SUFFIX);
134 }
135
136
137
138
139 protected String handleGetFullyQualifiedManageableValueObjectName()
140 {
141 return getManageablePackageName() + getNamespaceProperty() + getManageableValueObjectClassName();
142 }
143
144
145
146
147 protected String handleGetManageableSearchExampleFullPath()
148 {
149 return StringUtils.replace(this.getFullyQualifiedManageableSearchExampleName(), this.getNamespaceProperty(), "/");
150 }
151
152
153
154
155 protected String handleGetManageableSearchExampleClassName()
156 {
157 return getName() + "SearchExample";
158 }
159
160
161
162
163 protected String handleGetFullyQualifiedManageableSearchExampleName()
164 {
165 return getManageablePackageName() + getNamespaceProperty() + getManageableSearchExampleClassName();
166 }
167
168
169
170
171 protected boolean handleIsRemotingTypeRmi()
172 {
173 return SpringGlobals.REMOTING_PROTOCOL_RMI.equalsIgnoreCase(this.getRemotingType());
174 }
175
176
177
178
179 protected boolean handleIsRemotingTypeNone()
180 {
181 return SpringGlobals.REMOTING_PROTOCOL_NONE.equalsIgnoreCase(this.getRemotingType());
182 }
183
184
185
186
187 protected boolean handleIsRemotingTypeHttpInvoker()
188 {
189 return SpringGlobals.REMOTING_PROTOCOL_HTTPINVOKER.equalsIgnoreCase(this.getRemotingType());
190 }
191
192
193
194
195 protected boolean handleIsRemotingTypeHessian()
196 {
197 return SpringGlobals.REMOTING_PROTOCOL_HESSIAN.equalsIgnoreCase(this.getRemotingType());
198 }
199
200
201
202
203 protected boolean handleIsRemotingTypeBurlap()
204 {
205 return SpringGlobals.REMOTING_PROTOCOL_BURLAP.equalsIgnoreCase(this.getRemotingType());
206 }
207
208
209
210
211 protected String handleGetRemoteUrl()
212 {
213 final StringBuilder result = new StringBuilder();
214
215 String propertyPrefix = ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.CONFIG_PROPERTY_PREFIX));
216
217 if (this.isRemotingTypeNone())
218 {
219
220 }
221 else if (this.isRemotingTypeHttpInvoker() || this.isRemotingTypeHessian() || this.isRemotingTypeBurlap())
222 {
223
224 result.append("${").append(propertyPrefix).append("remoteHttpScheme}://${");
225 result.append(propertyPrefix);
226 result.append("remoteServer}");
227
228
229 if (hasServiceRemotePort())
230 {
231 result.append(":${");
232 result.append(propertyPrefix);
233 result.append("remotePort}");
234 }
235
236
237 if (hasServiceRemoteContext())
238 {
239 result.append("/${");
240 result.append(propertyPrefix);
241 result.append("remoteContext}");
242 }
243
244
245 result.append("/remote");
246 result.append(this.getManageableServiceName());
247 }
248 else if (this.isRemotingTypeRmi())
249 {
250
251 result.append("${").append(propertyPrefix).append("remoteRmiScheme}://${");
252 result.append(propertyPrefix);
253 result.append("remoteServer}");
254
255
256 if (hasServiceRemotePort())
257 {
258 result.append(":${");
259 result.append(propertyPrefix);
260 result.append("remotePort}");
261 }
262
263
264 result.append("/remote");
265 result.append(this.getManageableServiceName());
266 }
267
268 return result.toString();
269 }
270
271
272
273
274 protected String handleGetRemoteServer()
275 {
276 return StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_SERVER)));
277 }
278
279
280
281
282 protected String handleGetRemotePort()
283 {
284 final String serviceRemotePort =
285 StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_PORT)));
286 return SpringMetafacadeUtils.getServiceRemotePort(this, serviceRemotePort);
287 }
288
289
290
291
292 protected String handleGetRemoteContext()
293 {
294 return this.isConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT)
295 ? ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT)) : "";
296 }
297
298
299
300
301 protected boolean handleIsRemotable()
302 {
303 return !this.isRemotingTypeNone();
304 }
305
306
307
308
309 private String getRemotingType()
310 {
311 final String serviceRemotingType =
312 StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTING_TYPE)));
313 return SpringMetafacadeUtils.getServiceRemotingType(this, serviceRemotingType);
314 }
315
316
317
318
319
320
321 private boolean hasServiceRemotePort()
322 {
323 return StringUtils.isNotBlank(this.getRemotePort());
324 }
325
326
327
328
329
330
331 private boolean hasServiceRemoteContext()
332 {
333 return StringUtils.isNotBlank(this.getRemoteContext());
334 }
335
336
337
338
339
340
341 public Collection<SpringEntityOperation> getManageableDaoBusinessOperations()
342 {
343 Collection<SpringEntityOperation> result=super.getDaoBusinessOperations();
344 result = new FilteredCollection<SpringEntityOperation>(result)
345 {
346 private static final long serialVersionUID = 34L;
347 public boolean evaluate(Object object)
348 {
349 final SpringEntityOperation operation=(SpringEntityOperation)object;
350 final ClassifierFacade returnType=operation.getReturnType();
351 return operation.getVisibility().equals("public") &&
352 (returnType.isDataType() ||
353 returnType.getFullyQualifiedName().equals(getFullyQualifiedName()));
354 }
355 };
356
357 return result;
358 }
359
360
361
362
363
364
365 public Collection<EntityQueryOperation> getManageableQueryOperations()
366 {
367 Collection<EntityQueryOperation> result=super.getQueryOperations();
368 result = new FilteredCollection<EntityQueryOperation>(result)
369 {
370 private static final long serialVersionUID = 34L;
371 public boolean evaluate(Object object)
372 {
373 final EntityQueryOperation operation=(EntityQueryOperation)object;
374 final ClassifierFacade returnType=operation.getReturnType();
375 return operation.getVisibility().equals("public") &&
376 (returnType.isDataType() ||
377 returnType.getFullyQualifiedName().equals(getFullyQualifiedName()));
378 }
379 };
380 return result;
381 }
382
383
384
385
386
387
388
389 public boolean isCollection(OperationFacade operation)
390 {
391 return (operation.getUpper() > 1 || operation.getUpper() == -1);
392 }
393 }