KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > engine > JSharedObjects


1 /*
2     =========================================================================
3     Package engine - Implements the engine package.
4
5     This module is developed and maintained by PlanetaMessenger.org.
6     Specs, New and updated versions can be found in
7     http://www.planetamessenger.org
8     If you want contact the Team please send a email to Project Manager
9     Leidson Campos Alves Ferreira at leidson@planetamessenger.org
10
11     Copyright (C) since 2001 by PlanetaMessenger.org
12
13     This program is free software; you can redistribute it and/or modify
14     it under the terms of the GNU General Public License as published by
15     the Free Software Foundation; either version 2 of the License, or
16     (at your option) any later version.
17
18     This program is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21     GNU General Public License for more details.
22
23     You should have received a copy of the GNU General Public License
24     along with this program; if not, write to the Free Software
25     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27     =========================================================================
28 */

29 /**
30  *
31  * $Id: JSharedObjects.java,v 1.24 2007/02/03 18:47:06 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.24 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.engine;
40
41 import org.planetamessenger.db.*;
42 import org.planetamessenger.io.*;
43 import org.planetamessenger.ui.*;
44 import org.planetamessenger.mos.forms.*;
45
46
47 public class JSharedObjects {
48   
49   static private JConsoleWindow console = null;
50   static private JMOSWindow parentWindow = null;
51   static private JPluginEngine plugins = null;
52   static private JProfileManager profile = null;
53   static private JContactListManager contactListManager = null;
54   static private JConfiguration config = null;
55   static private JProxySettings proxySettings = null;
56   static private JDatabase database = null;
57   static private JResources resources = null;
58   static private JLookAndFeelManager plafManager = null;
59   static private JLanguageManager languageManager = null;
60   static private JPluginPreferencesManager pluginPreferencesManager = null;
61   static private JKernelManager kernelManager = null;
62   static private JUserInterfaceManager userInterfaceManager = null;
63   
64
65   /**
66    * Initializes the object sharing engine.
67    * @param parentWindow The MOS parent window;
68    */

69   static public boolean init( JMOSWindow parentWindow ) {
70
71     // Init the configuration file and database connection
72
try {
73       JSharedObjects.console = new JConsoleWindow();
74       
75       // Set the new debug output
76
System.setErr( JSharedObjects.console );
77       System.setOut( JSharedObjects.console );
78
79       JSharedObjects.config = new JConfiguration();
80       JSharedObjects.database = new JDatabase( "org.hsqldb.jdbcDriver" );
81
82       if( !database.open( "jdbc:hsqldb:file:" + config.getDatabaseName(), "sa", "" ) )
83         return false;
84
85     } catch( java.lang.Exception JavaDoc e ) {
86       System.err.println( "JSharedObjects.init() - " + e );
87       return false;
88     }
89     
90     // API's & others initializations
91
JSharedObjects.parentWindow = parentWindow;
92     JSharedObjects.resources = new JResources( config.getResourcesPath() );
93     JSharedObjects.contactListManager = new JContactListManager();
94     JSharedObjects.profile = new JProfileManager();
95     JSharedObjects.proxySettings = new JProxySettings();
96     JSharedObjects.plugins = new JPluginEngine();
97     JSharedObjects.plafManager = new JLookAndFeelManager();
98     JSharedObjects.languageManager = new JLanguageManager();
99     JSharedObjects.kernelManager = new JKernelManager();
100     JSharedObjects.userInterfaceManager = new JUserInterfaceManager();
101     JSharedObjects.pluginPreferencesManager = new JPluginPreferencesManager();
102
103     return true;
104   }
105
106   /**
107    * Releases all object data, database
108    * connections and others finalizations.
109    */

110   static public void destroy() {
111
112     config.setMainWindowProperties( parentWindow.getLocation(), parentWindow.getSize(), parentWindow.isVisible() );
113     
114     // After HSQLDB 1.8 and higher a explicit SHUTDOWN is required.
115
database.execute( "SHUTDOWN" );
116     database.close();
117     console.destroy();
118     plugins.destroy();
119     plafManager.destroy();
120     languageManager.destroy();
121     pluginPreferencesManager.destroy();
122     
123     console = null;
124     contactListManager = null;
125     profile = null;
126     parentWindow = null;
127     config = null;
128     database = null;
129     resources = null;
130     plugins = null;
131     plafManager = null;
132     languageManager = null;
133     pluginPreferencesManager = null;
134     userInterfaceManager = null;
135   }
136   
137   /**
138    * Returns the shared contact list manager
139    * system object
140    */

141   static public JContactListManager getContactListManager() {
142     
143     return contactListManager;
144   }
145
146   /**
147    * Returns the shared database system
148    * object.
149    */

150   static public JDatabase getDatabase() {
151     
152     return database;
153   }
154
155   /**
156    * Returns the profile manager
157    * system object.
158    */

159   static public JProfileManager getProfileManager() {
160     
161     return profile;
162   }
163
164   /**
165    * Returns the plugin engine
166    * system object.
167    */

168   static public JPluginEngine getPluginEngine() {
169     
170     return plugins;
171   }
172
173   /**
174    * Returns the configuration object.
175    */

176   static public JConfiguration getConfiguration() {
177     
178     return config;
179   }
180   
181   /**
182    * Get the proxy settings property.
183    */

184   static public JProxySettings getProxySettings() {
185     
186     return proxySettings;
187   }
188
189   /**
190    * Returns the resources object.
191    */

192   static public JResources getResources() {
193     
194     return resources;
195   }
196
197   /**
198    * Returns the main window
199    * system object.
200    */

201   static public JMOSWindow getMainWindow() {
202     
203     return parentWindow;
204   }
205
206   /**
207    * Returns the debug console window
208    * system object.
209    */

210   static public JConsoleWindow getConsoleWindow() {
211     
212     return console;
213   }
214
215   /**
216    * Return the PluginEngine interface.
217    */

218   static public org.planetamessenger.plugin.JPluginEngineListener getPluginEngineListener() {
219     
220     return ( org.planetamessenger.plugin.JPluginEngineListener ) parentWindow;
221   }
222   
223   /**
224    * Return the KernelAPI Manager.
225    */

226   static public org.planetamessenger.plugin.JKernelAPIListener getKernelManager() {
227     
228     return kernelManager;
229   }
230   
231   /**
232    * Return the Look And Feel Manager.
233    */

234   
235   static public JLookAndFeelManager getLookAndFeelManager() {
236    
237     return plafManager;
238   }
239   
240   /**
241    * Return the language manager.
242    */

243   static public JLanguageManager getLanguageManager() {
244    
245     return languageManager;
246   }
247   
248   /**
249    * Return the preference manager.
250    */

251   static public JPluginPreferencesManager getPluginPreferencesManager() {
252     
253     return pluginPreferencesManager;
254   }
255   
256   /**
257    * Return the user interface manager.
258    */

259   static public JUserInterfaceManager getUserInterfaceManager() {
260     
261     return userInterfaceManager;
262   }
263 }
264
265 // JSharedObjects Class
266
Popular Tags