View Javadoc
1   package org.andromda.metafacades.emf.uml22;
2   
3   import java.util.Collection;
4   import java.util.Iterator;
5   import org.andromda.metafacades.uml.FrontEndAction;
6   import org.andromda.metafacades.uml.FrontEndController;
7   import org.andromda.metafacades.uml.FrontEndUseCase;
8   import org.andromda.metafacades.uml.PseudostateFacade;
9   import org.andromda.metafacades.uml.TransitionFacade;
10  import org.andromda.metafacades.uml.UMLProfile;
11  import org.eclipse.uml2.uml.Class;
12  import org.eclipse.uml2.uml.NamedElement;
13  import org.eclipse.uml2.uml.StateMachine;
14  import org.eclipse.uml2.uml.UseCase;
15  
16  /**
17   * MetafacadeLogic implementation for
18   * org.andromda.metafacades.uml.FrontEndActivityGraph.
19   *
20   * @see org.andromda.metafacades.uml.FrontEndActivityGraph
21   */
22  public class FrontEndActivityGraphLogicImpl
23      extends FrontEndActivityGraphLogic
24  {
25      private static final long serialVersionUID = 34L;
26      /**
27       * @param metaObject
28       * @param context
29       */
30      public FrontEndActivityGraphLogicImpl(
31          final Object metaObject,
32          final String context)
33      {
34          super(metaObject, context);
35      }
36  
37      /**
38       * @see org.andromda.metafacades.uml.FrontEndActivityGraph#isContainedInFrontEndUseCase()
39       */
40      @Override
41      protected boolean handleIsContainedInFrontEndUseCase()
42      {
43          return this.getUseCase() instanceof FrontEndUseCase;
44      }
45  
46      /**
47       * Retrieves the usecase that owns this activity.
48       *
49       * @see org.andromda.metafacades.emf.uml22.ActivityGraphFacadeLogic#handleGetUseCase()
50       */
51      @Override
52      protected UseCase handleGetUseCase()
53      {
54          UseCase useCase = super.handleGetUseCase();
55          if (useCase == null)
56          {
57              useCase =
58                  (UseCase) this.getModel().findUseCaseWithTaggedValueOrHyperlink(
59                      UMLProfile.TAGGEDVALUE_PRESENTATION_USECASE_ACTIVITY,
60                      this.handleGetName());
61          }
62          return useCase;
63      }
64  
65      /**
66       * @see org.andromda.metafacades.uml.FrontEndActivityGraph#getInitialAction()
67       */
68      @Override
69      protected Object handleGetInitialAction()
70      {
71          Object firstAction = null;
72          final Collection<PseudostateFacade> initialStates = this.getInitialStates();
73          if (!initialStates.isEmpty())
74          {
75              final PseudostateFacade initialState = initialStates.iterator().next();
76              final Collection<TransitionFacade> outgoings = initialState.getOutgoings();
77              firstAction = outgoings.isEmpty() ? null : outgoings.iterator().next();
78          }
79          return (FrontEndAction)this.shieldedElement(firstAction);
80      }
81  
82      /**
83       * @see org.andromda.metafacades.uml.FrontEndActivityGraph#getController()
84       */
85      @Override
86      protected Object handleGetController()
87      {
88          // Take the first class inside the FSM
89          Class controller = null;
90          for (final Iterator<NamedElement> it = ((StateMachine)this.metaObject).getOwnedMembers().iterator();
91              it.hasNext() && controller == null;)
92          {
93              final Object next = it.next();
94              if (next instanceof Class)
95              {
96                  controller = (Class)next;
97              }
98          }
99          return (FrontEndController)this.shieldedElement(controller);
100     }
101 }