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.actions;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.kuali.rice.kew.engine.RouteContext;
23  import org.kuali.rice.kew.engine.RouteHelper;
24  import org.kuali.rice.kew.engine.node.SplitNode;
25  import org.kuali.rice.kew.engine.node.SplitResult;
26  
27  
28  public class CustomCycleSplit implements SplitNode {
29  
30      private static int timesToCycle = 0;
31      private static String cycleBranchName = null;
32      private static String nonCycleBranchName = null;
33      private static int timesCycled = 0;
34      
35      public SplitResult process(RouteContext context, RouteHelper helper) throws Exception {
36          List<String> branchNames = new ArrayList<String>();
37          if (org.apache.commons.lang.StringUtils.isEmpty(cycleBranchName) || org.apache.commons.lang.StringUtils.isEmpty(nonCycleBranchName)) {
38              throw new Exception("Must specify cycle and non-cycle branch names.");
39          }
40          if (timesCycled++ == timesToCycle) {
41              branchNames.add(nonCycleBranchName); 
42          } else {
43              branchNames.add(cycleBranchName);
44          }
45          return new SplitResult(branchNames);
46      }
47      
48      public static void configureCycle(String cycleBranchName, String nonCycleBranchName, int timesToCycle) {
49          CustomCycleSplit.cycleBranchName = cycleBranchName;
50          CustomCycleSplit.nonCycleBranchName = nonCycleBranchName;
51          CustomCycleSplit.timesToCycle = timesToCycle;
52          CustomCycleSplit.timesCycled = 0;
53      }
54      
55      public static int getTimesCycled() {
56          return timesCycled;
57      }
58  
59  }