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.RouteHelper;
025: import edu.iu.uis.eden.engine.node.Node;
026: import edu.iu.uis.eden.engine.node.ProcessResult;
027: import edu.iu.uis.eden.engine.node.RouteNode;
028: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
029:
030: /**
031: * Common superclass for all Transition Engines. A TransitionEngine handles transitioning into and out of
032: * a {@link RouteNodeInstance}. The TransitionEngine is also responsible for determining if a Node has completed.
033: *
034: * @author ewestfal
035: * @author rkirkend
036: */
037: public abstract class TransitionEngine {
038:
039: private RouteHelper helper;
040:
041: public RouteNodeInstance transitionTo(
042: RouteNodeInstance nextNodeInstance, RouteContext context)
043: throws Exception {
044: return nextNodeInstance;
045: }
046:
047: /**
048: * Tell the WorkflowEngine processing the activeNodeInstance if the node is complete and transitionFrom can
049: * be called.
050: *
051: * @param activeNodeInstance
052: * @return boolean
053: */
054: public abstract ProcessResult isComplete(RouteContext context)
055: throws Exception;
056:
057: public Transition transitionFrom(RouteContext context,
058: ProcessResult processResult) throws Exception {
059: return new Transition(resolveNextNodeInstances(context
060: .getNodeInstance()));
061: }
062:
063: protected void setRouteHelper(RouteHelper helper) {
064: this .helper = helper;
065: }
066:
067: protected RouteHelper getRouteHelper() {
068: return helper;
069: }
070:
071: protected Node getNode(RouteNode routeNode, Class nodeClass)
072: throws Exception {
073: return helper.getNode(routeNode);
074: }
075:
076: /**
077: * Determines the next nodes instances for the transition. If the node instance already
078: * has next nodes instances (i.e. a dynamic node), then those will be returned. Otherwise
079: * it will resolve the next nodes from the RouteNode prototype.
080: */
081: protected List resolveNextNodeInstances(
082: RouteNodeInstance nodeInstance, List nextRouteNodes) {
083: List nextNodeInstances = new ArrayList();
084: for (Iterator iterator = nextRouteNodes.iterator(); iterator
085: .hasNext();) {
086: RouteNode nextNode = (RouteNode) iterator.next();
087: RouteNodeInstance nextNodeInstance = getRouteHelper()
088: .getNodeFactory().createRouteNodeInstance(
089: nodeInstance.getDocumentId(), nextNode);
090: nextNodeInstance.setBranch(nodeInstance.getBranch());
091: nextNodeInstance.setProcess(nodeInstance.getProcess());
092: nextNodeInstances.add(nextNodeInstance);
093: }
094: return nextNodeInstances;
095: }
096:
097: protected List resolveNextNodeInstances(
098: RouteNodeInstance nodeInstance) {
099: return resolveNextNodeInstances(nodeInstance, nodeInstance
100: .getRouteNode().getNextNodes());
101: }
102:
103: }
|