001package org.andromda.cartridges.bpm4struts.metafacades; 002 003import java.util.Collection; 004import java.util.Iterator; 005import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals; 006import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile; 007import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils; 008import org.andromda.metafacades.uml.AttributeFacade; 009import org.andromda.metafacades.uml.ManageableEntityAttribute; 010import org.andromda.metafacades.uml.UMLMetafacadeProperties; 011import org.andromda.utils.StringUtilsHelper; 012import org.apache.commons.lang.StringUtils; 013 014/** 015 * MetafacadeLogic implementation for org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntity. 016 * 017 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntity 018 */ 019public class StrutsManageableEntityLogicImpl 020 extends StrutsManageableEntityLogic 021{ 022 private static final long serialVersionUID = 34L; 023 /** 024 * @return the configured property denoting the character sequence to use for the separation of namespaces 025 */ 026 private String getNamespaceProperty() 027 { 028 return (String)this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR); 029 } 030 031 /** 032 * @param metaObject 033 * @param context 034 */ 035 public StrutsManageableEntityLogicImpl( 036 Object metaObject, 037 String context) 038 { 039 super(metaObject, context); 040 } 041 042 /** 043 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleIsMultipartFormData() 044 */ 045 protected boolean handleIsMultipartFormData() 046 { 047 boolean multipartFormPost = false; 048 049 final Collection<ManageableEntityAttribute> formFields = this.getManageableAttributes(); 050 for (final Iterator fieldIterator = formFields.iterator(); !multipartFormPost && fieldIterator.hasNext();) 051 { 052 final AttributeFacade field = (AttributeFacade)fieldIterator.next(); 053 if (field.getType().isFileType()) 054 { 055 multipartFormPost = true; 056 } 057 } 058 059 return multipartFormPost; 060 } 061 062 /** 063 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanType() 064 */ 065 protected String handleGetFormBeanType() 066 { 067 return this.getManageablePackageName() + this.getNamespaceProperty() + this.getFormBeanClassName(); 068 } 069 070 /** 071 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanClassName() 072 */ 073 protected String handleGetFormBeanClassName() 074 { 075 return this.getName() + Bpm4StrutsGlobals.FORM_SUFFIX; 076 } 077 078 /** 079 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetFormBeanFullPath() 080 */ 081 protected String handleGetFormBeanFullPath() 082 { 083 return StringUtils.replace(this.getFormBeanType(), this.getNamespaceProperty(), "/"); 084 } 085 086 /** 087 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetMessageKey() 088 */ 089 protected String handleGetMessageKey() 090 { 091 return StringUtilsHelper.toResourceMessageKey(this.getName()); 092 } 093 094 /** 095 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityLogic#handleGetMessageValue() 096 */ 097 protected String handleGetMessageValue() 098 { 099 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}