View Javadoc

1   /*
2    * Copyright 2005-2007 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.rule;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  /**
25   * A collection of rules uses by the web tier for rendering and interacting
26   * with the rules GUI.
27   *
28   * @see RuleBaseValues
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class MyRules implements Serializable {
33  
34  
35  	private static final long serialVersionUID = 9178574188141418571L;
36  	private List rules;
37  
38      public MyRules() {
39          rules = new ArrayList();
40      }
41  
42      public void addRule(RuleBaseValues rule, Integer counter) {
43          boolean alreadyAdded = false;
44          int location = 0;
45          for (Iterator ruleIter = getRules().iterator(); ruleIter.hasNext();) {
46              RuleBaseValues ruleRow = (RuleBaseValues) ruleIter.next();
47  
48              if (counter != null && counter.intValue() == location) {
49                  ruleRow.setActiveInd(rule.getActiveInd());
50                  ruleRow.setCurrentInd(rule.getCurrentInd());
51                  ruleRow.setVersionNumber(rule.getVersionNumber());
52                  ruleRow.setDescription(rule.getDescription());
53                  ruleRow.setForceAction(rule.getForceAction());
54                  ruleRow.setDocTypeName(rule.getDocTypeName());
55                  ruleRow.setFromDate(rule.getFromDate());
56                  ruleRow.setToDate(rule.getToDate());
57                  ruleRow.setRuleTemplate(rule.getRuleTemplate());
58                  ruleRow.setVersionNbr(rule.getVersionNbr());
59                  ruleRow.setResponsibilities(rule.getResponsibilities());
60                  ruleRow.setRuleExtensions(rule.getRuleExtensions());
61                  
62                  alreadyAdded = true;
63              }
64              location++;
65          }
66          if (!alreadyAdded) {
67              getRules().add(rule);
68          }
69      }
70  
71      public RuleBaseValues getRule(int index) {
72          while (getRules().size() <= index) {
73              RuleBaseValues rule = new RuleBaseValues();
74  //            rule.setPreviousVersion(new RuleBaseValues());
75              getRules().add(rule);
76          }
77          return (RuleBaseValues) getRules().get(index);
78      }
79  
80      public List getRules() {
81          return rules;
82      }
83  
84      public void setRules(List rules) {
85          this.rules = rules;
86      }
87  }