View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.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 org.kuali.rice.kew.engine.transition;
18  
19  import org.kuali.rice.kew.engine.RouteContext;
20  import org.kuali.rice.kew.engine.RouteHelper;
21  import org.kuali.rice.kew.engine.node.*;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  
27  /**
28   * Handles transitions into and out of {@link SplitNode} nodes.
29   * 
30   * @see SplitNode
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class SplitTransitionEngine extends TransitionEngine {
35  	
36      public ProcessResult isComplete(RouteContext context) throws Exception {
37          SplitNode node = (SplitNode)getNode(context.getNodeInstance().getRouteNode(), SplitNode.class);
38          return node.process(context, getRouteHelper());
39      }
40      
41  	public Transition transitionFrom(RouteContext context, ProcessResult processResult)
42  			throws Exception {
43  		RouteNodeInstance splitInstance = context.getNodeInstance();
44  		List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
45          SplitResult result = (SplitResult)processResult;
46          for (String branchName : result.getBranchNames())
47          {
48              for (RouteNode routeNode : splitInstance.getRouteNode().getNextNodes())
49              {
50                  if (routeNode.getBranch() != null && routeNode.getBranch().getName().equals(branchName))
51                  {
52                      nextNodeInstances.add(createSplitChild(branchName, routeNode, splitInstance));
53                  }
54              }
55          }
56  		return new Transition(nextNodeInstances);
57  	}
58  	
59  	public static RouteNodeInstance createSplitChild(String branchName, RouteNode routeNode, RouteNodeInstance splitInstance) {
60  	    RouteHelper routeHelper = new RouteHelper();
61  	    RouteNodeInstance nextNodeInstance = routeHelper.getNodeFactory().createRouteNodeInstance(splitInstance.getDocumentId(), routeNode);
62  		Branch branch = routeHelper.getNodeFactory().createBranch(branchName, splitInstance.getBranch(), nextNodeInstance);
63  		branch.setSplitNode(splitInstance);
64  		nextNodeInstance.setBranch(branch);
65  		nextNodeInstance.setProcess(splitInstance.getProcess());
66  		return nextNodeInstance;
67  	}
68  	
69  }