1 package org.andromda.cartridges.bpm4struts.metafacades;
2
3 import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals;
4 import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils;
5 import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile;
6 import org.andromda.utils.StringUtilsHelper;
7 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
8 import org.andromda.metafacades.uml.AttributeFacade;
9 import org.apache.commons.lang.StringUtils;
10
11 import java.util.Collection;
12 import java.util.Iterator;
13
14
15
16
17
18
19
20 public class StrutsManageableEntityLogicImpl
21 extends StrutsManageableEntityLogic
22 {
23
24
25
26 private String getNamespaceProperty()
27 {
28 return (String)this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR);
29 }
30
31 public StrutsManageableEntityLogicImpl(
32 Object metaObject,
33 String context)
34 {
35 super(metaObject, context);
36 }
37
38 protected boolean handleIsMultipartFormData()
39 {
40 boolean multipartFormPost = false;
41
42 final Collection formFields = this.getManageableAttributes();
43 for (final Iterator fieldIterator = formFields.iterator(); !multipartFormPost && fieldIterator.hasNext();)
44 {
45 final AttributeFacade field = (AttributeFacade)fieldIterator.next();
46 if (field.getType().isFileType())
47 {
48 multipartFormPost = true;
49 }
50 }
51
52 return multipartFormPost;
53 }
54
55 protected String handleGetFormBeanType()
56 {
57 return this.getManageablePackageName() + this.getNamespaceProperty() + this.getFormBeanClassName();
58 }
59
60 protected String handleGetFormBeanClassName()
61 {
62 return this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX;
63 }
64
65 protected String handleGetFormBeanFullPath()
66 {
67 return StringUtils.replace(this.getFormBeanType(), this.getNamespaceProperty(), "/");
68 }
69
70 protected java.lang.String handleGetMessageKey()
71 {
72 return StringUtilsHelper.toResourceMessageKey(this.getName());
73 }
74
75 protected java.lang.String handleGetMessageValue()
76 {
77 return StringUtilsHelper.toPhrase(this.getName());
78 }
79
80 protected java.lang.String handleGetPageTitleKey()
81 {
82 return StringUtilsHelper.toResourceMessageKey(this.getName()) + ".page.title";
83 }
84
85 protected java.lang.String handleGetPageTitleValue()
86 {
87 return StringUtilsHelper.toPhrase(getName());
88 }
89
90 protected java.lang.String handleGetListName()
91 {
92 return "manageableList";
93 }
94
95 protected java.lang.String handleGetListGetterName()
96 {
97 return "getManageableList";
98 }
99
100 protected java.lang.String handleGetListSetterName()
101 {
102 return "setManageableList";
103 }
104
105 protected String handleGetPageName()
106 {
107 return this.getName().toLowerCase() + "-crud.jsp";
108 }
109
110 protected String handleGetPageFullPath()
111 {
112 return '/' + this.getManageablePackagePath() + '/' + this.getPageName();
113 }
114
115 protected java.lang.String handleGetActionPath()
116 {
117 return '/' + this.getName() + "/Manage";
118 }
119
120 protected java.lang.String handleGetActionParameter()
121 {
122 return "crud";
123 }
124
125 protected java.lang.String handleGetFormBeanName()
126 {
127 return "manage" + this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX;
128 }
129
130 protected java.lang.String handleGetActionType()
131 {
132 return this.getManageablePackageName() + this.getNamespaceProperty() + this.getActionClassName();
133 }
134
135 protected java.lang.String handleGetExceptionKey()
136 {
137 return StringUtilsHelper.toResourceMessageKey(this.getName()) + ".exception";
138 }
139
140 protected java.lang.String handleGetExceptionPath()
141 {
142 return this.getPageFullPath();
143 }
144
145 protected java.lang.String handleGetActionFullPath()
146 {
147 return '/' + StringUtils.replace(this.getActionType(), this.getNamespaceProperty(), "/");
148 }
149
150 protected java.lang.String handleGetActionClassName()
151 {
152 return "Manage" + getName();
153 }
154
155 protected boolean handleIsPreload()
156 {
157 return this.isCreate() || this.isRead() || this.isUpdate() || this.isDelete();
158 }
159
160 protected String handleGetOnlineHelpKey()
161 {
162 return this.getMessageKey() + ".online.help";
163 }
164
165 protected String handleGetOnlineHelpValue()
166 {
167 final String value = StringUtilsHelper.toResourceMessage(this.getDocumentation("", 64, false));
168 return (value == null) ? "No entity documentation has been specified" : value;
169 }
170
171 protected String handleGetOnlineHelpActionPath()
172 {
173 return this.getActionPath() + "Help";
174 }
175
176 protected String handleGetOnlineHelpPagePath()
177 {
178 return '/' + this.getManageablePackagePath() + '/' + this.getName().toLowerCase() + "_help";
179 }
180
181 protected boolean handleIsTableExportable()
182 {
183 return this.getTableExportTypes().indexOf("none") == -1;
184 }
185
186 protected String handleGetTableExportTypes()
187 {
188 return Bpm4StrutsUtils.getDisplayTagExportTypes(
189 this.findTaggedValues(Bpm4StrutsProfile.TAGGEDVALUE_TABLE_EXPORT),
190 (String)getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_TABLE_EXPORT_TYPES) );
191 }
192
193 protected boolean handleIsTableSortable()
194 {
195 final Object taggedValue = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_TABLE_SORTABLE);
196 return (taggedValue == null)
197 ? Bpm4StrutsProfile.TAGGEDVALUE_TABLE_SORTABLE_DEFAULT_VALUE
198 : Bpm4StrutsUtils.isTrue(String.valueOf(taggedValue));
199 }
200
201 protected int handleGetTableMaxRows()
202 {
203 final Object taggedValue = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_TABLE_MAXROWS);
204 int pageSize;
205
206 try
207 {
208 pageSize = Integer.parseInt(String.valueOf(taggedValue));
209 }
210 catch (Exception e)
211 {
212 pageSize = Bpm4StrutsProfile.TAGGEDVALUE_TABLE_MAXROWS_DEFAULT_COUNT;
213 }
214
215 return pageSize;
216 }
217 }