View Javadoc

1   package org.andromda.cartridges.bpm4struts.metafacades;
2   
3   import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals;
4   import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile;
5   import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils;
6   import org.andromda.utils.StringUtilsHelper;
7   import org.andromda.metafacades.uml.ClassifierFacade;
8   
9   
10  /**
11   * MetafacadeLogic implementation for org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttribute.
12   *
13   * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttribute
14   */
15  public class StrutsManageableEntityAttributeLogicImpl
16      extends StrutsManageableEntityAttributeLogic
17  {
18      public StrutsManageableEntityAttributeLogicImpl(
19          Object metaObject,
20          String context)
21      {
22          super(metaObject, context);
23      }
24  
25      /**
26       * @see StrutsManageableEntityAttribute#getMessageKey()
27       */
28      protected java.lang.String handleGetMessageKey()
29      {
30          String titleKey = "";
31  
32          final ClassifierFacade owner = getOwner();
33          if (owner != null)
34          {
35              titleKey += owner.getName() + '.';
36          }
37  
38          return StringUtilsHelper.toResourceMessageKey(titleKey + getName());
39      }
40  
41      /**
42       * @see StrutsManageableEntityAttribute#getMessageValue()
43       */
44      protected java.lang.String handleGetMessageValue()
45      {
46          return StringUtilsHelper.toPhrase(getName());
47      }
48  
49      private String internalGetDateFormat()
50      {
51          String dateFormat = null;
52  
53          if (this.getType() != null && this.getType().isDateType())
54          {
55              final Object taggedValueObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_FORMAT);
56              if (taggedValueObject == null)
57              {
58                  dateFormat = (String)this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_DATEFORMAT);
59              }
60              else
61              {
62                  dateFormat = taggedValueObject.toString();
63              }
64          }
65  
66          return dateFormat;
67      }
68  
69      protected java.lang.String handleGetDateFormat()
70      {
71          String dateFormat = this.internalGetDateFormat();
72  
73          if (dateFormat != null)
74          {
75              final String[] tokens = dateFormat.split("[\\s]+");
76              int tokenIndex = 0;
77              if (tokenIndex < tokens.length && tokens[tokenIndex].trim().equals("strict"))
78              {
79                  tokenIndex++;
80              }
81              if (tokenIndex < tokens.length)
82              {
83                  dateFormat = tokens[tokenIndex].trim();
84              }
85          }
86  
87          return dateFormat;
88      }
89  
90      protected boolean handleIsStrictDateFormat()
91      {
92          final String dateFormat = this.internalGetDateFormat();
93          return (dateFormat != null && dateFormat.trim().startsWith("strict"));
94      }
95  
96      protected boolean handleIsNeedsFileUpload()
97      {
98          return this.getType() != null && this.getType().isBlobType();
99      }
100 
101     protected boolean handleIsHidden()
102     {
103         return !this.isDisplay() || Bpm4StrutsProfile.TAGGEDVALUE_INPUT_TYPE_HIDDEN.equals(this.getWidgetType());
104     }
105 
106     protected String handleGetWidgetType()
107     {
108         final Object widgetTag = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_TYPE);
109         return (widgetTag == null) ? Bpm4StrutsProfile.TAGGEDVALUE_INPUT_TYPE_TEXT : widgetTag.toString();
110     }
111 
112     protected Integer handleGetFieldColumnCount()
113     {
114         Integer columnCount = null;
115 
116         Object columnCountObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_COLUMN_COUNT);
117         if (columnCountObject == null)
118         {
119             columnCountObject = this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_INPUT_COLUMN_COUNT);
120         }
121 
122         if (columnCountObject != null)
123         {
124             try
125             {
126                 columnCount = Integer.valueOf(columnCountObject.toString());
127             }
128             catch (NumberFormatException e)
129             {
130                 // do nothing, we want columnCount to be null in case of an invalid value
131             }
132         }
133 
134         return columnCount;
135     }
136 
137     protected Integer handleGetFieldRowCount()
138     {
139         Integer rowCount = null;
140 
141         Object rowCountObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_ROW_COUNT);
142         if (rowCountObject == null)
143         {
144             rowCountObject = this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_INPUT_ROW_COUNT);
145         }
146 
147         if (rowCountObject != null)
148         {
149             try
150             {
151                 rowCount = Integer.valueOf(rowCountObject.toString());
152             }
153             catch (NumberFormatException e)
154             {
155                 // do nothing, we want rowCount to be null in case of an invalid value
156             }
157         }
158 
159         return rowCount;
160     }
161 
162     protected boolean handleIsSafeNamePresent()
163     {
164         return Bpm4StrutsUtils.isSafeName(this.getName());
165     }
166 
167     protected String handleGetOnlineHelpKey()
168     {
169         return this.getMessageKey() + ".online.help";
170     }
171 
172     protected String handleGetOnlineHelpValue()
173     {
174         final String value = StringUtilsHelper.toResourceMessage(this.getDocumentation("", 64, false));
175         return (value == null) ? "No field documentation has been specified" : value;
176     }
177 }