001: package org.andromda.cartridges.jbpm.metafacades;
002:
003: import org.andromda.utils.StringUtilsHelper;
004: import org.andromda.metafacades.uml.ActionStateFacade;
005: import org.andromda.metafacades.uml.ActivityGraphFacade;
006: import org.andromda.metafacades.uml.PseudostateFacade;
007: import org.andromda.metafacades.uml.StateFacade;
008: import org.andromda.metafacades.uml.UMLProfile;
009: import org.apache.commons.lang.StringUtils;
010:
011: import java.util.ArrayList;
012: import java.util.Collection;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: /**
017: * MetafacadeLogic implementation for org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinition.
018: *
019: * @see org.andromda.cartridges.jbpm.metafacades.JBpmProcessDefinition
020: */
021: public class JBpmProcessDefinitionLogicImpl extends
022: JBpmProcessDefinitionLogic {
023:
024: public JBpmProcessDefinitionLogicImpl(Object metaObject,
025: String context) {
026: super (metaObject, context);
027: }
028:
029: protected List handleGetStates() {
030: final List states = new ArrayList();
031:
032: final ActivityGraphFacade graph = this .getFirstActivityGraph();
033: if (graph != null) {
034: final Collection graphStates = graph.getStates();
035: for (final Iterator stateIterator = graphStates.iterator(); stateIterator
036: .hasNext();) {
037: final StateFacade state = (StateFacade) stateIterator
038: .next();
039: if (state instanceof JBpmState) {
040: states.add(state);
041: }
042: }
043: }
044:
045: return states;
046: }
047:
048: protected List handleGetNodes() {
049: final List states = new ArrayList();
050:
051: final ActivityGraphFacade graph = this .getFirstActivityGraph();
052: if (graph != null) {
053: final Collection actionStates = graph.getActionStates();
054: for (final Iterator actionStateIterator = actionStates
055: .iterator(); actionStateIterator.hasNext();) {
056: final ActionStateFacade state = (ActionStateFacade) actionStateIterator
057: .next();
058: if (state instanceof JBpmNode
059: && !((JBpmNode) state).isTaskNode()) {
060: states.add(state);
061: }
062: }
063: }
064:
065: return states;
066: }
067:
068: protected List handleGetTaskNodes() {
069: final List taskNodes = new ArrayList();
070:
071: final ActivityGraphFacade graph = this .getFirstActivityGraph();
072: if (graph != null) {
073: final Collection actionStates = graph.getActionStates();
074: for (final Iterator actionStateIterator = actionStates
075: .iterator(); actionStateIterator.hasNext();) {
076: final ActionStateFacade state = (ActionStateFacade) actionStateIterator
077: .next();
078: if (state instanceof JBpmNode
079: && ((JBpmNode) state).isTaskNode()) {
080: taskNodes.add(state);
081: }
082: }
083: }
084:
085: return taskNodes;
086: }
087:
088: protected List handleGetTasks() {
089: final List tasks = new ArrayList();
090:
091: final List taskNodes = getTaskNodes();
092: for (int i = 0; i < taskNodes.size(); i++) {
093: final JBpmNode node = (JBpmNode) taskNodes.get(i);
094: tasks.addAll(node.getTasks());
095: }
096:
097: return tasks;
098: }
099:
100: protected boolean handleIsBusinessProcess() {
101: return true;
102: }
103:
104: protected List handleGetSwimlanes() {
105: final List swimlanes = new ArrayList();
106:
107: final ActivityGraphFacade graph = this .getFirstActivityGraph();
108: if (graph != null) {
109: swimlanes.addAll(graph.getPartitions());
110: }
111:
112: return swimlanes;
113: }
114:
115: protected Object handleGetStartState() {
116: Object startState = null;
117:
118: final ActivityGraphFacade graph = this .getFirstActivityGraph();
119: if (graph != null) {
120: startState = graph.getInitialState();
121: }
122:
123: return startState;
124: }
125:
126: protected List handleGetEndStates() {
127: final List endStates = new ArrayList();
128:
129: final ActivityGraphFacade graph = this .getFirstActivityGraph();
130: if (graph != null) {
131: endStates.addAll(graph.getFinalStates());
132: }
133:
134: return endStates;
135: }
136:
137: protected List handleGetDecisions() {
138: final List decisions = new ArrayList();
139:
140: final ActivityGraphFacade graph = this .getFirstActivityGraph();
141: if (graph != null) {
142: final Collection pseudostates = graph.getPseudostates();
143: for (final Iterator pseudostateIterator = pseudostates
144: .iterator(); pseudostateIterator.hasNext();) {
145: final PseudostateFacade pseudostate = (PseudostateFacade) pseudostateIterator
146: .next();
147: if (pseudostate.isDecisionPoint()) {
148: decisions.add(pseudostate);
149: }
150: }
151: }
152:
153: return decisions;
154: }
155:
156: protected List handleGetForks() {
157: final List forks = new ArrayList();
158:
159: final ActivityGraphFacade graph = this .getFirstActivityGraph();
160: if (graph != null) {
161: final Collection pseudostates = graph.getPseudostates();
162: for (final Iterator pseudostateIterator = pseudostates
163: .iterator(); pseudostateIterator.hasNext();) {
164: final PseudostateFacade pseudostate = (PseudostateFacade) pseudostateIterator
165: .next();
166: if (pseudostate.isSplit()) {
167: forks.add(pseudostate);
168: }
169: }
170: }
171:
172: return forks;
173: }
174:
175: protected List handleGetJoins() {
176: final List joins = new ArrayList();
177:
178: final ActivityGraphFacade graph = this .getFirstActivityGraph();
179: if (graph != null) {
180: final Collection pseudostates = graph.getPseudostates();
181: for (final Iterator pseudostateIterator = pseudostates
182: .iterator(); pseudostateIterator.hasNext();) {
183: final PseudostateFacade pseudostate = (PseudostateFacade) pseudostateIterator
184: .next();
185: if (pseudostate.isCollect()) {
186: joins.add(pseudostate);
187: }
188: }
189: }
190:
191: return joins;
192: }
193:
194: protected String handleGetDescriptorFullPath() {
195: final StringBuffer pathBuffer = new StringBuffer();
196:
197: if (StringUtils.isNotBlank(this .getPackagePath())) {
198: pathBuffer.append(this .getPackagePath());
199: pathBuffer.append('/');
200: }
201: pathBuffer.append(StringUtilsHelper.separate(this .getName(),
202: "-").toLowerCase());
203: pathBuffer.append(".pdl.xml");
204:
205: return pathBuffer.toString();
206: }
207:
208: protected String handleGetNodeInterfaceName() {
209: return StringUtilsHelper.upperCamelCaseName(this .getName())
210: + "ProcessNode";
211: }
212:
213: /**
214: * Overwritten because we want to be able to make use of the AndroMDA tagged value for use-case
215: * to activity graph linking.
216: */
217: public ActivityGraphFacade getFirstActivityGraph() {
218: ActivityGraphFacade activityGraph;
219:
220: final Object activity = this
221: .findTaggedValue(UMLProfile.TAGGEDVALUE_PRESENTATION_USECASE_ACTIVITY);
222: if (activity == null) {
223: activityGraph = super .getFirstActivityGraph();
224: } else {
225: final String activityName = String.valueOf(activity
226: .toString());
227: activityGraph = this.getModel().findActivityGraphByName(
228: activityName);
229: }
230:
231: return activityGraph;
232: }
233: }
|