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