KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.lucane.server.store;
21
22 import org.lucane.server.*;
23 import org.lucane.common.concepts.*;
24 import org.lucane.common.crypto.MD5;
25 import org.lucane.server.store.sql.*;
26 import org.lucane.server.store.ldap.*;
27 import org.lucane.common.Logging;
28
29 /**
30  * The unique way to get Stores for the different concepts.
31  */

32 public class Store
33 {
34     private GroupStore group;
35     private PluginStore plugin;
36     private ServiceStore service;
37     private UserStore user;
38     
39     /**
40      * Constructor.
41      *
42      * Instantiate the managers and set some initial data if necessary
43      */

44     public Store(ServerConfig config)
45     throws Exception JavaDoc
46     {
47         String JavaDoc backend = config.getStoreBackend();
48         
49         if(backend.equals("database"))
50         {
51             Logging.getLogger().info("Using database backend");
52             this.group = new SqlGroupStore(this);
53             this.plugin = new SqlPluginStore();
54             this.service = new SqlServiceStore();
55             this.user = new SqlUserStore();
56         }
57         else if(backend.equals("ldap"))
58         {
59             Logging.getLogger().info("Using ldap backend");
60             LdapConfig ldapConfig = new LdapConfig(LdapConfig.CONFIG_FILE);
61             this.group = new LdapGroupStore(this, ldapConfig);
62             this.plugin = new LdapPluginStore(ldapConfig);
63             this.service = new LdapServiceStore(ldapConfig);
64             this.user = new LdapUserStore(ldapConfig);
65         }
66         else
67             throw new Exception JavaDoc("no such backend : '" + backend + "'");
68         
69         if(! this.group.isInitialized())
70             setInitialData();
71     }
72     
73     /**
74      * Get the GroupStore
75      *
76      * @return the GroupStore instance
77      */

78     public GroupStore getGroupStore()
79     {
80         return group;
81     }
82     
83     /**
84      * Get the PluginStore
85      *
86      * @return the PluginStore instance
87      */

88     public PluginStore getPluginStore()
89     {
90         return plugin;
91     }
92     
93     /**
94      * Get the ServiceStore
95      *
96      * @return the ServiceStore instance
97      */

98     public ServiceStore getServiceStore()
99     {
100         return service;
101     }
102     
103     /**
104      * Get the UserStore
105      *
106      * @return the UserStore instance
107      */

108     public UserStore getUserStore()
109     {
110         return user;
111     }
112     
113     /**
114      * Set some default initial data.
115      * Called by the constructor.
116      */

117     private void setInitialData()
118     throws Exception JavaDoc
119     {
120         //groups
121
GroupConcept allUsers = new GroupConcept("AllUsers");
122         GroupConcept admins = new GroupConcept("Admins");
123         GroupConcept shutdownGroup = new GroupConcept("Shutdown");
124         admins.addParent(allUsers);
125
126         //admin user
127
UserConcept admin = new UserConcept("admin", MD5.encode("admin"),
128                 "Admin User", "", "en", false, "org.lucane.applications.quicklaunch");
129         admins.addUser(admin);
130         getUserStore().storeUser(admin);
131
132         //shutdown user
133
UserConcept shutdown = new UserConcept("shutdown", MD5.encode("shutdown"),
134                 "Shutdown User", "", "en", false, "org.lucane.applications.shutdown");
135         shutdownGroup.addUser(shutdown);
136         getUserStore().storeUser(shutdown);
137         
138         //guest user
139
UserConcept guest = new UserConcept("guest", MD5.encode("guest"),
140                 "Guest User", "", "en", false, "org.lucane.applications.quicklaunch");
141         allUsers.addUser(guest);
142         getUserStore().storeUser(guest);
143
144         //administrator application
145
PluginConcept administratorPlugin = new PluginConcept("org.lucane.applications.administrator", "0.7.5");
146         ServiceConcept administratorService = new ServiceConcept("org.lucane.applications.administrator", false);
147         admins.addPlugin(administratorPlugin);
148         admins.addService(administratorService);
149         getPluginStore().storePlugin(administratorPlugin);
150         getServiceStore().storeService(administratorService);
151         
152         //shutdown application
153
PluginConcept shutdownPlugin = new PluginConcept("org.lucane.applications.shutdown", "0.7.5");
154          ServiceConcept shutdownService = new ServiceConcept("org.lucane.applications.shutdown", false);
155          admins.addPlugin(shutdownPlugin);
156          admins.addService(shutdownService);
157          shutdownGroup.addPlugin(shutdownPlugin);
158          shutdownGroup.addService(shutdownService);
159          getPluginStore().storePlugin(shutdownPlugin);
160          getServiceStore().storeService(shutdownService);
161
162         //forum application
163
PluginConcept forumPlugin = new PluginConcept("org.lucane.applications.forum", "0.7.5");
164         ServiceConcept forumService = new ServiceConcept("org.lucane.applications.forum", false);
165         allUsers.addPlugin(forumPlugin);
166         allUsers.addService(forumService);
167         getPluginStore().storePlugin(forumPlugin);
168         getServiceStore().storeService(forumService);
169         
170         //forumadmin application
171
PluginConcept forumadminPlugin = new PluginConcept("org.lucane.applications.forumadmin", "0.7.5");
172         ServiceConcept forumadminService = new ServiceConcept("org.lucane.applications.forumadmin", false);
173         admins.addPlugin(forumadminPlugin);
174         admins.addService(forumadminService);
175         getPluginStore().storePlugin(forumadminPlugin);
176         getServiceStore().storeService(forumadminService);
177         
178         //helpbrowser application
179
PluginConcept helpbrowserPlugin = new PluginConcept("org.lucane.applications.helpbrowser", "0.7.5");
180         allUsers.addPlugin(helpbrowserPlugin);
181         getPluginStore().storePlugin(helpbrowserPlugin);
182                 
183         //maininterface application
184
PluginConcept maininterfacePlugin = new PluginConcept("org.lucane.applications.maininterface", "0.7.5");
185         ServiceConcept maininterfaceService = new ServiceConcept("org.lucane.applications.maininterface", false);
186         allUsers.addPlugin(maininterfacePlugin);
187         allUsers.addService(maininterfaceService);
188         admins.addPlugin(maininterfacePlugin);
189         admins.addService(maininterfaceService);
190         getPluginStore().storePlugin(maininterfacePlugin);
191         getServiceStore().storeService(maininterfaceService);
192         
193         //quicklaunch application
194
PluginConcept quicklaunchPlugin = new PluginConcept("org.lucane.applications.quicklaunch", "0.7.5");
195         allUsers.addPlugin(quicklaunchPlugin);
196         admins.addPlugin(quicklaunchPlugin);
197         getPluginStore().storePlugin(quicklaunchPlugin);
198         
199         //notes application
200
PluginConcept notesPlugin = new PluginConcept("org.lucane.applications.notes", "0.7.5");
201         ServiceConcept notesService = new ServiceConcept("org.lucane.applications.notes", false);
202         allUsers.addPlugin(notesPlugin);
203         allUsers.addService(notesService);
204         getPluginStore().storePlugin(notesPlugin);
205         getServiceStore().storeService(notesService);
206                 
207         //passwdchanger application
208
PluginConcept passwdchangerPlugin = new PluginConcept("org.lucane.applications.passwdchanger", "0.7.5");
209         ServiceConcept passwdchangerService = new ServiceConcept("org.lucane.applications.passwdchanger", false);
210         allUsers.addPlugin(passwdchangerPlugin);
211         allUsers.addService(passwdchangerService);
212         admins.addPlugin(passwdchangerPlugin);
213         admins.addService(passwdchangerService);
214         getPluginStore().storePlugin(passwdchangerPlugin);
215         getServiceStore().storeService(passwdchangerService);
216
217         //userprofile application
218
PluginConcept userprofilePlugin = new PluginConcept("org.lucane.applications.userprofile", "0.7.5");
219         ServiceConcept userprofileService = new ServiceConcept("org.lucane.applications.userprofile", false);
220         allUsers.addPlugin(userprofilePlugin);
221         allUsers.addService(userprofileService);
222         getPluginStore().storePlugin(userprofilePlugin);
223         getServiceStore().storeService(userprofileService);
224         
225         //pluginsinfos application
226
PluginConcept pluginsinfosPlugin = new PluginConcept("org.lucane.applications.pluginsinfos", "0.7.5");
227         allUsers.addPlugin(pluginsinfosPlugin);
228         getPluginStore().storePlugin(pluginsinfosPlugin);
229        
230         //quickmessage application
231
PluginConcept quickmessagePlugin = new PluginConcept("org.lucane.applications.quickmessage", "0.7.5");
232         allUsers.addPlugin(quickmessagePlugin);
233         admins.addPlugin(quickmessagePlugin);
234         getPluginStore().storePlugin(quickmessagePlugin);
235               
236         //reunion application
237
PluginConcept reunionPlugin = new PluginConcept("org.lucane.applications.reunion", "0.7.5");
238         allUsers.addPlugin(reunionPlugin);
239         getPluginStore().storePlugin(reunionPlugin);
240         
241         //sendfile application
242
PluginConcept sendfilePlugin = new PluginConcept("org.lucane.applications.sendfile", "0.7.5");
243         allUsers.addPlugin(sendfilePlugin);
244         getPluginStore().storePlugin(sendfilePlugin);
245
246         //audioconf application
247
PluginConcept audioconfPlugin = new PluginConcept("org.lucane.applications.audioconf", "0.7.5");
248         allUsers.addPlugin(audioconfPlugin);
249         getPluginStore().storePlugin(audioconfPlugin);
250
251         //kick application
252
PluginConcept kickPlugin = new PluginConcept("org.lucane.applications.kick", "0.7.5");
253         admins.addPlugin(kickPlugin);
254         getPluginStore().storePlugin(kickPlugin);
255                 
256         //sendmail application
257
PluginConcept sendmailPlugin = new PluginConcept("org.lucane.applications.sendmail", "0.7.5");
258         ServiceConcept sendmailService = new ServiceConcept("org.lucane.applications.sendmail", false);
259         admins.addPlugin(sendmailPlugin);
260         allUsers.addService(sendmailService);
261         getPluginStore().storePlugin(sendmailPlugin);
262         getServiceStore().storeService(sendmailService);
263
264         //sqlnavigator application
265
PluginConcept sqlnavigatorPlugin = new PluginConcept("org.lucane.applications.sqlnavigator", "0.7.5");
266         ServiceConcept sqlnavigatorService = new ServiceConcept("org.lucane.applications.sqlnavigator", false);
267         admins.addPlugin(sqlnavigatorPlugin);
268         admins.addService(sqlnavigatorService);
269         getPluginStore().storePlugin(sqlnavigatorPlugin);
270         getServiceStore().storeService(sqlnavigatorService);
271
272         //calendar application
273
PluginConcept calendarPlugin = new PluginConcept("org.lucane.applications.calendar", "0.7.5");
274         ServiceConcept calendarService = new ServiceConcept("org.lucane.applications.calendar", false);
275         allUsers.addPlugin(calendarPlugin);
276         allUsers.addService(calendarService);
277         getPluginStore().storePlugin(calendarPlugin);
278         getServiceStore().storeService(calendarService);
279         
280         //calendarprefs application
281
PluginConcept calendarprefsPlugin = new PluginConcept("org.lucane.applications.calendarprefs", "0.7.5");
282         allUsers.addPlugin(calendarprefsPlugin);
283         getPluginStore().storePlugin(calendarprefsPlugin);
284
285         //reminder application
286
PluginConcept reminderPlugin = new PluginConcept("org.lucane.applications.reminder", "0.7.5");
287         ServiceConcept reminderService = new ServiceConcept("org.lucane.applications.reminder", false);
288         allUsers.addPlugin(reminderPlugin);
289         allUsers.addService(reminderService);
290         getPluginStore().storePlugin(reminderPlugin);
291         getServiceStore().storeService(reminderService);
292         
293         //jmail
294
PluginConcept jmailPlugin = new PluginConcept("org.lucane.applications.jmail", "0.7.5");
295         ServiceConcept jmailService = new ServiceConcept("org.lucane.applications.jmail", false);
296         allUsers.addPlugin(jmailPlugin);
297         allUsers.addService(jmailService);
298         getPluginStore().storePlugin(jmailPlugin);
299         getServiceStore().storeService(jmailService);
300
301         //jmail account
302
PluginConcept jmailaccountPlugin = new PluginConcept("org.lucane.applications.jmailaccount", "0.7.5");
303         ServiceConcept jmailaccountService = new ServiceConcept("org.lucane.applications.jmailaccount", false);
304         allUsers.addPlugin(jmailaccountPlugin);
305         allUsers.addService(jmailaccountService);
306         getPluginStore().storePlugin(jmailaccountPlugin);
307         getServiceStore().storeService(jmailaccountService);
308
309         //jmail admin
310
PluginConcept jmailadminPlugin = new PluginConcept("org.lucane.applications.jmailadmin", "0.7.5");
311         ServiceConcept jmailadminService = new ServiceConcept("org.lucane.applications.jmailadmin", false);
312         admins.addPlugin(jmailadminPlugin);
313         admins.addService(jmailadminService);
314         getPluginStore().storePlugin(jmailadminPlugin);
315         getServiceStore().storeService(jmailadminService);
316         
317         //todolist application
318
PluginConcept todolistPlugin = new PluginConcept("org.lucane.applications.todolist", "0.7.5");
319         ServiceConcept todolistService = new ServiceConcept("org.lucane.applications.todolist", false);
320         allUsers.addPlugin(todolistPlugin);
321         allUsers.addService(todolistService);
322         getPluginStore().storePlugin(todolistPlugin);
323         getServiceStore().storeService(todolistService);
324         
325         //rssreader application
326
PluginConcept rssreaderPlugin = new PluginConcept("org.lucane.applications.rssreader", "0.7.5");
327         ServiceConcept rssreaderService = new ServiceConcept("org.lucane.applications.rssreader", false);
328         allUsers.addPlugin(rssreaderPlugin);
329         allUsers.addService(rssreaderService);
330         getPluginStore().storePlugin(rssreaderPlugin);
331         getServiceStore().storeService(rssreaderService);
332
333         //sharedfolder application
334
PluginConcept sharedfolderPlugin = new PluginConcept("org.lucane.applications.sharedfolder", "0.7.5");
335         ServiceConcept sharedfolderService = new ServiceConcept("org.lucane.applications.sharedfolder", false);
336         allUsers.addPlugin(sharedfolderPlugin);
337         allUsers.addService(sharedfolderService);
338         getPluginStore().storePlugin(sharedfolderPlugin);
339         getServiceStore().storeService(sharedfolderService);
340
341         //whiteboard application
342
PluginConcept whiteboardPlugin = new PluginConcept("org.lucane.applications.whiteboard", "0.7.5");
343         allUsers.addPlugin(whiteboardPlugin);
344         getPluginStore().storePlugin(whiteboardPlugin);
345
346         //slideshow application
347
PluginConcept slideshowPlugin = new PluginConcept("org.lucane.applications.slideshow", "0.7.5");
348         allUsers.addPlugin(slideshowPlugin);
349         getPluginStore().storePlugin(slideshowPlugin);
350
351         //webconnector
352
ServiceConcept webconnectorService = new ServiceConcept("org.lucane.webconnector", false);
353         allUsers.addService(webconnectorService);
354         getServiceStore().storeService(webconnectorService);
355
356         //webadmin application
357
PluginConcept webadminPlugin = new PluginConcept("org.lucane.applications.webadmin", "0.7.5");
358         ServiceConcept webadminService = new ServiceConcept("org.lucane.applications.webadmin", false);
359         admins.addPlugin(webadminPlugin);
360         admins.addService(webadminService);
361         getPluginStore().storePlugin(webadminPlugin);
362         getServiceStore().storeService(webadminService);
363
364         
365         getGroupStore().storeGroup(allUsers);
366         getGroupStore().storeGroup(admins);
367         getGroupStore().storeGroup(shutdownGroup);
368     }
369 }
370
Popular Tags