View Javadoc
1   package org.andromda.cartridges.jsf.metafacades;
2   
3   import java.util.Collection;
4   import java.util.Collections;
5   import java.util.Iterator;
6   import java.util.LinkedHashMap;
7   import java.util.Map;
8   import org.andromda.cartridges.jsf.JSFGlobals;
9   import org.andromda.cartridges.jsf.JSFProfile;
10  import org.andromda.cartridges.jsf.JSFUtils;
11  import org.andromda.metafacades.uml.StateVertexFacade;
12  import org.andromda.utils.StringUtilsHelper;
13  
14  /**
15   * MetafacadeLogic implementation for org.andromda.cartridges.jsf.metafacades.JSFForward.
16   *
17   * @see org.andromda.cartridges.jsf.metafacades.JSFForward
18   */
19  public class JSFForwardLogicImpl
20      extends JSFForwardLogic
21  {
22      private static final long serialVersionUID = 34L;
23      /**
24       * @param metaObject
25       * @param context
26       */
27      public JSFForwardLogicImpl(Object metaObject, String context)
28      {
29          super(metaObject, context);
30      }
31  
32      /**
33       * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
34       */
35      public String getName()
36      {
37          StringBuilder name = new StringBuilder(super.getName());
38          final Object target = this.getTarget();
39          if (target instanceof JSFFinalState)
40          {
41              name.append(JSFGlobals.USECASE_FORWARD_NAME_SUFFIX);
42          }
43          else
44          {
45              name.insert(0, this.getUseCase().getName() + "-");
46          }
47          return JSFUtils.toWebResourceName(name.toString());
48      }
49  
50      /**
51       * @return forwardPath
52       * @see org.andromda.cartridges.jsf.metafacades.JSFForward#getPath()
53       */
54      protected String handleGetPath()
55      {
56          String forwardPath = null;
57          final StateVertexFacade target = getTarget();
58          if (this.isEnteringView())
59          {
60              forwardPath = ((JSFView)target).getPath();
61          }
62          else if (this.isEnteringFinalState())
63          {
64              forwardPath = ((JSFFinalState)target).getPath();
65          }
66  
67          return forwardPath;
68      }
69  
70      /**
71       * @see org.andromda.cartridges.jsf.metafacades.JSFForwardLogic#handleIsSuccessMessagesPresent()
72       */
73      protected boolean handleIsSuccessMessagesPresent()
74      {
75          return !this.getSuccessMessages().isEmpty();
76      }
77  
78      /**
79       * @see org.andromda.cartridges.jsf.metafacades.JSFForwardLogic#handleIsWarningMessagesPresent()
80       */
81      protected boolean handleIsWarningMessagesPresent()
82      {
83          return !this.getWarningMessages().isEmpty();
84      }
85  
86      /**
87       * Collects specific messages in a map.
88       *
89       * @param taggedValue the tagged value from which to read the message
90       * @return maps message keys to message values, but only those that match the arguments
91       *         will have been recorded
92       */
93      @SuppressWarnings("unchecked")
94      private Map<String, String> getMessages(String taggedValue)
95      {
96          Map<String, String> messages;
97  
98          final Collection taggedValues = this.findTaggedValues(taggedValue);
99          if (taggedValues.isEmpty())
100         {
101             messages = Collections.EMPTY_MAP;
102         }
103         else
104         {
105             messages = new LinkedHashMap<String, String>(); // we want to keep the order
106 
107             for (final Iterator iterator = taggedValues.iterator(); iterator.hasNext();)
108             {
109                 final String value = (String)iterator.next();
110                 messages.put(StringUtilsHelper.toResourceMessageKey(value), value);
111             }
112         }
113 
114         return messages;
115     }
116 
117     /**
118      * @see org.andromda.cartridges.jsf.metafacades.JSFForwardLogic#handleGetSuccessMessages()
119      */
120     protected Map handleGetSuccessMessages()
121     {
122         return this.getMessages(JSFProfile.TAGGEDVALUE_ACTION_SUCCESS_MESSAGE);
123     }
124 
125     /**
126      * @see org.andromda.cartridges.jsf.metafacades.JSFForwardLogic#handleGetWarningMessages()
127      */
128     protected Map handleGetWarningMessages()
129     {
130         return this.getMessages(JSFProfile.TAGGEDVALUE_ACTION_WARNING_MESSAGE);
131     }
132 
133     /**
134      * @return getTarget() instanceof JSFFinalState
135      * @see org.andromda.cartridges.jsf.metafacades.JSFForward#isFinalStateTarget()
136      */
137     protected boolean handleIsFinalStateTarget()
138     {
139         return this.getTarget() instanceof JSFFinalState;
140     }
141 
142     /**
143      * @return getName()
144      * @see org.andromda.cartridges.jsf.metafacades.JSFForward#getFromOutcome()
145      */
146     protected String handleGetFromOutcome()
147     {
148         return this.getName();
149     }
150 }