01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.engine.transition;
18:
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import edu.iu.uis.eden.engine.RouteContext;
24: import edu.iu.uis.eden.engine.RouteHelper;
25: import edu.iu.uis.eden.engine.node.Branch;
26: import edu.iu.uis.eden.engine.node.ProcessResult;
27: import edu.iu.uis.eden.engine.node.RouteNode;
28: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
29: import edu.iu.uis.eden.engine.node.SplitNode;
30: import edu.iu.uis.eden.engine.node.SplitResult;
31:
32: /**
33: * Handles transitions into and out of {@link SplitNode} nodes.
34: *
35: * @see SplitNode
36: *
37: * @author ewestfal
38: * @author rkirkend
39: */
40: public class SplitTransitionEngine extends TransitionEngine {
41:
42: public ProcessResult isComplete(RouteContext context)
43: throws Exception {
44: SplitNode node = (SplitNode) getNode(context.getNodeInstance()
45: .getRouteNode(), SplitNode.class);
46: return node.process(context, getRouteHelper());
47: }
48:
49: public Transition transitionFrom(RouteContext context,
50: ProcessResult processResult) throws Exception {
51: RouteNodeInstance splitInstance = context.getNodeInstance();
52: List nextNodeInstances = new ArrayList();
53: SplitResult result = (SplitResult) processResult;
54: for (Iterator iterator = result.getBranchNames().iterator(); iterator
55: .hasNext();) {
56: String branchName = (String) iterator.next();
57: for (Iterator nodeIt = splitInstance.getRouteNode()
58: .getNextNodes().iterator(); nodeIt.hasNext();) {
59: RouteNode routeNode = (RouteNode) nodeIt.next();
60: if (routeNode.getBranch() != null
61: && routeNode.getBranch().getName().equals(
62: branchName)) {
63: nextNodeInstances.add(createSplitChild(branchName,
64: routeNode, splitInstance));
65: }
66: }
67: }
68: return new Transition(nextNodeInstances);
69: }
70:
71: public static RouteNodeInstance createSplitChild(String branchName,
72: RouteNode routeNode, RouteNodeInstance splitInstance) {
73: RouteHelper routeHelper = new RouteHelper();
74: RouteNodeInstance nextNodeInstance = routeHelper
75: .getNodeFactory().createRouteNodeInstance(
76: splitInstance.getDocumentId(), routeNode);
77: Branch branch = routeHelper.getNodeFactory()
78: .createBranch(branchName, splitInstance.getBranch(),
79: nextNodeInstance);
80: branch.setSplitNode(splitInstance);
81: nextNodeInstance.setBranch(branch);
82: nextNodeInstance.setProcess(splitInstance.getProcess());
83: return nextNodeInstance;
84: }
85:
86: }
|