1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.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.coreservice.api.CoreServiceApiServiceLocator;
21 import org.kuali.rice.coreservice.api.namespace.Namespace;
22 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
23
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.List;
28
29 public class NamespaceValuesFinder extends KeyValuesBase {
30
31 @Override
32 public List<KeyValue> getKeyValues() {
33
34
35 List<Namespace> namespaces = CoreServiceApiServiceLocator.getNamespaceService().findAllNamespaces();
36
37 namespaces = namespaces == null ? new ArrayList<Namespace>(0) : new ArrayList<Namespace>( namespaces );
38
39
40 Collections.sort(namespaces, NamespaceComparator.INSTANCE);
41
42
43 List<KeyValue> labels = new ArrayList<KeyValue>( namespaces.size() );
44 labels.add(new ConcreteKeyValue("", ""));
45 for ( Namespace namespace : namespaces ) {
46 labels.add( new ConcreteKeyValue(namespace.getCode(), namespace.getCode() + " - " + namespace.getName() ) );
47 }
48 return labels;
49 }
50
51 private static class NamespaceComparator implements Comparator<Namespace> {
52 public static final Comparator<Namespace> INSTANCE = new NamespaceComparator();
53
54 @Override
55 public int compare(Namespace o1, Namespace o2) {
56 return o1.getCode().compareTo( o2.getCode() );
57 }
58 }
59 }