001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jbpm.graph.node;
023:
024: import java.util.*;
025: import org.dom4j.Element;
026: import org.jbpm.graph.def.*;
027: import org.jbpm.graph.exe.*;
028: import org.jbpm.jpdl.xml.*;
029:
030: /**
031: * a interleaving end node should have 2 leaving transitions.
032: * one with the name 'back' that has the interleaving start node as
033: * destinationNode. and one with the name 'done' that specifies the
034: * destinationNode in case the interleaving is done.
035: * Alternatively, the back and done transitions can be specified
036: * in this interleave handler.
037: */
038: public class InterleaveEnd extends Node implements Parsable {
039:
040: private static final long serialVersionUID = 1L;
041:
042: Transition back = null;
043: Transition done = null;
044:
045: public InterleaveEnd() {
046: }
047:
048: public InterleaveEnd(String name) {
049: super (name);
050: }
051:
052: public void read(Element element, JpdlXmlReader jpdlReader) {
053: // TODO
054: }
055:
056: public void write(Element element) {
057: // TODO
058: }
059:
060: public void execute(ExecutionContext executionContext) {
061: Token token = executionContext.getToken();
062: Node interleaveEndNode = token.getNode();
063: Collection transitionNames = getInterleaveStart()
064: .retrieveTransitionNames(token);
065: // if the set is *not* empty
066: if (!transitionNames.isEmpty()) {
067: // go back to the interleave start handler
068: String backTransitionName = "back";
069: if (back != null) {
070: backTransitionName = back.getName();
071: }
072: interleaveEndNode.leave(executionContext,
073: backTransitionName);
074: } else {
075: // leave the to the
076: getInterleaveStart().removeTransitionNames(token);
077: String doneTransitionName = "done";
078: if (done != null) {
079: doneTransitionName = done.getName();
080: }
081: interleaveEndNode.leave(executionContext,
082: doneTransitionName);
083: }
084: }
085:
086: public InterleaveStart getInterleaveStart() {
087: return (InterleaveStart) getLeavingTransition("back").getTo();
088: }
089:
090: public Transition getBack() {
091: return back;
092: }
093:
094: public void setBack(Transition back) {
095: this .back = back;
096: }
097:
098: public Transition getDone() {
099: return done;
100: }
101:
102: public void setDone(Transition done) {
103: this.done = done;
104: }
105: }
|