01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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 edu.iu.uis.eden.actions;
18:
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: import edu.iu.uis.eden.engine.RouteContext;
23: import edu.iu.uis.eden.engine.RouteHelper;
24: import edu.iu.uis.eden.engine.node.SplitNode;
25: import edu.iu.uis.eden.engine.node.SplitResult;
26: import edu.iu.uis.eden.util.Utilities;
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)
36: throws Exception {
37: List branchNames = new ArrayList();
38: if (Utilities.isEmpty(cycleBranchName)
39: || Utilities.isEmpty(nonCycleBranchName)) {
40: throw new Exception(
41: "Must specify cycle and non-cycle branch names.");
42: }
43: if (timesCycled++ == timesToCycle) {
44: branchNames.add(nonCycleBranchName);
45: } else {
46: branchNames.add(cycleBranchName);
47: }
48: return new SplitResult(branchNames);
49: }
50:
51: public static void configureCycle(String cycleBranchName,
52: String nonCycleBranchName, int timesToCycle) {
53: CustomCycleSplit.cycleBranchName = cycleBranchName;
54: CustomCycleSplit.nonCycleBranchName = nonCycleBranchName;
55: CustomCycleSplit.timesToCycle = timesToCycle;
56: CustomCycleSplit.timesCycled = 0;
57: }
58:
59: public static int getTimesCycled() {
60: return timesCycled;
61: }
62:
63: }
|