1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.web.namespace;
17
18 import org.kuali.rice.core.api.util.ConcreteKeyValue;
19 import org.kuali.rice.core.api.util.KeyValue;
20 import org.kuali.rice.core.impl.namespace.NamespaceBo;
21 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.service.KeyValuesService;
24
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.Comparator;
28 import java.util.List;
29
30 public class NamespaceValuesFinder extends KeyValuesBase {
31
32 @Override
33 public List<KeyValue> getKeyValues() {
34
35
36 KeyValuesService boService = KRADServiceLocator.getKeyValuesService();
37 List<NamespaceBo> bos = (List<NamespaceBo>) boService.findAll(NamespaceBo.class);
38
39 if ( bos == null ) {
40 bos = new ArrayList<NamespaceBo>(0);
41 } else {
42 bos = new ArrayList<NamespaceBo>( bos );
43 }
44
45
46 Collections.sort(bos, NamespaceComparator.INSTANCE);
47
48
49 List<KeyValue> labels = new ArrayList<KeyValue>( bos.size() );
50 labels.add(new ConcreteKeyValue("", ""));
51 for ( NamespaceBo bo : bos ) {
52 labels.add( new ConcreteKeyValue(bo.getCode(), bo.getName() ) );
53 }
54 return labels;
55 }
56
57 private static class NamespaceComparator implements Comparator<NamespaceBo> {
58 public static final Comparator<NamespaceBo> INSTANCE = new NamespaceComparator();
59
60 @Override
61 public int compare(NamespaceBo o1, NamespaceBo o2) {
62 return o1.getCode().compareTo( o2.getCode() );
63 }
64 }
65 }