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