KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > VModule


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3;
7
8 import java.text.ParseException JavaDoc;
9 import java.util.*;
10
11 import javax.sql.DataSource JavaDoc;
12
13 /**
14  *
15  * <hr>
16  * <table width="100%" border="0">
17  * <tr>
18  * <td width="24%"><b>Filename</b></td><td width="76%">VModule.java</td>
19  * </tr>
20  * <tr>
21  * <td width="24%"><b>Author</b></td><td width="76%">Guy Z�rcher (gzuercher@raptus.com)</td>
22  * </tr>
23  * <tr>
24  * <td width="24%"><b>Date</b></td><td width="76%">16th of April 2001</td>
25  * </tr>
26  * </table>
27  * <hr>
28  * <table width="100%" border="0">
29  * <tr>
30  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
31  * </tr>
32  * </table>
33  * <hr>
34  */

35 public class VModule extends Object JavaDoc
36 {
37     public static final int TYPE_VIRTUAL = 3;
38     public static final int TYPE_STANDARD = 2;
39     public static final int TYPE_BUILTIN = 1;
40
41     /**
42      *
43      */

44     protected String JavaDoc identification;
45
46     /**
47      *
48      */

49     protected int type;
50
51     /**
52      *
53      */

54     protected String JavaDoc[] locales;
55
56     /**
57      * deprecated
58      */

59 // protected String resources = null;
60

61     /**
62      *
63      */

64     protected String JavaDoc dmgrclass = null;
65
66     /**
67      *
68      */

69     protected String JavaDoc dmgrcfgfile = null;
70
71     /**
72      *
73      */

74     protected DataSource JavaDoc datasource = null;
75
76     /**
77      *
78      */

79     protected Configuration cfg = null;
80
81     /**
82      *
83      */

84     protected String JavaDoc[] sections;
85
86     /**
87      *
88      */

89     protected Hashtable vmoduleSections = null;
90     
91     /**
92      * The base vmodule, set if this is a virtual vmodule
93      */

94     protected String JavaDoc base= null;
95     
96     /**
97      * The roles for which this vmodule is accessible
98      */

99     protected String JavaDoc[] roles = null;
100     
101     /**
102      * Return the roles for this vmodule
103      */

104     public String JavaDoc[] getRoles()
105     {
106         return roles;
107     }
108     
109     /**
110      * returnt true if this vmodule is virtual one
111      */

112     public boolean isVirtual()
113     {
114         if(base != null)
115         {
116             return true;
117         }
118         else
119         {
120             return false;
121         }
122     }
123     
124     /**
125      * set the base vmodule name
126      */

127     public void setBaseModule(String JavaDoc baseModule)
128     {
129         this.base = baseModule;
130     }
131     
132     /**
133      * return the base module for this vmodule
134      */

135     public String JavaDoc getBaseModule()
136     {
137         return base;
138     }
139
140     /**
141      *
142      */

143     public boolean initialize(String JavaDoc vmid, DataSource JavaDoc ds)
144     {
145         XMLConfigManager cm = XMLConfigManager.getInstance();
146         cfg = cm.getConfiguration();
147
148         String JavaDoc pfx = Constants.VMODULE_PREFIX + vmid;
149         //String t = cfg.getStringByKey(pfx + Constants.VMODULE_PROPERTY_TYPE);
150
String JavaDoc t = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid,"type");
151         LoggingManager.log("VModule id is "+vmid+", type is "+t, this);
152         if(t.equals("virtual"))
153         {
154             base=cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid,"base");
155             LoggingManager.log("Base vmodule is "+base, this);
156         }
157         //locales = cfg.getStringArrayByKey(pfx + Constants.VMODULE_PROPERTY_LOCALES);
158

159         roles=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vmid+"/roles", "value");
160         LoggingManager.log("vmodule roles:"+roles, this);
161         if(roles != null)
162         {
163             for(int i=0;i<roles.length;i++)
164             {
165                 LoggingManager.log("Role for vmodule "+vmid+":"+roles[i], this);
166             }
167         }
168 //
169
// 20030623/gz: removed
170
// else
171
// {
172
// LoggingManager.log("No roles for vmodule"+vmid, this);
173
// }
174

175         
176         locales=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vmid+"/properties/property?name=locales", "value");
177         LoggingManager.log("vmodule locales:"+locales, this);
178
179         if((locales==null || locales.length<1) && isVirtual())
180         {
181             LoggingManager.log("Locale not found..loading from base!", this);
182             locales=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+base+"/properties/property?name=locales", "value");
183             LoggingManager.log("vmodule locales(from base module):"+locales, this);
184         }
185
186 //
187
// 20021230/gz: hack in order to get only ONE resource file per language for all modules
188
//
189
// //resources = cfg.getStringByKey(pfx + Constants.VMODULE_PROPERTY_RESOURCES);
190
// resources = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid+"/properties/property?name=resources", "value");
191
// LoggingManager.log("vmodule resources "+ resources, this);
192
// if((resources == null || resources.trim().length()<1)&&isVirtual())
193
// {
194
// resources = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+base+"/properties/property?name=resources", "value");
195
// LoggingManager.log("vmodule resources (from base module) "+ resources, this);
196
// }
197

