001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.engine.transition;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import edu.iu.uis.eden.engine.RouteContext;
024: import edu.iu.uis.eden.engine.node.Process;
025: import edu.iu.uis.eden.engine.node.ProcessResult;
026: import edu.iu.uis.eden.engine.node.RouteNode;
027: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
028: import edu.iu.uis.eden.engine.node.SubProcessNode;
029: import edu.iu.uis.eden.engine.node.SubProcessResult;
030: import edu.iu.uis.eden.exception.WorkflowException;
031:
032: /**
033: * Handles transitions into and out of {@link SubProcessNode} nodes.
034: *
035: * @see SubProcessNode
036: *
037: * @author ewestfal
038: * @author rkirkend
039: */
040: public class SubProcessTransitionEngine extends TransitionEngine {
041:
042: public RouteNodeInstance transitionTo(
043: RouteNodeInstance nextNodeInstance, RouteContext context)
044: throws Exception {
045: String processName = nextNodeInstance.getRouteNode()
046: .getRouteNodeName();
047: Process process = context.getDocument().getDocumentType()
048: .getNamedProcess(processName);
049: if (process == null) {
050: throw new WorkflowException(
051: "Could not locate named sub process: "
052: + processName);
053: }
054: RouteNodeInstance subProcessNodeInstance = nextNodeInstance;
055: subProcessNodeInstance.setInitial(false);
056: subProcessNodeInstance.setActive(false);
057: nextNodeInstance = getRouteHelper().getNodeFactory()
058: .createRouteNodeInstance(
059: subProcessNodeInstance.getDocumentId(),
060: process.getInitialRouteNode());
061: nextNodeInstance.setBranch(subProcessNodeInstance.getBranch());
062: nextNodeInstance.setProcess(subProcessNodeInstance);
063: return nextNodeInstance;
064: }
065:
066: public ProcessResult isComplete(RouteContext context)
067: throws Exception {
068: throw new UnsupportedOperationException(
069: "isComplete() should not be invoked on a SubProcess!");
070: }
071:
072: public Transition transitionFrom(RouteContext context,
073: ProcessResult processResult) throws Exception {
074: RouteNodeInstance processInstance = context.getNodeInstance()
075: .getProcess();
076: processInstance.setComplete(true);
077: SubProcessNode node = (SubProcessNode) getNode(processInstance
078: .getRouteNode(), SubProcessNode.class);
079: SubProcessResult result = node.process(context);
080: List nextNodeInstances = new ArrayList();
081: if (result.isComplete()) {
082: List nextNodes = processInstance.getRouteNode()
083: .getNextNodes();
084: for (Iterator iterator = nextNodes.iterator(); iterator
085: .hasNext();) {
086: RouteNode nextNode = (RouteNode) iterator.next();
087: RouteNodeInstance nextNodeInstance = getRouteHelper()
088: .getNodeFactory().createRouteNodeInstance(
089: processInstance.getDocumentId(),
090: nextNode);
091: nextNodeInstance.setBranch(processInstance.getBranch());
092: nextNodeInstance.setProcess(processInstance
093: .getProcess());
094: nextNodeInstances.add(nextNodeInstance);
095: }
096: }
097: return new Transition(nextNodeInstances);
098: }
099:
100: }
|