Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.kuali.rice.kew.engine.transition;
 import java.util.List;
 import java.util.Set;

The DynamicTransitionEngine operates on a org.kuali.rice.kew.engine.node.DynamicNode and takes the next node instances returned by the node and runs returns them in a TransitionResult after doing some processing and validation on them.

Kuali Rice Team (
See also:
 public class DynamicTransitionEngine extends TransitionEngine {
     // TODO interate the all the nodes and attach the dynamic node as the 'process'
     // don't include the dynamic node instance in the routing structure - require a correctly built graph
     // change dynamic node signiture to next node because of above
     // reconcile branching if necessary
     public RouteNodeInstance transitionTo(RouteNodeInstance dynamicNodeInstanceRouteContext contextthrows Exception {
         DynamicNode dynamicNode = (DynamicNodegetNode(dynamicNodeInstance.getRouteNode(), DynamicNode.class);
         DynamicResult result = dynamicNode.transitioningInto(contextdynamicNodeInstancegetRouteHelper());
         RouteNodeInstance nextNodeInstance = result.getNextNodeInstance();
         RouteNodeInstance finalNodeInstance = null;
         if (result.isComplete()) {
             finalNodeInstance = getFinalNodeInstance(dynamicNodeInstancecontext); 
             if (nextNodeInstance == null) {
                 nextNodeInstance = finalNodeInstance;
         if (nextNodeInstance !=null) {
             initializeNodeGraph(contextdynamicNodeInstancenextNodeInstancenew HashSet<RouteNodeInstance>(), finalNodeInstance);
         return nextNodeInstance;   
     public ProcessResult isComplete(RouteContext contextthrows Exception {
         throw new UnsupportedOperationException("isComplete() should not be invoked on a Dynamic node!");
     public Transition transitionFrom(RouteContext contextProcessResult processResultthrows Exception {
         Transition transition = new Transition();
         RouteNodeInstance dynamicNodeInstance = context.getNodeInstance().getProcess();
         DynamicNode dynamicNode = (DynamicNodegetNode(dynamicNodeInstance.getRouteNode(), DynamicNode.class);
         DynamicResult result = dynamicNode.transitioningOutOf(contextgetRouteHelper());
         if (result.getNextNodeInstance() == null && result.getNextNodeInstances().isEmpty() && result.isComplete()) {
             RouteNodeInstance finalNodeInstance = getFinalNodeInstance(dynamicNodeInstancecontext);
             if (finalNodeInstance != null) {
         } else {
             if (result.getNextNodeInstance() != null) {
             for (Iterator iter = result.getNextNodeInstances().iterator(); iter.hasNext();) {
                 RouteNodeInstance nextNodeInstance = (;
         return transition;

This method checks the next node returned by the user and walks the resulting node graph, filling in required data where possible. Will throw errors if there is a problem with what the implementor has returned to us. This allows them to do things like return next nodes with no attached branches, and we will go ahead and generate the branches for them, etc.
     private void initializeNodeGraph(RouteContext contextRouteNodeInstance dynamicNodeInstanceRouteNodeInstance nodeInstanceSet<RouteNodeInstancenodeInstancesRouteNodeInstance finalNodeInstancethrows Exception {
         if (nodeInstances.contains(nodeInstance)) {
            throw new RouteManagerException("A cycle was detected in the node graph returned from the dynamic node."context);
        List<RouteNodeInstancenextNodeInstances = nodeInstance.getNextNodeInstances();
        if (nextNodeInstances.size() > 1) {
            // TODO implement this feature
//            throw new UnsupportedOperationException("Need to implement support for branch generation!");
        for (RouteNodeInstance nextNodeInstance : nextNodeInstances)
        if (nextNodeInstances.isEmpty() && finalNodeInstance != null) {
    private RouteNodeInstance getFinalNodeInstance(RouteNodeInstance dynamicNodeInstanceRouteContext contextthrows Exception {
        List<RouteNodenextNodes = dynamicNodeInstance.getRouteNode().getNextNodes();
        if (nextNodes.size() > 1) {
            throw new RouteManagerException("There should only be 1 next node following a dynamic node, there were " + nextNodes.size(), context);
        RouteNodeInstance finalNodeInstance = null;
        if (!nextNodes.isEmpty()) {
            finalNodeInstance = getRouteHelper().getNodeFactory().createRouteNodeInstance(context.getDocument().getDocumentId(), (RouteNodenextNodes.get(0));
        return finalNodeInstance;
New to GrepCode? Check out our FAQ X