1 package org.andromda.cartridges.bpm4struts.metafacades;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals;
6 import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile;
7 import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils;
8 import org.andromda.metafacades.uml.AttributeFacade;
9 import org.andromda.metafacades.uml.ManageableEntityAttribute;
10 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
11 import org.andromda.utils.StringUtilsHelper;
12 import org.apache.commons.lang.StringUtils;
13
14
15
16
17
18
19 public class StrutsManageableEntityLogicImpl
20 extends StrutsManageableEntityLogic
21 {
22 private static final long serialVersionUID = 34L;
23
24
25
26 private String getNamespaceProperty()
27 {
28 return (String)this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR);
29 }
30
31
32
33
34
35 public StrutsManageableEntityLogicImpl(
36 Object metaObject,
37 String context)
38 {
39 super(metaObject, context);
40 }
41
42
43
44
45 protected boolean handleIsMultipartFormData()
46 {
47 boolean multipartFormPost = false;
48
49 final Collection<ManageableEntityAttribute> formFields = this.getManageableAttributes();
50 for (final Iterator fieldIterator = formFields.iterator(); !multipartFormPost && fieldIterator.hasNext();)
51 {
52 final AttributeFacade field = (AttributeFacade)fieldIterator.next();
53 if (field.getType().isFileType())
54 {
55 multipartFormPost = true;
56 }
57 }
58
59 return multipartFormPost;
60 }
61
62
63
64
65 protected String handleGetFormBeanType()
66 {
67 return this.getManageablePackageName() + this.getNamespaceProperty() + this.getFormBeanClassName();
68 }
69
70
71
72
73 protected String handleGetFormBeanClassName()
74 {
75 return this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX;
76 }
77
78
79
80
81 protected String handleGetFormBeanFullPath()
82 {
83 return StringUtils.replace(this.getFormBeanType(), this.getNamespaceProperty(), "/");
84 }
85
86
87
88
89 protected String handleGetMessageKey()
90 {
91 return StringUtilsHelper.toResourceMessageKey(this.getName());
92 }
93
94
95
96
97 protected String handleGetMessageValue()
98 {
99 return StringUtilsHelper.toPhrase(this.getName());
100 }
101
102
103
104
105 protected String handleGetPageTitleKey()
106 {
107 return StringUtilsHelper.toResourceMessageKey(this.getName()) + ".page.title";
108 }
109
110
111
112
113 protected String handleGetPageTitleValue()
114 {
115 return StringUtilsHelper.toPhrase(getName());
116 }
117
118
119
120
121 protected String handleGetListName()
122 {
123 return "manageableList";
124 }
125
126
127
128
129 protected String handleGetListGetterName()
130 {
131 return "getManageableList";
132 }
133
134
135
136
137 protected String handleGetListSetterName()
138 {
139 return "setManageableList";
140 }
141
142
143
144
145 protected String handleGetPageName()
146 {
147 return this.getName().toLowerCase() + "-crud.jsp";
148 }
149
150
151
152
153 protected String handleGetPageFullPath()
154 {
155 return '/' + this.getManageablePackagePath() + '/' + this.getPageName();
156 }
157
158
159
160
161 protected String handleGetActionPath()
162 {
163 return '/' + this.getName() + "/Manage";
164 }
165
166
167
168
169 protected String handleGetActionParameter()
170 {
171 return "crud";
172 }
173
174
175
176
177 protected String handleGetFormBeanName()
178 {
179 return "manage" + this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX;
180 }
181
182
183
184
185 protected String handleGetActionType()
186 {
187 return this.getManageablePackageName() + this.getNamespaceProperty() + this.getActionClassName();
188 }
189
190
191
192
193 protected String handleGetExceptionKey()
194 {
195 return StringUtilsHelper.toResourceMessageKey(this.getName()) + ".exception";
196 }
197
198
199
200
201 protected String handleGetExceptionPath()
202 {
203 return this.getPageFullPath();
204 }
205
206
207
208
209 protected String handleGetActionFullPath()
210 {
211 return '/' + StringUtils.replace(this.getActionType(), this.getNamespaceProperty(), "/");
212 }
213
214
215
216
217 protected String handleGetActionClassName()
218 {
219 return "Manage" + getName();
220 }
221
222
223
224
225 protected boolean handleIsPreload()
226 {
227 return this.isCreate() || this.isRead() || this.isUpdate() || this.isDelete();
228 }
229
230
231
232
233 protected String handleGetOnlineHelpKey()
234 {
235 return this.getMessageKey() + ".online.help";
236 }
237
238
239
240
241 protected String handleGetOnlineHelpValue()
242 {
243 return (!this.isDocumentationPresent()) ? "No entity documentation has been specified" :
244 StringUtilsHelper.toResourceMessage(this.getDocumentation("", 64, false));
245 }
246
247
248
249
250 protected String handleGetOnlineHelpActionPath()
251 {
252 return this.getActionPath() + "Help";
253 }
254
255
256
257
258 protected String handleGetOnlineHelpPagePath()
259 {
260 return '/' + this.getManageablePackagePath() + '/' + this.getName().toLowerCase() + "_help";
261 }
262
263
264
265
266 protected boolean handleIsTableExportable()
267 {
268 return this.getTableExportTypes().indexOf("none") == -1;
269 }
270
271
272
273
274 protected String handleGetTableExportTypes()
275 {
276 return Bpm4StrutsUtils.getDisplayTagExportTypes(
277 this.findTaggedValues(Bpm4StrutsProfile.TAGGEDVALUE_TABLE_EXPORT),
278 (String)getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_TABLE_EXPORT_TYPES) );
279 }
280
281
282
283
284 protected boolean handleIsTableSortable()
285 {
286 final Object taggedValue = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_TABLE_SORTABLE);
287 return (taggedValue == null)
288 ? Bpm4StrutsProfile.TAGGEDVALUE_TABLE_SORTABLE_DEFAULT_VALUE
289 : Bpm4StrutsUtils.isTrue(String.valueOf(taggedValue));
290 }
291
292
293
294
295 protected int handleGetTableMaxRows()
296 {
297 final Object taggedValue = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_TABLE_MAXROWS);
298 int pageSize;
299
300 try
301 {
302 pageSize = Integer.parseInt(String.valueOf(taggedValue));
303 }
304 catch (Exception e)
305 {
306 pageSize = Bpm4StrutsProfile.TAGGEDVALUE_TABLE_MAXROWS_DEFAULT_COUNT;
307 }
308
309 return pageSize;
310 }
311 }