1 package org.andromda.cartridges.ejb3.metafacades;
2
3 import java.text.MessageFormat;
4 import java.util.Collection;
5 import java.util.List;
6 import org.andromda.cartridges.ejb3.EJB3Globals;
7 import org.andromda.metafacades.uml.EntityAttribute;
8 import org.andromda.metafacades.uml.ModelElementFacade;
9 import org.apache.commons.collections.CollectionUtils;
10 import org.apache.commons.collections.Predicate;
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.commons.lang.StringUtils;
13
14
15
16
17
18
19 public class EJB3ManageableEntityFacadeLogicImpl
20 extends EJB3ManageableEntityFacadeLogic
21 {
22 private static final long serialVersionUID = 34L;
23
24
25
26 public static final String CREATE_EXCEPTION_NAME_PATTERN = "manageableCreateExceptionNamePattern";
27
28
29
30
31 public static final String READ_EXCEPTION_NAME_PATTERN = "manageableReadExceptionNamePattern";
32
33
34
35
36 public static final String UPDATE_EXCEPTION_NAME_PATTERN = "manageableUpdateExceptionNamePattern";
37
38
39
40
41 public static final String DELETE_EXCEPTION_NAME_PATTERN = "manageableDeleteExceptionNamePattern";
42
43
44
45
46 public static final String SERVICE_JNDI_NAME_PREFIX = "jndiNamePrefix";
47
48
49
50
51 public static final String MANAGEABLE_SERVICE_BASE_NAME_PATTERN = "manageableServiceBaseNamePattern";
52
53
54
55
56
57
58
59 public EJB3ManageableEntityFacadeLogicImpl(final Object metaObject, final String context)
60 {
61 super (metaObject, context);
62 }
63
64
65
66
67 @Override
68 protected String handleGetManageableServiceCreateExceptionName()
69 {
70 String exceptionNamePattern = (String)this.getConfiguredProperty(CREATE_EXCEPTION_NAME_PATTERN);
71
72 return MessageFormat.format(
73 exceptionNamePattern,
74 StringUtils.trimToEmpty(this.getName()));
75 }
76
77
78
79
80 @Override
81 protected String handleGetFullyQualifiedManageableServiceCreateExceptionName()
82 {
83 return EJB3MetafacadeUtils.getFullyQualifiedName(
84 this.getManageablePackageName(),
85 this.getManageableServiceCreateExceptionName(),
86 null);
87 }
88
89
90
91
92 @Override
93 protected String handleGetManageableServiceReadExceptionName()
94 {
95 String exceptionNamePattern = (String)this.getConfiguredProperty(READ_EXCEPTION_NAME_PATTERN);
96
97 return MessageFormat.format(
98 exceptionNamePattern,
99 StringUtils.trimToEmpty(this.getName()));
100 }
101
102
103
104
105 @Override
106 protected String handleGetFullyQualifiedManageableServiceReadExceptionName()
107 {
108 return EJB3MetafacadeUtils.getFullyQualifiedName(
109 this.getManageablePackageName(),
110 this.getManageableServiceReadExceptionName(),
111 null);
112 }
113
114
115
116
117 @Override
118 protected String handleGetManageableServiceUpdateExceptionName()
119 {
120 String exceptionNamePattern = (String)this.getConfiguredProperty(UPDATE_EXCEPTION_NAME_PATTERN);
121
122 return MessageFormat.format(
123 exceptionNamePattern,
124 StringUtils.trimToEmpty(this.getName()));
125 }
126
127
128
129
130 @Override
131 protected String handleGetFullyQualifiedManageableServiceUpdateExceptionName()
132 {
133 return EJB3MetafacadeUtils.getFullyQualifiedName(
134 this.getManageablePackageName(),
135 this.getManageableServiceUpdateExceptionName(),
136 null);
137 }
138
139
140
141
142 @Override
143 protected String handleGetManageableServiceDeleteExceptionName()
144 {
145 String exceptionNamePattern = (String)this.getConfiguredProperty(DELETE_EXCEPTION_NAME_PATTERN);
146
147 return MessageFormat.format(
148 exceptionNamePattern,
149 StringUtils.trimToEmpty(this.getName()));
150 }
151
152
153
154
155 @Override
156 protected String handleGetFullyQualifiedManageableServiceDeleteExceptionName()
157 {
158 return EJB3MetafacadeUtils.getFullyQualifiedName(
159 this.getManageablePackageName(),
160 this.getManageableServiceDeleteExceptionName(),
161 null);
162 }
163
164
165
166
167
168 protected String handleGetDefaultPersistenceContextUnitName()
169 {
170 return StringUtils.trimToEmpty(
171 ObjectUtils.toString(this.getConfiguredProperty(EJB3Globals.PERSISTENCE_CONTEXT_UNIT_NAME)));
172 }
173
174
175
176
177 @Override
178 protected String handleGetJndiNamePrefix()
179 {
180 return this.isConfiguredProperty(SERVICE_JNDI_NAME_PREFIX) ?
181 ObjectUtils.toString(this.getConfiguredProperty(SERVICE_JNDI_NAME_PREFIX)) : null;
182 }
183
184
185
186
187 @Override
188 protected String handleGetManageableServiceBaseName()
189 {
190 String exceptionNamePattern = (String)this.getConfiguredProperty(MANAGEABLE_SERVICE_BASE_NAME_PATTERN);
191
192 return MessageFormat.format(
193 exceptionNamePattern,
194 StringUtils.trimToEmpty(this.getManageableServiceName()));
195 }
196
197
198
199
200 @Override
201 protected String handleGetManageableServiceBaseFullPath()
202 {
203 return StringUtils.replace(this.getFullyQualifiedManageableServiceBaseName(), ".", "/");
204 }
205
206
207
208
209 @Override
210 protected String handleGetFullyQualifiedManageableServiceBaseName()
211 {
212 return EJB3MetafacadeUtils.getFullyQualifiedName(
213 this.getManageablePackageName(),
214 this.getManageableServiceBaseName(),
215 null);
216 }
217
218
219
220
221 @Override
222 protected String handleGetManageableRolesAllowed()
223 {
224 StringBuilder rolesAllowed = null;
225 String[] roles = StringUtils.split(
226 StringUtils.trimToEmpty(
227 ObjectUtils.toString(this.getConfiguredProperty(EJB3Globals.MANAGEABLE_ROLES_ALLOWED))),
228 ',');
229 String separator = "";
230
231 for (int i = 0; i < roles.length; i++)
232 {
233 if (rolesAllowed == null)
234 {
235 rolesAllowed = new StringBuilder();
236 }
237 rolesAllowed.append(separator);
238 rolesAllowed.append('"');
239 rolesAllowed.append(roles[i]);
240 rolesAllowed.append('"');
241 separator = ", ";
242 }
243 return rolesAllowed != null ? rolesAllowed.toString() : null;
244 }
245
246
247
248
249
250
251
252 @Override
253 public ModelElementFacade getIdentifier()
254 {
255 return super.getIdentifiers().iterator().next();
256 }
257
258
259
260
261
262
263
264 @Override public List getAllInstanceAttributes()
265 {
266 return EJB3MetafacadeUtils.getAllInstanceAttributes(this);
267 }
268
269
270
271
272
273
274
275 @Override
276 public List getInheritedInstanceAttributes()
277 {
278 return EJB3MetafacadeUtils.getInheritedInstanceAttributes(this);
279 }
280
281
282
283
284
285
286
287 @Override
288 public Collection getInstanceAttributes(final boolean follow, final boolean withIdentifiers)
289 {
290 final Collection attributes = this.getAttributes(follow, withIdentifiers);
291 CollectionUtils.filter(
292 attributes,
293 new Predicate()
294 {
295 public boolean evaluate(final Object object)
296 {
297 boolean valid = true;
298 if (object instanceof EntityAttribute)
299 {
300 valid = !((EntityAttribute)object).isStatic();
301 }
302 return valid;
303 }
304 });
305 return attributes;
306 }
307 }