View Javadoc
1   package org.andromda.metafacades.uml14;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.Iterator;
6   import java.util.LinkedHashMap;
7   import java.util.List;
8   import java.util.Map;
9   import org.andromda.metafacades.uml.FrontEndActivityGraph;
10  import org.andromda.metafacades.uml.FrontEndForward;
11  import org.andromda.metafacades.uml.FrontEndParameter;
12  import org.andromda.metafacades.uml.FrontEndUseCase;
13  import org.andromda.metafacades.uml.TransitionFacade;
14  import org.andromda.metafacades.uml.UMLProfile;
15  import org.andromda.metafacades.uml.UseCaseFacade;
16  import org.apache.commons.lang.StringUtils;
17  
18  /**
19   * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndFinalState.
20   *
21   * @see org.andromda.metafacades.uml.FrontEndFinalState
22   * @author Bob Fields
23   */
24  public class FrontEndFinalStateLogicImpl
25      extends FrontEndFinalStateLogic
26  {
27      private static final long serialVersionUID = -3707764533520958069L;
28  
29      /**
30       * @param metaObject
31       * @param context
32       */
33      public FrontEndFinalStateLogicImpl (Object metaObject, String context)
34      {
35          super (metaObject, context);
36      }
37  
38      /**
39       * @see org.andromda.metafacades.uml.FrontEndFinalState#isContainedInFrontEndUseCase()
40       */
41      @Override
42      protected boolean handleIsContainedInFrontEndUseCase()
43      {
44          return this.getStateMachine() instanceof FrontEndActivityGraph;
45      }
46  
47      /**
48       * @see org.andromda.metafacades.uml14.ModelElementFacadeLogicImpl#handleGetName()
49       */
50      @Override
51      public String handleGetName()
52      {
53          String name = super.handleGetName();
54          if (name == null)
55          {
56              FrontEndUseCase useCase = this.getTargetUseCase();
57              if (useCase != null)
58              {
59                  name = useCase.getName();
60              }
61          }
62          return name;
63      }
64  
65      /**
66       * @see org.andromda.metafacades.uml.FrontEndFinalState#getTargetUseCase()
67       */
68      @Override
69      protected Object handleGetTargetUseCase()
70      {
71          Object targetUseCase = null;
72  
73          // first check if there is a hyperlink from this final state to a use-case
74          // this works at least in MagicDraw
75          final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_MODEL_HYPERLINK);
76          if (taggedValue != null)
77          {
78              if (taggedValue instanceof FrontEndActivityGraph)
79              {
80                  targetUseCase = ((FrontEndActivityGraph)taggedValue).getUseCase();
81              }
82              else if (taggedValue instanceof FrontEndUseCase)
83              {
84                  targetUseCase = taggedValue;
85              }
86          }
87  
88          // maybe the name points to a use-case ?
89          if (targetUseCase == null)
90          {
91              final String name = super.handleGetName();
92              if (StringUtils.isNotBlank(name))
93              {
94                  final UseCaseFacade useCase = getModel().findUseCaseByName(name);
95                  if (useCase instanceof FrontEndUseCase)
96                  {
97                      targetUseCase = useCase;
98                  }
99              }
100         }
101         return targetUseCase;
102     }
103 
104     /**
105      * @see org.andromda.metafacades.uml.FrontEndFinalState#getInterUseCaseParameters()
106      */
107     @Override
108     protected List<FrontEndParameter> handleGetInterUseCaseParameters()
109     {
110         // we don't want to list parameters with the same name to we use a hash map
111         final Map<String, FrontEndParameter> parameterMap = new LinkedHashMap<String, FrontEndParameter>();
112 
113         final Collection<TransitionFacade> transitions = getIncomings();
114         for (final Iterator<TransitionFacade> transitionIterator = transitions.iterator(); transitionIterator.hasNext();)
115         {
116             final FrontEndForward forward = (FrontEndForward)transitionIterator.next();
117             final List<FrontEndParameter> forwardParameters = forward.getForwardParameters();
118             for (int i = 0; i < forwardParameters.size(); i++)
119             {
120                 final FrontEndParameter parameter = forwardParameters.get(i);
121                 parameterMap.put(parameter.getName(), parameter);
122             }
123         }
124 
125         return new ArrayList<FrontEndParameter>(parameterMap.values());
126     }
127 }