View Javadoc
1   package org.andromda.metafacades.emf.uml22;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.Iterator;
6   import java.util.List;
7   import org.andromda.metafacades.uml.FrontEndAction;
8   import org.andromda.metafacades.uml.FrontEndControllerOperation;
9   import org.andromda.metafacades.uml.FrontEndUseCase;
10  import org.andromda.metafacades.uml.TransitionFacade;
11  import org.apache.commons.lang.StringUtils;
12  import org.eclipse.uml2.uml.Activity;
13  import org.eclipse.uml2.uml.ActivityNode;
14  import org.eclipse.uml2.uml.CallOperationAction;
15  import org.eclipse.uml2.uml.Element;
16  import org.eclipse.uml2.uml.NamedElement;
17  import org.eclipse.uml2.uml.Operation;
18  import org.eclipse.uml2.uml.Transition;
19  import org.eclipse.uml2.uml.UseCase;
20  
21  /**
22   * MetafacadeLogic implementation for
23   * org.andromda.metafacades.uml.FrontEndEvent.
24   *
25   * @see org.andromda.metafacades.uml.FrontEndEvent
26   */
27  public class FrontEndEventLogicImpl
28      extends FrontEndEventLogic
29  {
30      private static final long serialVersionUID = 34L;
31      /**
32       * @param metaObject
33       * @param context
34       */
35      public FrontEndEventLogicImpl(
36          final Object metaObject,
37          final String context)
38      {
39          super(metaObject, context);
40      }
41  
42      /**
43       * @see org.andromda.metafacades.uml.FrontEndEvent#isContainedInFrontEndUseCase()
44       */
45      @Override
46      protected boolean handleIsContainedInFrontEndUseCase()
47      {
48          // Be careful. Should return true only when it has an owning transition
49          // contained in front end usecase
50          // from UML1.4: return this.getTransition() instanceof FrontEndForward;
51          // Causes stack overflow...
52          Element owner = (Element)this.metaObject;
53          if (!(owner.getOwner() instanceof Transition))
54          {
55              return false;
56          }
57          while (owner != null)
58          {
59              if (owner instanceof UseCase)
60              {
61                  if (this.shieldedElement(owner) instanceof FrontEndUseCase)
62                  {
63                      return true;
64                  }
65              }
66              owner = owner.getOwner();
67          }
68          return false;
69      }
70  
71      /**
72       * @see org.andromda.metafacades.uml.FrontEndEvent#getControllerCall()
73       */
74      @Override
75      protected FrontEndControllerOperation handleGetControllerCall()
76      {
77          final List<FrontEndControllerOperation> operations = this.getControllerCalls();
78          return (operations.isEmpty() ? null : operations.iterator().next());
79      }
80  
81      /**
82       * @see org.andromda.metafacades.uml.FrontEndEvent#getControllerCalls()
83       */
84      @Override
85      public List<Operation> handleGetControllerCalls()
86      {
87          // - get every operation from each CallOperationAction instance.
88          // - Note: this is the same implementation as CallEvent.getOperationCall()
89          final Activity activity = (Activity)this.metaObject;
90          final List<Operation> operations = new ArrayList<Operation>();
91          Collection<ActivityNode> nodes = activity.getNodes();
92          // UML2 v3: What previously was in getNodes is now in getOwnedNodes, while getNodes returns null
93          // This causes JSF cartridge to fail unless implemented
94          if (nodes==null || nodes.isEmpty())
95          {
96              nodes = activity.getOwnedNodes();
97          }
98          for (final Iterator<ActivityNode> iterator = nodes.iterator(); iterator.hasNext();)
99          {
100             final Object nextNode = iterator.next();
101             if (nextNode instanceof CallOperationAction)
102             {
103                 final Operation operation = ((CallOperationAction)nextNode).getOperation();
104                 if (operation != null)
105                 {
106                     operations.add(operation);
107                 }
108             }
109         }
110         return operations;
111     }
112 
113     /**
114      * @see org.andromda.metafacades.uml.FrontEndEvent#getAction()
115      */
116     @Override
117     protected FrontEndAction handleGetAction()
118     {
119         FrontEndAction action = null;
120         final TransitionFacade transition = this.getTransition();
121         if (transition instanceof FrontEndAction)
122         {
123             action = (FrontEndAction)transition;
124         }
125         return action;
126     }
127 
128     /**
129      * UML2 v5: ActivityImpl returns NULL for namespace. Need another way to get package name
130      * @see org.andromda.metafacades.uml.FrontEndEvent#getPackageName()
131      */
132     @Override
133     protected String handleGetPackageName()
134     {
135         String packageName = UmlUtilities.getPackageName((NamedElement)this.metaObject, ".", false);
136         if (StringUtils.isBlank(packageName))
137         {
138             packageName = this.getPackage().getFullyQualifiedName();
139         }
140         return packageName;
141     }
142 }