KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > server > store > GroupStore


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.server.store;
20
21 import java.util.*;
22 import org.lucane.common.concepts.*;
23 import org.lucane.server.Server;
24
25 /**
26  * GroupManager abstraction.
27  */

28 public abstract class GroupStore
29 {
30   /**
31    * Does the store has any data ?
32    *
33    * @return true if the store is already created
34    */

35   public abstract boolean isInitialized() throws Exception JavaDoc;
36     
37   /**
38    * Store a group.
39    *
40    * @param group the GroupConcept to store
41    */

42   public abstract void storeGroup(GroupConcept group) throws Exception JavaDoc;
43   
44   /**
45    * Store a group.
46    *
47    * @param group the GroupConcept to store
48    */

49   public abstract void updateGroup(GroupConcept group) throws Exception JavaDoc;
50     
51   /**
52    * Remove a group
53    *
54    * @param group the GroupConcept to remove
55    */

56   public abstract void removeGroup(GroupConcept group) throws Exception JavaDoc;
57   
58   /**
59    * Fetch a group
60    *
61    * @param name the name of the group to fetch
62    * @return the GroupConcept or null if no group of this name exists.
63    */

64   public abstract GroupConcept getGroup(String JavaDoc name) throws Exception JavaDoc;
65   
66   /**
67    * Fetch all groups
68    *
69    * @return an iterator listing all groups available.
70    */

71   public abstract Iterator getAllGroups() throws Exception JavaDoc;
72   
73   /**
74    * Get all users that are in a group or in a child group
75    *
76    * @param group the GroupConcept
77    * @return the list of users that are in this group (or in a child)
78    */

79   public Iterator getUsersFor(GroupConcept group)
80   throws Exception JavaDoc
81   {
82       ArrayList list = new ArrayList();
83
84       UserStore us = Server.getInstance().getStore().getUserStore();
85       Iterator users = us.getAllUsers();
86       while(users.hasNext())
87       {
88           UserConcept user = (UserConcept)users.next();
89           Iterator groups = us.getAllUserGroups(user);
90           while(groups.hasNext())
91           {
92             if(group.equals(groups.next()))
93             {
94                 list.add(user);
95                 break;
96             }
97           }
98       }
99         
100       return list.iterator();
101   }
102 }
Popular Tags