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.metafacades.uml.ClassifierFacade;
7   import org.andromda.utils.StringUtilsHelper;
8   
9   /**
10   * MetafacadeLogic implementation for org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttribute.
11   *
12   * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttribute
13   */
14  public class StrutsManageableEntityAttributeLogicImpl
15      extends StrutsManageableEntityAttributeLogic
16  {
17      private static final long serialVersionUID = 34L;
18      /**
19       * @param metaObject
20       * @param context
21       */
22      public StrutsManageableEntityAttributeLogicImpl(
23          Object metaObject,
24          String context)
25      {
26          super(metaObject, context);
27      }
28  
29      /**
30       * @return messageKey
31       * @see StrutsManageableEntityAttribute#getMessageKey()
32       */
33      protected String handleGetMessageKey()
34      {
35          String titleKey = "";
36  
37          final ClassifierFacade owner = getOwner();
38          if (owner != null)
39          {
40              titleKey += owner.getName() + '.';
41          }
42  
43          return StringUtilsHelper.toResourceMessageKey(titleKey + getName());
44      }
45  
46      /**
47       * @return messageValue
48       * @see StrutsManageableEntityAttribute#getMessageValue()
49       */
50      protected String handleGetMessageValue()
51      {
52          return StringUtilsHelper.toPhrase(getName());
53      }
54  
55      private String internalGetDateFormat()
56      {
57          String dateFormat = null;
58  
59          if (this.getType() != null && this.getType().isDateType())
60          {
61              final Object taggedValueObject = this.findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_INPUT_FORMAT);
62              if (taggedValueObject == null)
63              {
64                  dateFormat = (String)this.getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_DATEFORMAT);
65              }
66              else
67              {
68                  dateFormat = taggedValueObject.toString();
69              }
70          }
71  
72          return dateFormat;
73      }
74  
75      /**
76       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsManageableEntityAttributeLogic#handleGetDateFormat()
77       */
78      protected String handleGetDateFormat()
79      {
80          String dateFormat = this.internalGetDateFormat();
81  
82          if (dateFormat != null)
83          {
84              final String[] tokens = dateFormat.split("[\\s]+");
85              int tokenIndex = 0;
86              if (tokenIndex < tokens.length && "strict".equals(tokens[tokenIndex].trim()))
87              {
88                  tokenIndex++;
89              }
90              if (tokenIndex < tokens.length)
91              {
92                  dateFormat = tokens[tokenIndex].trim();
93              }
94          }
95  
96          return dateFormat;
97      }
98  
99      /**
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 }