KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import org.lucane.server.*;
24 import org.lucane.common.concepts.*;
25
26 /**
27  * PluginManager abstraction
28  */

29 public abstract class PluginStore
30 {
31     /**
32      * Store a plugin concept.
33      *
34      * @param plugin the PluginConcept to store
35      */

36     public abstract void storePlugin(PluginConcept plugin) throws Exception JavaDoc;
37
38     /**
39      * Update a plugin concept.
40      *
41      * @param plugin the PluginConcept to update
42      */

43     public abstract void updatePlugin(PluginConcept plugin) throws Exception JavaDoc;
44
45     /**
46      * Remove a plugin from the store.
47      *
48      * @param plugin the PluginConcept to remove
49      */

50     public abstract void removePlugin(PluginConcept plugin) throws Exception JavaDoc;
51
52     /**
53      * Retrieve a plugin by its name
54      *
55      * @param name the plugin to fetch
56      * @return the corresponding PluginConcept or null
57      */

58     public abstract PluginConcept getPlugin(String JavaDoc name) throws Exception JavaDoc;
59
60     /**
61      * Get all plugins
62      *
63      * @return an iterator listing all plugins
64      */

65     public abstract Iterator getAllPlugins() throws Exception JavaDoc;
66     
67     /**
68      * Get the plugins a user can use
69      *
70      * @param user the UserConcept
71      * @return the list of authorized plugins
72      */

73     public Iterator getAuthorizedPlugins(UserConcept user)
74     throws Exception JavaDoc
75     {
76         ArrayList authorizedPlugins = new ArrayList();
77         
78         UserStore us = Server.getInstance().getStore().getUserStore();
79         Iterator groups = us.getAllUserGroups(user);
80         while(groups.hasNext())
81         {
82             GroupConcept group = (GroupConcept)groups.next();
83             Iterator plugins = group.getPlugins();
84             while(plugins.hasNext())
85             {
86                 PluginConcept plugin = (PluginConcept)plugins.next();
87                 if(! authorizedPlugins.contains(plugin))
88                     authorizedPlugins.add(plugin);
89             }
90         }
91                 
92         return authorizedPlugins.iterator();
93     }
94     
95     /**
96      * Check if a user can use a plugin
97      *
98      * @param user the UserConcept
99      * @param plugin the PluginConcept
100      * @return true if the user has access to the plugin, false instead.
101      */

102     public boolean isAuthorizedPlugin(UserConcept user, PluginConcept plugin)
103     throws Exception JavaDoc
104     {
105         Iterator i = getAuthorizedPlugins(user);
106         while(i.hasNext())
107         {
108             Object JavaDoc o = i.next();
109                 
110             if(plugin.equals(o))
111                 return true;
112         }
113         
114         return false;
115     }
116     
117     /**
118      * Get all users that can use a plugin
119      *
120      * @param plugin the PluginConcept
121      * @return the list of users that have access to this plugin
122      */

123     public Iterator getUsersFor(PluginConcept plugin)
124     throws Exception JavaDoc
125     {
126         ArrayList users = new ArrayList();
127
128         UserStore us = Server.getInstance().getStore().getUserStore();
129         Iterator i = us.getAllUsers();
130         while(i.hasNext())
131         {
132             UserConcept user = (UserConcept)i.next();
133             if(isAuthorizedPlugin(user, plugin))
134                         users.add(user);
135         }
136         
137         return users.iterator();
138     }
139 }
Popular Tags