01: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.groups;
07:
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: import org.jasig.portal.ChannelDefinition;
12: import org.jasig.portal.ChannelRegistryStoreFactory;
13: import org.jasig.portal.IChannelRegistryStore;
14: import org.apache.commons.logging.Log;
15: import org.apache.commons.logging.LogFactory;
16:
17: /**
18: * Reference implementation of <code>IEntityNameFinder</code> for <code>Channels</code>.
19: * @author Alex Vigdor
20: * @version $Revision: 34837 $
21: */
22: public class ReferenceChannelNameFinder implements IEntityNameFinder {
23:
24: private static final Log log = LogFactory
25: .getLog(ReferenceChannelNameFinder.class);
26:
27: private static IEntityNameFinder _instance = null;
28: private Class type = null;
29:
30: protected ReferenceChannelNameFinder() {
31: try {
32: type = Class.forName("org.jasig.portal.ChannelDefinition");
33: } catch (Exception e) {
34: log
35: .error(
36: "Exception instantiating ReferenceChannelNameFinder.",
37: e);
38: }
39: }
40:
41: public static synchronized IEntityNameFinder singleton() {
42: if (_instance == null) {
43: _instance = new ReferenceChannelNameFinder();
44: }
45: return _instance;
46: }
47:
48: /**
49: * Given the key, returns the entity's name.
50: * @param key java.lang.String
51: */
52: public String getName(String key) throws Exception {
53: IChannelRegistryStore crs = ChannelRegistryStoreFactory
54: .getChannelRegistryStoreImpl();
55: ChannelDefinition cd = crs.getChannelDefinition(Integer
56: .parseInt(key));
57: return cd.getName();
58: }
59:
60: /**
61: * Given an array of keys, returns the names of the entities.
62: * @param keys java.lang.String[]
63: */
64: public Map getNames(String[] keys) throws Exception {
65: HashMap names = new HashMap();
66: for (int i = 0; i < keys.length; i++) {
67: names.put(keys[i], getName(keys[i]));
68: }
69: return names;
70: }
71:
72: /**
73: * Returns the entity type for this <code>IEntityFinder</code>.
74: * @return java.lang.Class
75: */
76: public Class getType() {
77: return type;
78: }
79: }
|