View Javadoc

1   package org.andromda.cartridges.bpm4struts.metafacades;
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.FrontEndUseCase;
11  import org.andromda.metafacades.uml.UMLProfile;
12  import org.andromda.metafacades.uml.UseCaseFacade;
13  import org.apache.commons.lang.StringUtils;
14  
15  
16  /**
17   * MetafacadeLogic implementation.
18   *
19   * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsFinalState
20   */
21  public class StrutsFinalStateLogicImpl
22      extends StrutsFinalStateLogic
23  {
24      public StrutsFinalStateLogicImpl(
25          java.lang.Object metaObject,
26          java.lang.String context)
27      {
28          super(metaObject, context);
29      }
30  
31      /**
32       * @see org.andromda.metafacades.uml.ModelElementFacad#getValue()
33       */
34      public String getName()
35      {
36          String name = super.getName();
37  
38          if (name == null)
39          {
40              final UseCaseFacade useCase = this.getTargetUseCase();
41              if (useCase != null)
42              {
43                  name = useCase.getName();
44              }
45          }
46  
47          return name;
48      }
49  
50      protected String handleGetFullPath()
51      {
52          String fullPath = null;
53  
54          final StrutsUseCase useCase = (StrutsUseCase)this.getTargetUseCase();
55          if (useCase == null)
56          {
57              // perhaps this final state links outside of the UML model
58              final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_EXTERNAL_HYPERLINK);
59              if (taggedValue == null)
60              {
61                  String name = getName();
62                  if (name != null && (name.startsWith("/") || name.startsWith("http://")))
63                  {
64                      fullPath = name;
65                  }
66              }
67              else
68              {
69                  fullPath = String.valueOf(taggedValue);
70              }
71          }
72          else
73          {
74              fullPath = useCase.getActionPath() + ".do";
75          }
76          return fullPath;
77      }
78  
79      /**
80       * Overridden for now (@todo need to figure out why it doesn't work correctly when using
81       * the one from the FrontEndFinalState).
82       *
83       * @see org.andromda.metafacades.uml.FrontEndFinalState#getTargetUseCase()
84       */
85      public FrontEndUseCase getTargetUseCase()
86      {
87          FrontEndUseCase targetUseCase = null;
88          // first check if there is a hyperlink from this final state to a use-case
89          // this works at least in MagicDraw
90          final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_MODEL_HYPERLINK);
91          if (taggedValue != null)
92          {
93              if (taggedValue instanceof StrutsActivityGraph)
94              {
95                  targetUseCase = (FrontEndUseCase)((StrutsActivityGraph)taggedValue).getUseCase();
96              }
97              else if (taggedValue instanceof StrutsUseCase)
98              {
99                  targetUseCase = (FrontEndUseCase)taggedValue;
100             }
101         }
102         
103         // maybe the name points to a use-case ?
104         if (targetUseCase == null)
105         {
106             final String name = super.getName();
107             if (StringUtils.isNotBlank(name))
108             {
109                 UseCaseFacade useCase = getModel().findUseCaseByName(name);
110                 if (useCase instanceof FrontEndUseCase)
111                 {
112                     targetUseCase = (FrontEndUseCase)useCase;
113                 }
114             }
115         }
116         return targetUseCase;
117     }
118 
119     protected List handleGetActions()
120     {
121         Set actions = new LinkedHashSet();
122         Collection incoming = this.getIncoming();
123 
124         for (final Iterator incomingIterator = incoming.iterator(); incomingIterator.hasNext();)
125         {
126             StrutsForward forward = (StrutsForward)incomingIterator.next();
127             actions.addAll(forward.getActions());
128         }
129         return new ArrayList(actions);
130     }
131 }