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.services.GroupService;
12: import org.apache.commons.logging.Log;
13: import org.apache.commons.logging.LogFactory;
14:
15: /**
16: * Reference implementation of <code>IEntityNameFinder</code> for <code>IEntityGroup</code>.
17: * @author Alex Vigdor
18: * @version $Revision: 34837 $
19: */
20: public class EntityGroupNameFinder implements IEntityNameFinder {
21: private static final Log log = LogFactory
22: .getLog(EntityGroupNameFinder.class);
23: private static IEntityNameFinder _instance = null;
24: private Class type = null;
25:
26: protected EntityGroupNameFinder() {
27: try {
28: type = Class
29: .forName("org.jasig.portal.groups.IEntityGroup");
30: } catch (Exception e) {
31: log.error(e, e);
32: }
33: }
34:
35: public synchronized static IEntityNameFinder singleton() {
36: if (_instance == null) {
37: _instance = new EntityGroupNameFinder();
38: }
39: return _instance;
40: }
41:
42: /**
43: * Given the key, returns the entity's name.
44: * @param key java.lang.String
45: */
46: public String getName(String key) throws Exception {
47: IEntityGroup g = GroupService.findGroup(key);
48: return g.getName();
49: }
50:
51: /**
52: * Given an array of keys, returns the names of the entities.
53: * @param keys java.lang.String[]
54: */
55: public Map getNames(String[] keys) throws Exception {
56: HashMap names = new HashMap();
57: for (int i = 0; i < keys.length; i++) {
58: names.put(keys[i], getName(keys[i]));
59: }
60: return names;
61: }
62:
63: /**
64: * Returns the entity type for this <code>IEntityFinder</code>.
65: * @return java.lang.Class
66: */
67: public Class getType() {
68: return type;
69: }
70: }
|