View Javadoc
1   package org.andromda.cartridges.bpm4struts.metafacades;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.Iterator;
6   import java.util.LinkedHashSet;
7   import java.util.List;
8   import java.util.Set;
9   import org.andromda.metafacades.uml.FrontEndAction;
10  import org.andromda.metafacades.uml.FrontEndUseCase;
11  import org.andromda.metafacades.uml.TransitionFacade;
12  import org.andromda.metafacades.uml.UMLProfile;
13  import org.andromda.metafacades.uml.UseCaseFacade;
14  import org.apache.commons.lang.StringUtils;
15  
16  /**
17   * MetafacadeLogic implementation.
18   *
19   * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsFinalState
20   * @author Bob Fields
21   */
22  public class StrutsFinalStateLogicImpl
23      extends StrutsFinalStateLogic
24  {
25      private static final long serialVersionUID = 34L;
26      /**
27       * @param metaObject
28       * @param context
29       */
30      public StrutsFinalStateLogicImpl(
31          Object metaObject,
32          String context)
33      {
34          super(metaObject, context);
35      }
36  
37      /**
38       * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
39       */
40      public String getName()
41      {
42          String name = super.getName();
43  
44          if (name == null)
45          {
46              final UseCaseFacade useCase = this.getTargetUseCase();
47              if (useCase != null)
48              {
49                  name = useCase.getName();
50              }
51          }
52  
53          return name;
54      }
55  
56      /**
57       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsFinalStateLogic#handleGetFullPath()
58       */
59      protected String handleGetFullPath()
60      {
61          String fullPath = null;
62  
63          final StrutsUseCase useCase = (StrutsUseCase)this.getTargetUseCase();
64          if (useCase == null)
65          {
66              // perhaps this final state links outside of the UML model
67              final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_EXTERNAL_HYPERLINK);
68              if (taggedValue == null)
69              {
70                  String name = getName();
71                  if (StringUtils.isNotBlank(name) && ((name.charAt(0) == '/') || name.startsWith("http://")))
72                  {
73                      fullPath = name;
74                  }
75              }
76              else
77              {
78                  fullPath = String.valueOf(taggedValue);
79              }
80          }
81          else
82          {
83              fullPath = useCase.getActionPath() + ".do";
84          }
85          return fullPath;
86      }
87  
88      /**
89       * Overridden for now (//TODO need to figure out why it doesn't work correctly when using
90       * the one from the FrontEndFinalState).
91       *
92       * @see org.andromda.metafacades.uml.FrontEndFinalState#getTargetUseCase()
93       */
94      public FrontEndUseCase getTargetUseCase()
95      {
96          FrontEndUseCase targetUseCase = null;
97          // first check if there is a hyperlink from this final state to a use-case
98          // this works at least in MagicDraw
99          final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_MODEL_HYPERLINK);
100         if (taggedValue != null)
101         {
102             if (taggedValue instanceof StrutsActivityGraph)
103             {
104                 targetUseCase = (FrontEndUseCase)((StrutsActivityGraph)taggedValue).getUseCase();
105             }
106             else if (taggedValue instanceof StrutsUseCase)
107             {
108                 targetUseCase = (FrontEndUseCase)taggedValue;
109             }
110         }
111 
112         // maybe the name points to a use-case ?
113         if (targetUseCase == null)
114         {
115             final String name = super.getName();
116             if (StringUtils.isNotBlank(name))
117             {
118                 UseCaseFacade useCase = getModel().findUseCaseByName(name);
119                 if (useCase instanceof FrontEndUseCase)
120                 {
121                     targetUseCase = (FrontEndUseCase)useCase;
122                 }
123             }
124         }
125         return targetUseCase;
126     }
127 
128     /**
129      * Need to override default handling in StateVertexFacade.handleGetActions()
130      * @return handleGetActions()
131      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsFinalStateLogicImpl#handleGetActions()
132      */
133     public List<FrontEndAction> getActions()
134     {
135         return handleGetActions();
136     }
137 
138     /**
139      * @return getIncomings().getActions()
140      * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsFinalStateLogicImpl#handleGetActions()
141      */
142     // TODO StateVertexFacade.handleGetActions calls getOutgoings. Why?
143     // Changed from previous handleGetActions because that could never be called by FacadeLogic which delegates to StateVertexFacade.
144     //@Override
145     protected List<FrontEndAction> handleGetActions()
146     {
147         Set<FrontEndAction> actions = new LinkedHashSet<FrontEndAction>();
148         Collection<TransitionFacade> incomings = this.getIncomings();
149 
150         for (final Iterator<TransitionFacade> incomingIterator = incomings.iterator(); incomingIterator.hasNext();)
151         {
152             StrutsForward forward = (StrutsForward)incomingIterator.next();
153             actions.addAll(forward.getActions());
154         }
155         return new ArrayList<FrontEndAction>(actions);
156     }
157 }