01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.chart.lookup.keyvalues;
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.core.bo.KualiCodeBase;
24: import org.kuali.core.lookup.keyvalues.KeyValuesBase;
25: import org.kuali.core.service.KeyValuesService;
26: import org.kuali.core.web.ui.KeyLabelPair;
27: import org.kuali.kfs.context.SpringContext;
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.core.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(
46: KeyValuesService.class).findAll(this .getValuesClass());
47: List keyLabels = new ArrayList();
48:
49: // add a blank pair for the first/default key/value pair
50: keyLabels.add(new KeyLabelPair("", ""));
51:
52: // build the list of code/name combos
53: for (Iterator iter = businessObjects.iterator(); iter.hasNext();) {
54: KualiCodeBase businessObject = (KualiCodeBase) iter.next();
55: keyLabels.add(new KeyLabelPair(businessObject.getCode(),
56: businessObject.getCodeAndDescription()));
57: }
58:
59: return keyLabels;
60: }
61:
62: /**
63: * This method must be implemented by the base class, should return the Class of the object being looked up
64: *
65: * @return class of object being looked up
66: */
67: protected abstract Class getValuesClass();
68:
69: }
|