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.io.StringReader;
20: import java.util.ArrayList;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: import org.jdom.Document;
25:
26: import edu.iu.uis.eden.engine.RouteContext;
27: import edu.iu.uis.eden.engine.node.ProcessResult;
28: import edu.iu.uis.eden.engine.node.RouteNode;
29: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
30: import edu.iu.uis.eden.engine.node.SimpleResult;
31: import edu.iu.uis.eden.exception.InvalidXmlException;
32: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
33: import edu.iu.uis.eden.util.XmlHelper;
34:
35: /**
36: * TransitionEngine responsible for returning the workflow engine to another RouteNode
37: *
38: * @author rkirkend
39: */
40: public class LoopTransitionEngine extends TransitionEngine {
41:
42: @Override
43: public ProcessResult isComplete(RouteContext context)
44: throws Exception {
45: return new SimpleResult(true);
46: }
47:
48: /**
49: * Determines the next nodes instances for the transition. If the node instance already
50: * has next nodes instances (i.e. a dynamic node), then those will be returned. Otherwise
51: * it will resolve the next nodes from the RouteNode prototype.
52: */
53: protected List resolveNextNodeInstances(
54: RouteNodeInstance nodeInstance, List nextRouteNodes) {
55:
56: try {
57: Document doc = XmlHelper.buildJDocument(new StringReader(
58: nodeInstance.getRouteNode().getContentFragment()));
59:
60: } catch (InvalidXmlException e) {
61: throw new WorkflowRuntimeException(e);
62: }
63:
64: List nextNodeInstances = new ArrayList();
65: for (Iterator iterator = nextRouteNodes.iterator(); iterator
66: .hasNext();) {
67: RouteNode nextNode = (RouteNode) iterator.next();
68: RouteNodeInstance nextNodeInstance = getRouteHelper()
69: .getNodeFactory().createRouteNodeInstance(
70: nodeInstance.getDocumentId(), nextNode);
71: nextNodeInstance.setBranch(nodeInstance.getBranch());
72: nextNodeInstance.setProcess(nodeInstance.getProcess());
73: nextNodeInstances.add(nextNodeInstance);
74: }
75: return nextNodeInstances;
76: }
77:
78: }
|