KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
9  * Every virtual module that needs individual data or configuration has
10  * the possibility to subclass this DataManager in order to implement its
11  * own data functionality. There are even specific datamanagers, like
12  * the SQLDataManager which can be used generally for all modules too.
13  *
14  * <hr>
15  * <table width="100%" border="0">
16  * <tr>
17  * <td width="24%"><b>Filename</b></td><td width="76%">PropertiesDataManager.java</td>
18  * </tr>
19  * <tr>
20  * <td width="24%"><b>Author</b></td><td width="76%">Guy Z�rcher (gzuercher@raptus.com)</td>
21  * </tr>
22  * <tr>
23  * <td width="24%"><b>Date</b></td><td width="76%">15th of April 2001</td>
24  * </tr>
25  * </table>
26  * <hr>
27  * <table width="100%" border="0">
28  * <tr>
29  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
30  * </tr>
31  * </table>
32  * <hr>
33  */

34 public class PropertiesDataManager extends Object JavaDoc implements DataManager
35 {
36     private static final String JavaDoc PROPERTY_SUFFIX = ".property.";
37
38     /**
39      *
40      */

41     protected VModule vmodule = null;
42
43     /**
44      *
45      */

46     protected String JavaDoc propPrefix = null;
47     /**
48      *
49      */

50     protected PropertiesFile datacfg = null;
51
52     /**
53      *
54      */

55     public boolean initialize(String JavaDoc file, String JavaDoc prefix)
56     {
57         propPrefix = prefix;
58         
59         LoggingManager.log("Initialising "+this.getClass().getName()+"with file " +
60                                    file + ", propPrefix="+prefix, this);
61 // if(!loadProperties(file))
62
// return false;
63

64         return true;
65     }
66
67     /**
68      * initializer which is reading the configuration file.
69      */

70     public boolean initialize(VModule m)
71     {
72         vmodule = m;
73 // VModuleManager vmm = VModuleManager.getInstance();
74
// String file = vmm.getWEBINFDir() + vmodule.getDatamanagerCfgFile();
75
//
76
// propPrefix = vmodule.getIdentification();
77
// if(!loadProperties(file))
78
// return false;
79
//
80
// LoggingManager.log("Data configuration file " + file + " successfully loaded", this);
81
propPrefix = vmodule.getIdentification();
82         return true;
83     }
84
85     /**
86      *
87      */

88     protected boolean loadProperties(String JavaDoc file)
89     {
90         if(file != null && file.length() > 0)
91         {
92             datacfg = new PropertiesFile(file);
93             if(!datacfg.load())
94             {
95                 LoggingManager.log("Cannot load PropertiesDataManager configurationfile " +
96                                    file + "!", this);
97                 return false;
98             }
99         }
100         else
101         {
102             LoggingManager.log("No datamanager configurationfile for " +
103                                propPrefix + " specified", this);
104             return false;
105         }
106
107         return true;
108     }
109
110     /**
111      *
112      */

113     public void saveProperties()
114     {
115         if(!datacfg.store())
116             LoggingManager.log("Failed to save properties for prefix scope " +
117                                propPrefix + " (File: " +
118                                datacfg.getPropertiesFilename(), this);
119     }
120
121     /**
122      *
123      */

124     public String JavaDoc getProperty(String JavaDoc property)
125     {
126         return datacfg.getProperty(propPrefix + PROPERTY_SUFFIX + property);
127     }
128
129     /**
130      *
131      */

132     public void setProperty(String JavaDoc property, String JavaDoc value)
133     {
134         datacfg.setProperty(propPrefix + PROPERTY_SUFFIX + property, value);
135     }
136
137     /**
138      * preparing the data for a virtual module means, creating SQL tables
139      * or XML files or stuff like that
140      */

141     public boolean prepareData()
142     {
143         LoggingManager.log("Preparing data for prefix scope " +
144                            propPrefix, this);
145         return true;
146     }
147
148 }
149
150 /* end class DataManager */
151
Popular Tags