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.LinkedHashSet;
7   import java.util.List;
8   import java.util.Set;
9   import org.andromda.metafacades.uml.ActivityGraphFacade;
10  import org.andromda.metafacades.uml.CallEventFacade;
11  import org.andromda.metafacades.uml.EventFacade;
12  import org.andromda.metafacades.uml.FrontEndAction;
13  import org.andromda.metafacades.uml.FrontEndActivityGraph;
14  import org.andromda.metafacades.uml.FrontEndControllerOperation;
15  import org.andromda.metafacades.uml.FrontEndEvent;
16  import org.andromda.metafacades.uml.FrontEndExceptionHandler;
17  import org.andromda.metafacades.uml.FrontEndUseCase;
18  import org.andromda.metafacades.uml.FrontEndView;
19  import org.andromda.metafacades.uml.OperationFacade;
20  import org.andromda.metafacades.uml.ServiceOperation;
21  import org.andromda.metafacades.uml.StateMachineFacade;
22  import org.andromda.metafacades.uml.TransitionFacade;
23  import org.andromda.metafacades.uml.UseCaseFacade;
24  import org.andromda.utils.StringUtilsHelper;
25  import org.apache.commons.collections.CollectionUtils;
26  import org.apache.commons.collections.Predicate;
27  
28  /**
29   * MetafacadeLogic implementation for
30   * org.andromda.metafacades.uml.FrontEndActionState.
31   *
32   * @see org.andromda.metafacades.uml.FrontEndActionState
33   */
34  public class FrontEndActionStateLogicImpl extends FrontEndActionStateLogic
35  {
36      private static final long serialVersionUID = 34L;
37      /**
38       * @param metaObject
39       * @param context
40       */
41      public FrontEndActionStateLogicImpl(final Object metaObject, final String context)
42      {
43          super(metaObject, context);
44      }
45  
46      /**
47       * @see org.andromda.metafacades.uml.FrontEndActionState#isServerSide()
48       */
49      @Override
50      protected boolean handleIsServerSide()
51      {
52          return !(this.THIS() instanceof FrontEndView);
53      }
54  
55      /**
56       * @see org.andromda.metafacades.uml.FrontEndActionState#getActionMethodName()
57       */
58      @Override
59      protected String handleGetActionMethodName()
60      {
61          return '_' + StringUtilsHelper.lowerCamelCaseName(this.handleGetName());
62      }
63  
64      /**
65       * @see org.andromda.metafacades.uml.FrontEndActionState#isContainedInFrontEndUseCase()
66       */
67      @Override
68      protected boolean handleIsContainedInFrontEndUseCase()
69      {
70          return this.getStateMachine() instanceof FrontEndActivityGraph;
71      }
72  
73      /**
74       * @see org.andromda.metafacades.uml.FrontEndActionState#getForward()
75       */
76      @Override
77      protected TransitionFacade handleGetForward()
78      {
79          TransitionFacade forward = null;
80  
81          for (TransitionFacade transition : this.getOutgoings())
82          {
83              if (!(transition instanceof FrontEndExceptionHandler))
84              {
85                  forward = transition;
86                  break;
87              }
88          }
89          return forward;
90      }
91  
92      /**
93       * @see org.andromda.metafacades.uml.FrontEndActionState#getServiceCalls()
94       */
95      @Override
96      protected List<OperationFacade> handleGetServiceCalls()
97      {
98          final List<OperationFacade> serviceCallsList = new ArrayList<OperationFacade>();
99          final Collection<EventFacade> deferrableEvents = this.getDeferrableEvents();
100         for (final Iterator<EventFacade> iterator = deferrableEvents.iterator(); iterator
101                 .hasNext();)
102         {
103             final EventFacade event = iterator.next();
104             if (event instanceof CallEventFacade)
105             {
106                 serviceCallsList.addAll(((CallEventFacade)event).getOperations());
107             }
108             else if (event instanceof FrontEndEvent)
109             {
110                 serviceCallsList.addAll(((FrontEndEvent)event).getControllerCalls());
111             }
112         }
113         //removing the controller calls
114         CollectionUtils.filter(serviceCallsList, new Predicate() {
115             @Override
116             public boolean evaluate(Object object) {
117                 final OperationFacade operation=(OperationFacade)object;
118                 return operation instanceof ServiceOperation;
119             }
120         });
121         return serviceCallsList;
122     }
123 
124     /**
125      * @see org.andromda.metafacades.uml.FrontEndActionState#getControllerCalls()
126      */
127     @Override
128     protected List<OperationFacade> handleGetControllerCalls()
129     {
130         final List<OperationFacade> controllerCallsList = new ArrayList<OperationFacade>();
131         final Collection<EventFacade> deferrableEvents = this.getDeferrableEvents();
132         for (final Iterator<EventFacade> iterator = deferrableEvents.iterator(); iterator
133                 .hasNext();)
134         {
135             final EventFacade event = iterator.next();
136             if (event instanceof CallEventFacade)
137             {
138                 controllerCallsList.addAll(((CallEventFacade)event).getOperations());
139             }
140             else if (event instanceof FrontEndEvent)
141             {
142                 controllerCallsList.addAll(((FrontEndEvent)event).getControllerCalls());
143             }
144         }
145         //removing the direct service calls
146         CollectionUtils.filter(controllerCallsList, new Predicate() {
147             @Override
148             public boolean evaluate(Object object) {
149                 final OperationFacade operation=(OperationFacade)object;
150                 return operation instanceof FrontEndControllerOperation;
151             }
152         });
153         return controllerCallsList;
154     }
155 
156     /**
157      * @see org.andromda.metafacades.uml.FrontEndActionState#getExceptions()
158      */
159     @Override
160     protected List<FrontEndExceptionHandler> handleGetExceptions()
161     {
162         final Set<FrontEndExceptionHandler> exceptions = new LinkedHashSet<FrontEndExceptionHandler>();
163         final Collection<TransitionFacade> outgoing = this.getOutgoings();
164         for (final Iterator<TransitionFacade> iterator = outgoing.iterator(); iterator.hasNext();)
165         {
166             final TransitionFacade transition = iterator
167                     .next();
168             if (transition instanceof FrontEndExceptionHandler)
169             {
170                 exceptions.add((FrontEndExceptionHandler)transition);
171             }
172         }
173         return new ArrayList<FrontEndExceptionHandler>(exceptions);
174     }
175 
176     /**
177      * @see org.andromda.metafacades.uml.FrontEndActionState#getContainerActions()
178      */
179     @Override
180     protected List<FrontEndAction> handleGetContainerActions()
181     {
182         final Collection<FrontEndAction> actionSet = new LinkedHashSet<FrontEndAction>();
183 
184         final StateMachineFacade stateMachineFacade = this.getStateMachine();
185         if (stateMachineFacade instanceof ActivityGraphFacade)
186         {
187             final ActivityGraphFacade activityGraph = (ActivityGraphFacade)stateMachineFacade;
188             final UseCaseFacade useCase = activityGraph.getUseCase();
189 
190             if (useCase instanceof FrontEndUseCase)
191             {
192                 final Collection<FrontEndAction> actions = ((FrontEndUseCase)useCase)
193                         .getActions();
194                 for (final Iterator<FrontEndAction> actionIterator = actions.iterator(); actionIterator
195                         .hasNext();)
196                 {
197                     final FrontEndAction action = actionIterator
198                             .next();
199                     if (action.getActionStates().contains(this))
200                     {
201                         actionSet.add(action);
202                     }
203                 }
204             }
205         }
206         return new ArrayList<FrontEndAction>(actionSet);
207     }
208 
209 }