View Javadoc
1   package org.andromda.cartridges.jbpm.metafacades;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import org.andromda.metafacades.uml.ActionStateFacade;
6   import org.andromda.metafacades.uml.ActivityGraphFacade;
7   import org.andromda.metafacades.uml.FinalStateFacade;
8   import org.andromda.metafacades.uml.PartitionFacade;
9   import org.andromda.metafacades.uml.PseudostateFacade;
10  import org.andromda.metafacades.uml.StateFacade;
11  import org.andromda.metafacades.uml.UMLProfile;
12  import org.andromda.utils.StringUtilsHelper;
13  import org.apache.commons.lang.StringUtils;
14  
15  /**
16   * MetafacadeLogic implementation for org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinition.
17   *
18   * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinition
19   */
20  public class JBpmProcessDefinitionLogicImpl
21      extends JBpmProcessDefinitionLogic
22  {
23      private static final long serialVersionUID = 34L;
24      /**
25       * @param metaObject
26       * @param context
27       */
28      public JBpmProcessDefinitionLogicImpl(Object metaObject, String context)
29      {
30          super(metaObject, context);
31      }
32  
33      /**
34       * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetStates()
35       */
36      protected List<JBpmState> handleGetStates()
37      {
38          final List<JBpmState> states = new ArrayList<JBpmState>();
39          final ActivityGraphFacade graph = this.getFirstActivityGraph();
40          if (graph != null)
41          {
42              for (final StateFacade state : graph.getStates())
43              {
44                  if (state instanceof JBpmState)
45                  {
46                      states.add((JBpmState)state);
47                  }
48              }
49          }
50          return states;
51      }
52  
53      /**
54       * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetNodes()
55       */
56      protected List<JBpmNode> handleGetNodes()
57      {
58          final List<JBpmNode> states = new ArrayList<JBpmNode>();
59          final ActivityGraphFacade graph = this.getFirstActivityGraph();
60          if (graph != null)
61          {
62              for (final ActionStateFacade state : graph.getActionStates())
63              {
64                  if (state instanceof JBpmNode && !((JBpmNode)state).isTaskNode())
65                  {
66                      states.add((JBpmNode)state);
67                  }
68              }
69          }
70          return states;
71      }
72  
73      /**
74       * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetTaskNodes()
75       */
76      protected List<JBpmNode> handleGetTaskNodes()
77      {
78          final List<JBpmNode> taskNodes = new ArrayList<JBpmNode>();
79          final ActivityGraphFacade graph = this.getFirstActivityGraph();
80          if (graph != null)
81          {
82              for (final ActionStateFacade state : graph.getActionStates())
83              {
84                  if (state instanceof JBpmNode && ((JBpmNode)state).isTaskNode())
85                  {
86                      taskNodes.add((JBpmNode)state);
87                  }
88              }
89          }
90          return taskNodes;
91      }
92  
93      /**
94       * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetTasks()
95       */
96      protected List<JBpmAction> handleGetTasks()
97      {
98          final List<JBpmAction> tasks = new ArrayList<JBpmAction>();
99          for (JBpmNode node : getTaskNodes())
100         {
101             tasks.addAll(node.getTasks());
102         }
103         return tasks;
104     }
105 
106     /**
107      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleIsBusinessProcess()
108      */
109     protected boolean handleIsBusinessProcess()
110     {
111         return true;
112     }
113 
114     /**
115      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetSwimlanes()
116      */
117     protected List<PartitionFacade> handleGetSwimlanes()
118     {
119         final List<PartitionFacade> swimlanes = new ArrayList<PartitionFacade>();
120         final ActivityGraphFacade graph = this.getFirstActivityGraph();
121         if (graph != null)
122         {
123             swimlanes.addAll(graph.getPartitions());
124         }
125         return swimlanes;
126     }
127 
128     /**
129      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetStartState()
130      */
131     protected PseudostateFacade  handleGetStartState()
132     {
133         PseudostateFacade  startState = null;
134         final ActivityGraphFacade graph = this.getFirstActivityGraph();
135         if (graph != null)
136         {
137             startState = graph.getInitialState();
138         }
139         return startState;
140     }
141 
142     /**
143      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetEndStates()
144      */
145     protected List<FinalStateFacade> handleGetEndStates()
146     {
147         final List<FinalStateFacade> endStates = new ArrayList<FinalStateFacade>();
148         final ActivityGraphFacade graph = this.getFirstActivityGraph();
149         if (graph != null)
150         {
151             endStates.addAll(graph.getFinalStates());
152         }
153         return endStates;
154     }
155 
156     /**
157      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetDecisions()
158      */
159     protected List<PseudostateFacade> handleGetDecisions()
160     {
161         final List<PseudostateFacade> decisions = new ArrayList<PseudostateFacade>();
162         final ActivityGraphFacade graph = this.getFirstActivityGraph();
163         if (graph != null)
164         {
165             for (final PseudostateFacade pseudostate : graph.getPseudostates())
166             {
167                 if (pseudostate.isDecisionPoint())
168                 {
169                     decisions.add(pseudostate);
170                 }
171             }
172         }
173         return decisions;
174     }
175 
176     /**
177      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetForks()
178      */
179     protected List<PseudostateFacade> handleGetForks()
180     {
181         final List<PseudostateFacade> forks = new ArrayList<PseudostateFacade>();
182         final ActivityGraphFacade graph = this.getFirstActivityGraph();
183         if (graph != null)
184         {
185             for (final PseudostateFacade pseudostate : graph.getPseudostates())
186             {
187                 if (pseudostate.isSplit())
188                 {
189                     forks.add(pseudostate);
190                 }
191             }
192         }
193         return forks;
194     }
195 
196     /**
197      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetJoins()
198      */
199     protected List<PseudostateFacade> handleGetJoins()
200     {
201         final List<PseudostateFacade> joins = new ArrayList<PseudostateFacade>();
202         final ActivityGraphFacade graph = this.getFirstActivityGraph();
203         if (graph != null)
204         {
205             for (final PseudostateFacade pseudostate : graph.getPseudostates())
206             {
207                 if (pseudostate.isCollect())
208                 {
209                     joins.add(pseudostate);
210                 }
211             }
212         }
213         return joins;
214     }
215 
216     /**
217      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetDescriptorFullPath()
218      */
219     protected String handleGetDescriptorFullPath()
220     {
221         final StringBuilder pathBuffer = new StringBuilder();
222 
223         if (StringUtils.isNotBlank(this.getPackagePath()))
224         {
225             pathBuffer.append(this.getPackagePath());
226             pathBuffer.append('/');
227         }
228         pathBuffer.append(StringUtilsHelper.separate(this.getName(), "-").toLowerCase());
229         pathBuffer.append(".pdl.xml");
230 
231         return pathBuffer.toString();
232     }
233 
234     /**
235      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#handleGetNodeInterfaceName()
236      */
237     protected String handleGetNodeInterfaceName()
238     {
239         return StringUtilsHelper.upperCamelCaseName(this.getName()) + "ProcessNode";
240     }
241 
242     /**
243      * Overwritten because we want to be able to make use of the AndroMDA tagged value for use-case
244      * to activity graph linking.
245      * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinitionLogic#getFirstActivityGraph()
246      */
247     public ActivityGraphFacade getFirstActivityGraph()
248     {
249         ActivityGraphFacade activityGraph;
250 
251         final Object activity = this.findTaggedValue(UMLProfile.TAGGEDVALUE_PRESENTATION_USECASE_ACTIVITY);
252         if (activity == null)
253         {
254             activityGraph = super.getFirstActivityGraph();
255         }
256         else
257         {
258             final String activityName = String.valueOf(activity.toString());
259             activityGraph = this.getModel().findActivityGraphByName(activityName);
260         }
261 
262         return activityGraph;
263     }
264 }