KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > daemon > group > GroupManager


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.daemon.group;
6
7 import java.util.Enumeration JavaDoc;
8 import java.util.Hashtable JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 import ve.luz.ica.jackass.util.ConfigurationManager;
17
18 /**
19  * Class group manager keeps a map of the groups to which this node belongs
20  * @author Carlos Arévalo
21  */

22 public final class GroupManager
23 {
24     private static Log log = LogFactory.getLog(GroupManager.class);
25
26     private static GroupManager manager = null;
27     private Map JavaDoc groups;
28
29     /**
30      * Returns the singleton GroupManager
31      * @return the singleton GroupManager
32      */

33     public static GroupManager getManager()
34     {
35         if (manager == null)
36         {
37             manager = new GroupManager();
38         }
39         return manager;
40     }
41
42     /**
43      * Class constructor.
44      * It scans the configuration file for entries that begin with group.
45      */

46     private GroupManager()
47     {
48         groups = new Hashtable JavaDoc();
49         Properties JavaDoc cf = ConfigurationManager.getConfigFile();
50         Enumeration JavaDoc e = cf.propertyNames();
51         while (e.hasMoreElements())
52         {
53             String JavaDoc name = (String JavaDoc) e.nextElement();
54             if (name.startsWith("group."))
55             {
56                 String JavaDoc groupName = cf.getProperty(name);
57                 if (log.isDebugEnabled())
58                 {
59                     log.debug("Creating group "+name);
60                 }
61                 GroupNode gm = new GroupNode(groupName);
62                 groups.put(groupName, gm);
63             }
64         }
65
66     }
67
68     /**
69      * Get a group given its name
70      * @param name the name of the group to be retrieved
71      * @return the group associated with the given name
72      */

73     public GroupNode getGroupMember(String JavaDoc name)
74     {
75         return (GroupNode) groups.get(name);
76     }
77
78     /**
79      * Returns an Iterator on the the list of keys (group names)
80      * @return the Iterator
81      */

82     public Iterator JavaDoc getGroupNames()
83     {
84         return groups.keySet().iterator();
85     }
86 }
87
Popular Tags