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.coa.businessobject.options;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.rice.core.api.util.ConcreteKeyValue;
25 import org.kuali.rice.krad.bo.KualiCodeBase;
26 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
27 import org.kuali.rice.krad.service.KeyValuesService;
28
29 /**
30 * This class is the base class for all the ValueFinders for any class extending KualiSystemCode. Subclasses should extend this, but
31 * do nothing. Just extending this class will be sufficient to work.
32 */
33 public abstract class KualiSystemCodeValuesFinder extends KeyValuesBase {
34
35 /**
36 * Calls getValuesClass() to generate a list of key/value pairs from the {@link KualiCodeBase}'s code as the key and the code
37 * and description as the value
38 *
39 * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
40 * @return list of key/value pairs for displaying on the client side
41 */
42 public List getKeyValues() {
43
44 // get all the KualiCodeService objects that are associated with this class
45 Collection businessObjects = SpringContext.getBean(KeyValuesService.class).findAll(this.getValuesClass());
46 List keyLabels = new ArrayList();
47
48 // add a blank pair for the first/default key/value pair
49 keyLabels.add(new ConcreteKeyValue("", ""));
50
51 // build the list of code/name combos
52 for (Iterator iter = businessObjects.iterator(); iter.hasNext();) {
53 KualiCodeBase businessObject = (KualiCodeBase) iter.next();
54 keyLabels.add(new ConcreteKeyValue(businessObject.getCode(), businessObject.getCodeAndDescription()));
55 }
56
57 return keyLabels;
58 }
59
60 /**
61 * This method must be implemented by the base class, should return the Class of the object being looked up
62 *
63 * @return class of object being looked up
64 */
65 protected abstract Class getValuesClass();
66
67 }