View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.businessobject.options;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.rice.core.api.util.ConcreteKeyValue;
23  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
24  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
25  
26  /**
27   * This class gets all the values of a parameter and then builds a list of key label pairs out of them, using each parameter value
28   * as both key and label
29   */
30  public class ParameterValuesFinder extends KeyValuesBase {
31      private Class componentClass;
32      private String parameterName;
33      private boolean insertBlankRow = true;
34  
35      public ParameterValuesFinder() {
36      }
37  
38      public ParameterValuesFinder(Class componentClass, String parameterName) {
39          this.componentClass = componentClass;
40          this.parameterName = parameterName;
41      }
42  
43      public List getKeyValues() {
44          List keyLabels = new ArrayList();
45          List<String> parameterValues = new ArrayList<String>( SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.componentClass, this.parameterName) );
46          if (insertBlankRow) {
47              keyLabels.add(new ConcreteKeyValue("", ""));
48          }
49          if (parameterValues != null) {
50              for (String parameterValue : parameterValues) {
51                  keyLabels.add(new ConcreteKeyValue(parameterValue, parameterValue));
52              }
53          }
54          return keyLabels;
55      }
56  
57      /**
58       * Gets the insertBlankRow attribute.
59       * 
60       * @return Returns the insertBlankRow.
61       */
62      public boolean shouldInsertBlankRow() {
63          return insertBlankRow;
64      }
65  
66      /**
67       * Sets the insertBlankRow attribute value.
68       * 
69       * @param insertBlankRow The insertBlankRow to set.
70       */
71      public void setInsertBlankRow(boolean insertBlankRow) {
72          this.insertBlankRow = insertBlankRow;
73      }
74  
75      /**
76       * Gets the componentClass attribute.
77       * 
78       * @return Returns the componentClass.
79       */
80      public Class getComponentClass() {
81          return componentClass;
82      }
83  
84      /**
85       * Gets the parameterName attribute.
86       * 
87       * @return Returns the parameterName.
88       */
89      public String getParameterName() {
90          return parameterName;
91      }
92  
93      /**
94       * Sets the componentClass attribute value.
95       * 
96       * @param componentClass The componentClass to set.
97       */
98      public void setComponentClass(Class componentClass) {
99          this.componentClass = componentClass;
100     }
101 
102     /**
103      * Sets the parameterName attribute value.
104      * 
105      * @param parameterName The parameterName to set.
106      */
107     public void setParameterName(String parameterName) {
108         this.parameterName = parameterName;
109     }
110 
111 
112 }