198         //dmgrclass = cfg.getStringByKey(pfx + Constants.VMODULE_PROPERTY_DATA_MANAGER);
199
dmgrclass = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid+"/properties/property?name=manager", "value");
200         LoggingManager.log("vmodule manager "+dmgrclass, this);
201         if((dmgrclass==null || dmgrclass.trim().length()<1)&&isVirtual())
202         {
203             dmgrclass = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+base+"/properties/property?name=manager", "value");
204             LoggingManager.log("vmodule manager (from base class)"+dmgrclass, this);
205         }
206         
207         //dmgrcfgfile = cfg.getStringByKey(pfx + Constants.VMODULE_PROPERTY_DATA_CONFIG);
208
//sections = cfg.getStringArrayByKey(pfx + Constants.VMODULE_PROPERTY_SECTIONS);
209
sections=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vmid+"/section", "items");
210
211         if(t != null && locales != null && sections != null)
212         {
213             if(t.compareToIgnoreCase("STANDARD") == 0)
214                 type = TYPE_STANDARD;
215             else if(t.compareToIgnoreCase("BUILTIN") == 0)
216                 type = TYPE_BUILTIN;
217             else if(t.compareToIgnoreCase("VIRTUAL") == 0)
218                 type = TYPE_VIRTUAL;
219
220             datasource = ds;
221             identification = vmid;
222             vmoduleSections = new Hashtable();
223
224             // initialize all sections
225
for(int i = 0; i < sections.length; i ++)
226             {
227                 VModuleSection section = new VModuleSection();
228                 if(section.initialize(sections[i], this))
229                     vmoduleSections.put(sections[i], section);
230             }
231
232             LoggingManager.log("Returning true in vmodule.init()", this);
233             return true;
234         }
235
236         LoggingManager.log("Virtual module " + vmid + " cannot be initialized!", this);
237         return false;
238     }
239
240     /**
241      *
242      */

243     public DataManager getDatamanager()
244     {
245         DataManager dm = null;
246
247         if(dmgrclass != null && dmgrclass.length() > 0)
248         {
249             try
250             {
251                 Class JavaDoc classObj = Class.forName(dmgrclass);
252                 if(classObj == null)
253                 {
254                     LoggingManager.log("Can't load datamanager " + dmgrclass + "!", this);
255                     return null;
256                 }
257
258                 dm = (DataManager) classObj.newInstance();
259                 if(dm == null)
260                 {
261                     LoggingManager.log("Can't instantiate datamanager " + dmgrclass + "!", this);
262                     return null;
263                 }
264
265                 return dm;
266             }
267             catch(Exception JavaDoc e)
268             {
269                 LoggingManager.log("Exception while instantiating datamanager " + dmgrclass, this);
270                 LoggingManager.log(e.toString(), this);
271             }
272
273             LoggingManager.log("Created an instance of " + dmgrclass + " for virtual module " +
274                                identification, this);
275         }
276
277         return dm;
278     }
279
280     /**
281      *
282      */

283     public boolean isLocaleAvailable(Locale locale)
284     {
285         String JavaDoc lcmp = locale.toString();
286         for(int i = 0; i < locales.length; i ++)
287         {
288             if(lcmp.compareToIgnoreCase(locales[i]) == 0)
289                 return true;
290         }
291
292         return false;
293     }
294
295     /**
296      *
297      */

298     public String JavaDoc getStringProperty(String JavaDoc property)
299     {
300         return cfg.getStringByKey(Constants.VMODULE_PREFIX + identification +
301                                   Constants.VMODULE_PROPERTY_PREFIX + property);
302     }
303
304     /**
305      *
306      */

307     public boolean getBooleanProperty(String JavaDoc property)
308                    throws ParseException JavaDoc
309     {
310         return cfg.getBooleanByKey(Constants.VMODULE_PREFIX + identification +
311                                    Constants.VMODULE_PROPERTY_PREFIX + property);
312     }
313
314     /**
315      *
316      */

317     public int getIntegerProperty(String JavaDoc property)
318                throws ParseException JavaDoc
319     {
320         return cfg.getIntByKey(Constants.VMODULE_PREFIX + identification +
321                                Constants.VMODULE_PROPERTY_PREFIX + property);
322     }
323
324
325      /**
326      * added by REEA, we need a String Array getter too in case of file mime-types
327      */

328     public String JavaDoc[] getStringArrayProperty(String JavaDoc property)
329     {
330         return cfg.getStringArrayByKey(Constants.VMODULE_PREFIX + identification +
331                                   Constants.VMODULE_PROPERTY_PREFIX + property);
332     }
333
334
335     /**
336      *
337      */

338     public String JavaDoc getIdentification() { return identification; }
339
340     /**
341      *
342      */

343     public int getType() { return type; }
344
345     /**
346      *
347      */

348     public String JavaDoc[] getLocales() { return locales; }
349     public int getLocalesCount() { return locales.length; }
350
351     /**
352      * deprecated
353      */

354 // public String getResources() { return resources; }
355

356     /**
357      *
358      */

359     public String JavaDoc[] getSections() { return sections; }
360     public int getSectionsCount() { return sections.length; }
361
362     /**
363      *
364      */

365     public DataSource JavaDoc getDatasource() { return datasource; }
366
367     /**
368      *
369      */

370     public String JavaDoc getDatamanagerCfgFile() { return dmgrcfgfile; }
371
372     /**
373      *
374      */

375     public Configuration getConfiguration() { return cfg; }
376
377     /**
378      *
379      */

380     public VModuleSection getSection(String JavaDoc section) { return (VModuleSection) vmoduleSections.get(section); }
381
382 }
383
384 /* end class VModule */
385
Popular Tags