View Javadoc
1   package org.andromda.metafacades.uml14;
2   
3   import java.util.Collection;
4   import org.andromda.metafacades.uml.FrontEndController;
5   import org.andromda.metafacades.uml.FrontEndUseCase;
6   import org.andromda.metafacades.uml.ModelElementFacade;
7   import org.andromda.metafacades.uml.PseudostateFacade;
8   import org.andromda.metafacades.uml.TransitionFacade;
9   import org.andromda.metafacades.uml.UMLProfile;
10  import org.andromda.metafacades.uml.UseCaseFacade;
11  
12  
13  /**
14   * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndActivityGraph.
15   *
16   * @see org.andromda.metafacades.uml.FrontEndActivityGraph
17   * @author Bob Fields
18   */
19  public class FrontEndActivityGraphLogicImpl
20      extends FrontEndActivityGraphLogic
21  {
22      private static final long serialVersionUID = 815773525076250652L;
23  
24      /**
25       * @param metaObject
26       * @param context
27       */
28      public FrontEndActivityGraphLogicImpl (Object metaObject, String context)
29      {
30          super (metaObject, context);
31      }
32  
33      /**
34       * @see org.andromda.metafacades.uml.FrontEndActivityGraph#isContainedInFrontEndUseCase()
35       */
36      @Override
37      protected boolean handleIsContainedInFrontEndUseCase()
38      {
39          return this.getUseCase() instanceof FrontEndUseCase;
40      }
41  
42      /**
43       * Retrieves the usecase that owns this activity.
44       *
45       * @see org.andromda.metafacades.uml14.ActivityGraphFacadeLogic#handleGetUseCase()
46       */
47      protected Object handleGetUseCase()
48      {
49          Object useCase = super.handleGetUseCase();
50          if (useCase == null)
51          {
52              useCase = getModel().findUseCaseWithTaggedValueOrHyperlink(UMLProfile.TAGGEDVALUE_PRESENTATION_USECASE_ACTIVITY,
53                      getName());
54          }
55          return useCase;
56      }
57  
58      /**
59       * @see org.andromda.metafacades.uml.FrontEndActivityGraph#getInitialAction()
60       */
61      @Override
62      protected TransitionFacade handleGetInitialAction()
63      {
64          TransitionFacade firstAction = null;
65          final Collection<PseudostateFacade> initialStates = getInitialStates();
66          if (!initialStates.isEmpty())
67          {
68              final PseudostateFacade initialState = initialStates.iterator().next();
69              final Collection<TransitionFacade> outgoings = initialState.getOutgoings();
70              firstAction = outgoings.isEmpty() ? null : outgoings.iterator().next();
71          }
72          return firstAction;
73      }
74  
75      /**
76       * @see org.andromda.metafacades.uml.FrontEndActivityGraph#getController()
77       */
78      @Override
79      protected Object handleGetController()
80      {
81          Object controller = null;
82  
83          final ModelElementFacade contextElement = this.getContextElement();
84          if (contextElement instanceof FrontEndController)
85          {
86              controller = contextElement;
87          }
88  
89           // - for those tools not supporting setting the context of an activity graph (such as Poseidon)
90           //   an alternative is implemented: a tagged value on the controller, specifying the name of the use-case
91           //
92           // It is also allowed to set a hyperlink from the controller to the usecase
93          if (controller == null)
94          {
95              final UseCaseFacade useCase = this.getUseCase();
96              if (useCase != null)
97              {
98                  final String useCaseName = useCase.getName();
99                  controller = this.getModel().findClassWithTaggedValueOrHyperlink(
100                         UMLProfile.TAGGEDVALUE_PRESENTATION_CONTROLLER_USECASE, useCaseName);
101             }
102         }
103         return controller;
104     }
105 }