01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.graph.node;
23:
24: import java.util.*;
25:
26: import org.jbpm.graph.def.*;
27: import org.jbpm.graph.exe.*;
28:
29: /**
30: * TODO is the merge node usefull ?
31: * i don't think the merge node is usefull because every node has an
32: * implicit merge in front of it (= multiple transitions can arrive in
33: * the same node). maybe we should just leave this in for the sake
34: * of workflow patterns ?
35: */
36: public class Merge extends Node {
37:
38: private static final long serialVersionUID = 1L;
39:
40: boolean isSynchronized = false;
41:
42: public Merge() {
43: }
44:
45: public Merge(String name) {
46: super (name);
47: }
48:
49: public void execute(ExecutionContext executionContext) {
50: Token token = executionContext.getToken();
51: Node mergeNode = token.getNode();
52:
53: // if this is a simple merge
54: if (!isSynchronized) {
55: mergeNode.leave(executionContext);
56:
57: // this is a synchronizing multi merge
58: } else {
59:
60: Collection concurrentTokens = token.getParent()
61: .getChildren().values();
62: boolean reactivate = true;
63: Iterator iter = concurrentTokens.iterator();
64: while ((iter.hasNext()) && (reactivate)) {
65: Token concurrentToken = (Token) iter.next();
66: if (!mergeNode.equals(concurrentToken.getNode())) {
67: reactivate = false;
68: }
69: }
70:
71: if (reactivate) {
72: iter = concurrentTokens.iterator();
73: while (iter.hasNext()) {
74: Token concurrentToken = (Token) iter.next();
75: mergeNode.leave(new ExecutionContext(
76: concurrentToken));
77: }
78: }
79: }
80: }
81:
82: public boolean isSynchronized() {
83: return isSynchronized;
84: }
85:
86: public void setSynchronized(boolean isSynchronized) {
87: this.isSynchronized = isSynchronized;
88: }
89: }
|