View Javadoc
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   * MetafacadeLogic implementation for org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntity.
16   *
17   * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntity
18   */
19  public class StrutsManageableEntityLogicImpl
20      extends StrutsManageableEntityLogic
21  {
22      private static final long serialVersionUID = 34L;
23      /**
24       * @return the configured property denoting the character sequence to use for the separation of namespaces
25       */
26      private String getNamespaceProperty()
27      {
28          return (String)this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR);
29      }
30  
31      /**
32       * @param metaObject
33       * @param context
34       */
35      public StrutsManageableEntityLogicImpl(
36          Object metaObject,
37          String context)
38      {
39          super(metaObject, context);
40      }
41  
42      /**
43       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleIsMultipartFormData()
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       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanType()
64       */
65      protected String handleGetFormBeanType()
66      {
67          return this.getManageablePackageName() + this.getNamespaceProperty() + this.getFormBeanClassName();
68      }
69  
70      /**
71       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanClassName()
72       */
73      protected String handleGetFormBeanClassName()
74      {
75          return this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX;
76      }
77  
78      /**
79       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanFullPath()
80       */
81      protected String handleGetFormBeanFullPath()
82      {
83          return StringUtils.replace(this.getFormBeanType(), this.getNamespaceProperty(), "/");
84      }
85  
86      /**
87       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetMessageKey()
88       */
89      protected String handleGetMessageKey()
90      {
91          return StringUtilsHelper.toResourceMessageKey(this.getName());
92      }
93  
94      /**
95       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetMessageValue()
96       */
97      protected String handleGetMessageValue()
98      {
99          return StringUtilsHelper.toPhrase(this.getName());
100     }
101 
102     /**
103      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetPageTitleKey()
104      */
105     protected String handleGetPageTitleKey()
106     {
107         return StringUtilsHelper.toResourceMessageKey(this.getName()) + ".page.title";
108     }
109 
110     /**
111      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetPageTitleValue()
112      */
113     protected String handleGetPageTitleValue()
114     {
115         return StringUtilsHelper.toPhrase(getName());
116     }
117 
118     /**
119      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetListName()
120      */
121     protected String handleGetListName()
122     {
123         return "manageableList";
124     }
125 
126     /**
127      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetListGetterName()
128      */
129     protected String handleGetListGetterName()
130     {
131         return "getManageableList";
132     }
133 
134     /**
135      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetListSetterName()
136      */
137     protected String handleGetListSetterName()
138     {
139         return "setManageableList";
140     }
141 
142     /**
143      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetPageName()
144      */
145     protected String handleGetPageName()
146     {
147         return this.getName().toLowerCase() + "-crud.jsp";
148     }
149 
150     /**
151      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetPageFullPath()
152      */
153     protected String handleGetPageFullPath()
154     {
155         return '/' + this.getManageablePackagePath() + '/' + this.getPageName();
156     }
157 
158     /**
159      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetActionPath()
160      */
161     protected String handleGetActionPath()
162     {
163         return '/' + this.getName() + "/Manage";
164     }
165 
166     /**
167      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetActionParameter()
168      */
169     protected String handleGetActionParameter()
170     {
171         return "crud";
172     }
173 
174     /**
175      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanName()
176      */
177     protected String handleGetFormBeanName()
178     {
179         return "manage" + this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX;
180     }
181 
182     /**
183      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetActionType()
184      */
185     protected String handleGetActionType()
186     {
187         return this.getManageablePackageName() + this.getNamespaceProperty() + this.getActionClassName();
188     }
189 
190     /**
191      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetExceptionKey()
192      */
193     protected String handleGetExceptionKey()
194     {
195         return StringUtilsHelper.toResourceMessageKey(this.getName()) + ".exception";
196     }
197 
198     /**
199      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetExceptionPath()
200      */
201     protected String handleGetExceptionPath()
202     {
203         return this.getPageFullPath();
204     }
205 
206     /**
207      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetActionFullPath()
208      */
209     protected String handleGetActionFullPath()
210     {
211         return '/' + StringUtils.replace(this.getActionType(), this.getNamespaceProperty(), "/");
212     }
213 
214     /**
215      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetActionClassName()
216      */
217     protected String handleGetActionClassName()
218     {
219         return "Manage" + getName();
220     }
221 
222     /**
223      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleIsPreload()
224      */
225     protected boolean handleIsPreload()
226     {
227         return this.isCreate() || this.isRead() || this.isUpdate() || this.isDelete();
228     }
229 
230     /**
231      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetOnlineHelpKey()
232      */
233     protected String handleGetOnlineHelpKey()
234     {
235         return this.getMessageKey() + ".online.help";
236     }
237 
238     /**
239      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetOnlineHelpValue()
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      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetOnlineHelpActionPath()
249      */
250     protected String handleGetOnlineHelpActionPath()
251     {
252         return this.getActionPath() + "Help";
253     }
254 
255     /**
256      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetOnlineHelpPagePath()
257      */
258     protected String handleGetOnlineHelpPagePath()
259     {
260         return '/' + this.getManageablePackagePath() + '/' + this.getName().toLowerCase() + "_help";
261     }
262 
263     /**
264      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleIsTableExportable()
265      */
266     protected boolean handleIsTableExportable()
267     {
268         return this.getTableExportTypes().indexOf("none") == -1;
269     }
270 
271     /**
272      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetTableExportTypes()
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      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleIsTableSortable()
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      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetTableMaxRows()
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 }