View Javadoc
1   package org.andromda.cartridges.bpm4struts.metafacades;
2   
3   import java.util.ArrayList;
4   import java.util.LinkedHashSet;
5   import java.util.List;
6   import java.util.Set;
7   import org.andromda.metafacades.uml.ActivityGraphFacade;
8   import org.andromda.metafacades.uml.StateMachineFacade;
9   import org.andromda.metafacades.uml.UseCaseFacade;
10  import org.andromda.utils.StringUtilsHelper;
11  
12  /**
13   * MetafacadeLogic implementation.
14   *
15   * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsPseudostate
16   */
17  public class StrutsPseudostateLogicImpl
18      extends StrutsPseudostateLogic
19  {
20      private static final long serialVersionUID = 34L;
21      /**
22       * @param metaObject
23       * @param context
24       */
25      public StrutsPseudostateLogicImpl(
26          Object metaObject,
27          String context)
28      {
29          super(metaObject, context);
30      }
31  
32      /**
33       * @return getStateMachine() instanceof StrutsActivityGraph
34       */
35      protected boolean handleIsContainedInFrontEndUseCase()
36      {
37          return this.getStateMachine() instanceof StrutsActivityGraph;
38      }
39  
40      /**
41       * @return actionMethodName
42       * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsPseudostate#getActionMethodName()
43       */
44      protected String handleGetActionMethodName()
45      {
46          final String methodName = getName();
47          return (methodName == null) ?
48              "a" + System.currentTimeMillis() : StringUtilsHelper.lowerCamelCaseName(methodName);
49      }
50  
51      /**
52       * Overridden and not typesafe since StrutsAction does not extend FrontEndAction
53       *
54       * @see org.andromda.metafacades.uml.FrontEndPseudostate#getContainerActions()
55       */
56      public List getContainerActions()
57      {
58          final Set<StrutsAction> actionSet = new LinkedHashSet<StrutsAction>();
59          final StateMachineFacade graphContext = getStateMachine();
60  
61          if (graphContext instanceof ActivityGraphFacade)
62          {
63              final UseCaseFacade useCase = ((ActivityGraphFacade)graphContext).getUseCase();
64  
65              if (useCase instanceof StrutsUseCase)
66              {
67                  // StrutsUseCase.getActions returns StrutsAction which cannot be cast to FrontEndAction
68                  for (final Object action : ((StrutsUseCaseLogicImpl)useCase).getActions())
69                  {
70                      for (final StrutsForward transition : ((StrutsAction)action).getTransitions())
71                      {
72                          if (this.equals(transition.getTarget()))
73                          {
74                              actionSet.add((StrutsAction)action);
75                          }
76                      }
77                  }
78              }
79          }
80          // Cannot make return type List<StrutsAction> because StrutsAction does not extend FrontEndAction
81          return new ArrayList<StrutsAction>(actionSet);
82      }
83  }