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.ActionStateFacade;
6   import org.andromda.metafacades.uml.FinalStateFacade;
7   import org.andromda.metafacades.uml.PseudostateFacade;
8   import org.andromda.metafacades.uml.StateVertexFacade;
9   import org.eclipse.uml2.uml.Action;
10  import org.eclipse.uml2.uml.Behavior;
11  import org.eclipse.uml2.uml.ConnectableElement;
12  import org.eclipse.uml2.uml.Constraint;
13  import org.eclipse.uml2.uml.Transition;
14  import org.eclipse.uml2.uml.Vertex;
15  
16  /**
17   * MetafacadeLogic implementation for
18   * org.andromda.metafacades.uml.TransitionFacade.
19   *
20   * @see org.andromda.metafacades.uml.TransitionFacade
21   */
22  public class TransitionFacadeLogicImpl
23      extends TransitionFacadeLogic
24  {
25      private static final long serialVersionUID = 34L;
26      /**
27       * @param metaObject
28       * @param context
29       */
30      public TransitionFacadeLogicImpl(
31          final Transition metaObject,
32          final String context)
33      {
34          super(metaObject, context);
35      }
36  
37      /**
38       * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleGetEffect()
39       */
40      @Override
41      protected Action handleGetEffect()
42      {
43          // Effect is mapped to action, not activity
44          // We return the first action encountered in the activity
45          Action effectAction = null;
46          final Behavior effect = this.metaObject.getEffect();
47          if (effect != null)
48          {
49              final Collection<ConnectableElement> nodes = effect.getRoles();
50              for (final Iterator<ConnectableElement> nodesIt = nodes.iterator(); nodesIt.hasNext() && effectAction == null;)
51              {
52                  final Object nextNode = nodesIt.next();
53                  if (nextNode instanceof Action)
54                  {
55                      effectAction = (Action)nextNode;
56                  }
57              }
58          }
59          return effectAction;
60      }
61  
62      /**
63       * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleGetSource()
64       */
65      @Override
66      protected Vertex handleGetSource()
67      {
68          return this.metaObject.getSource();
69      }
70  
71      /**
72       * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleGetTarget()
73       */
74      @Override
75      protected Vertex handleGetTarget()
76      {
77          return this.metaObject.getTarget();
78      }
79  
80      /**
81       * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleGetTrigger()
82       */
83      @Override
84      protected Behavior handleGetTrigger()
85      {
86          // We use the effect instead of trigger. It's the same "trick" as
87          // using entry instead of deferrable events
88          return this.metaObject.getEffect();
89      }
90  
91      /**
92       * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleGetGuard()
93       */
94      @Override
95      protected Constraint handleGetGuard()
96      {
97          return this.metaObject.getGuard();
98      }
99  
100     /**
101      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsTriggerPresent()
102      */
103     @Override
104     protected boolean handleIsTriggerPresent()
105     {
106         return this.metaObject.getEffect() != null;
107     }
108 
109     /**
110      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsExitingDecisionPoint()
111      */
112     @Override
113     protected boolean handleIsExitingDecisionPoint()
114     {
115         final StateVertexFacade sourceVertex = this.getSource();
116         return sourceVertex instanceof PseudostateFacade && ((PseudostateFacade)sourceVertex).isDecisionPoint();
117     }
118 
119     /**
120      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsEnteringDecisionPoint()
121      */
122     @Override
123     protected boolean handleIsEnteringDecisionPoint()
124     {
125         final StateVertexFacade target = this.getTarget();
126         return target instanceof PseudostateFacade && ((PseudostateFacade)target).isDecisionPoint();
127     }
128 
129     /**
130      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsExitingActionState()
131      */
132     /**
133      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsExitingActionState()
134      */
135     @Override
136     protected boolean handleIsExitingActionState()
137     {
138         return this.getSource() instanceof ActionStateFacade;
139     }
140 
141     /**
142      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsEnteringActionState()
143      */
144     @Override
145     protected boolean handleIsEnteringActionState()
146     {
147         return this.getTarget() instanceof ActionStateFacade;
148     }
149 
150     /**
151      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsExitingInitialState()
152      */
153     @Override
154     protected boolean handleIsExitingInitialState()
155     {
156         final StateVertexFacade sourceVertex = this.getSource();
157         return sourceVertex instanceof PseudostateFacade && ((PseudostateFacade)sourceVertex).isInitialState();
158     }
159 
160     /**
161      * @see org.andromda.metafacades.emf.uml22.TransitionFacadeLogic#handleIsEnteringFinalState()
162      */
163     @Override
164     protected boolean handleIsEnteringFinalState()
165     {
166         return this.getTarget() instanceof FinalStateFacade;
167     }
168 
169     /**
170      * @return this.getTarget().getStateMachine()
171      * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
172      */
173     public Object handleGetValidationOwner()
174     {
175         return this.getTarget().getStateMachine();
176     }
177 }