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