001package org.andromda.cartridges.bpm4struts.metafacades; 002 003import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals; 004import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile; 005import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils; 006import org.andromda.metafacades.uml.ClassifierFacade; 007import org.andromda.utils.StringUtilsHelper; 008 009/** 010 * MetafacadeLogic implementation for org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttribute. 011 * 012 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttribute 013 */ 014public class StrutsManageableEntityAttributeLogicImpl 015 extends StrutsManageableEntityAttributeLogic 016{ 017 private static final long serialVersionUID = 34L; 018 /** 019 * @param metaObject 020 * @param context 021 */ 022 public StrutsManageableEntityAttributeLogicImpl( 023 Object metaObject, 024 String context) 025 { 026 super(metaObject, context); 027 } 028 029 /** 030 * @return messageKey 031 * @see StrutsManageableEntityAttribute#getMessageKey() 032 */ 033 protected String handleGetMessageKey() 034 { 035 String titleKey = ""; 036 037 final ClassifierFacade owner = getOwner(); 038 if (owner != null) 039 { 040 titleKey += owner.getName() + '.'; 041 } 042 043 return StringUtilsHelper.toResourceMessageKey(titleKey + getName()); 044 } 045 046 /** 047 * @return messageValue 048 * @see StrutsManageableEntityAttribute#getMessageValue() 049 */ 050 protected String handleGetMessageValue() 051 { 052 return StringUtilsHelper.toPhrase(getName()); 053 } 054 055 private String internalGetDateFormat() 056 { 057 String dateFormat = null; 058 059 if (this.getType() != null && this.getType().isDateType()) 060 { 061 final Object taggedValueObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_FORMAT); 062 if (taggedValueObject == null) 063 { 064 dateFormat = (String)this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_DATEFORMAT); 065 } 066 else 067 { 068 dateFormat = taggedValueObject.toString(); 069 } 070 } 071 072 return dateFormat; 073 } 074 075 /** 076 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetDateFormat() 077 */ 078 protected String handleGetDateFormat() 079 { 080 String dateFormat = this.internalGetDateFormat(); 081 082 if (dateFormat != null) 083 { 084 final String[] tokens = dateFormat.split("[\\s]+"); 085 int tokenIndex = 0; 086 if (tokenIndex < tokens.length && "strict".equals(tokens[tokenIndex].trim())) 087 { 088 tokenIndex++; 089 } 090 if (tokenIndex < tokens.length) 091 { 092 dateFormat = tokens[tokenIndex].trim(); 093 } 094 } 095 096 return dateFormat; 097 } 098 099 /** 100 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleIsStrictDateFormat() 101 */ 102 protected boolean handleIsStrictDateFormat() 103 { 104 final String dateFormat = this.internalGetDateFormat(); 105 return (dateFormat != null && dateFormat.trim().startsWith("strict")); 106 } 107 108 /** 109 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleIsNeedsFileUpload() 110 */ 111 protected boolean handleIsNeedsFileUpload() 112 { 113 return this.getType() != null && this.getType().isBlobType(); 114 } 115 116 /** 117 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleIsHidden() 118 */ 119 protected boolean handleIsHidden() 120 { 121 return !this.isDisplay() || Bpm4StrutsProfile.TAGGEDVALUE_INPUT_TYPE_HIDDEN.equals(this.getWidgetType()); 122 } 123 124 /** 125 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetWidgetType() 126 */ 127 protected String handleGetWidgetType() 128 { 129 final Object widgetTag = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_TYPE); 130 return (widgetTag == null) ? Bpm4StrutsProfile.TAGGEDVALUE_INPUT_TYPE_TEXT : widgetTag.toString(); 131 } 132 133 /** 134 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetFieldColumnCount() 135 */ 136 protected Integer handleGetFieldColumnCount() 137 { 138 Integer columnCount = null; 139 140 Object columnCountObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_COLUMN_COUNT); 141 if (columnCountObject == null) 142 { 143 columnCountObject = this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_INPUT_COLUMN_COUNT); 144 } 145 146 if (columnCountObject != null) 147 { 148 try 149 { 150 columnCount = Integer.valueOf(columnCountObject.toString()); 151 } 152 catch (NumberFormatException ignore) 153 { 154 // do nothing, we want columnCount to be null in case of an invalid value 155 } 156 } 157 158 return columnCount; 159 } 160 161 /** 162 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetFieldRowCount() 163 */ 164 protected Integer handleGetFieldRowCount() 165 { 166 Integer rowCount = null; 167 168 Object rowCountObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_ROW_COUNT); 169 if (rowCountObject == null) 170 { 171 rowCountObject = this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_INPUT_ROW_COUNT); 172 } 173 174 if (rowCountObject != null) 175 { 176 try 177 { 178 rowCount = Integer.valueOf(rowCountObject.toString()); 179 } 180 catch (NumberFormatException ignore) 181 { 182 // do nothing, we want rowCount to be null in case of an invalid value 183 } 184 } 185 186 return rowCount; 187 } 188 189 /** 190 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleIsSafeNamePresent() 191 */ 192 protected boolean handleIsSafeNamePresent() 193 { 194 return Bpm4StrutsUtils.isSafeName(this.getName()); 195 } 196 197 /** 198 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetOnlineHelpKey() 199 */ 200 protected String handleGetOnlineHelpKey() 201 { 202 return this.getMessageKey() + ".online.help"; 203 } 204 205 /** 206 * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetOnlineHelpValue() 207 */ 208 protected String handleGetOnlineHelpValue() 209 { 210 return (!this.isDocumentationPresent()) ? "No field documentation has been specified" : 211 StringUtilsHelper.toResourceMessage(this.getDocumentation("", 64, false)); 212 } 213}