KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > DODS


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19
20 /*
21  *
22  * @author Nenad Vico
23  * @author Tanja Jovanovic
24  * @version 1.0.0 2003/03/16
25  *
26  */

27 package org.enhydra.dods;
28
29 import java.io.File JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.lang.reflect.Constructor JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Set JavaDoc;
38
39 import javax.naming.Context JavaDoc;
40 import javax.naming.InitialContext JavaDoc;
41
42 import com.lutris.appserver.server.sql.DatabaseManager;
43 import com.lutris.appserver.server.sql.DatabaseManagerException;
44 import com.lutris.appserver.server.sql.StandardDatabaseManager;
45 import com.lutris.logging.LogChannel;
46 import com.lutris.logging.Logger;
47 import com.lutris.logging.StandardLogger;
48 import com.lutris.util.Config;
49 import com.lutris.util.ConfigException;
50 import com.lutris.util.ConfigFile;
51
52 /**
53  * Main DODS class.
54  *
55  * There are two modes of usage: non-threading and threading.
56  * In non-threading mode, only one DatabaseManager is used for the whole
57  * application, no matter the application has one or more Threads.
58  * In threading mode, there is one DatabaseManager for every Thread.
59  * User needs, for every Thread, to define the DatabaseManager.
60  * If, for any Thread, the DatabaseManager is not defined,
61  * the default DatabaseManager is used.
62  *
63  * <p>
64  * Example for non-threading mode:
65  * <blockquote><pre>
66  * ...
67  * try {
68  String fileName = "discRack.conf";
69  * DatabaseManager dbManager = StandardDatabaseManager.newInstance(fileName);
70  * DODS.register(dbManager);
71  * } catch (Exception e) {
72  * e.printStackTrace();
73  * }
74  * ...
75  * </pre></blockquote>
76  */

77 public class DODS {
78
79     
80     /**
81      *
82      * This attribute is used for storing <code>DatabaseManager</code>s, if
83      * threading mode is used.
84      * Every <code>Thread</code> has precisely one <code>DatabaseManager</code>.
85      * If <code>Thread</code> doesn't have <code>DatabaseManager</code>, it uses
86      * <code>defaultDatabaseManager</code>.
87      */

88     private static HashMap JavaDoc databaseManagers;
89
90     /**
91      * This attribute is used for storing default <code>DatabaseManager</code>.
92      * In non-treading mode, there is only one <code>DatabaseManager</code>, and
93      * this <code>DatabaseManager</code> is set as <code>defaultDatabaseManager</code>.
94      */

95     private static DatabaseManager defaultDatabaseManager;
96
97     /**
98      * This attribute is used for storing <code>LogChannel</code>s, if
99      * threading mode is used.
100      * Every <code>Thread</code> has precisely one <code>LogChannel</code>.
101      * If <code>Thread</code> doesn't have <code>LogChannel</code>, it uses
102      * <code>defaultLogger</code>.
103      */

104     private static HashMap JavaDoc logChannels;
105
106     /**
107      * This attribute is used for storing default <code>LogChannel</code>.
108      * <code>defaultLogger</code> is initialized with the root <code>LogChannel</code>.
109      * It is assumed that user sets root <code>LogChannel</code> in log4j configuration.
110      * Otherwise, logging is set to OFF.
111      */

112     private static LogChannel defaultLogChannel;
113      
114     /**
115      * Mode of usage. If this flag is <code>true</code>, DODS uses multi
116      * threading mode. This means that DODS handles multiple threads, like
117      * Enhydra application server (each application in one <code>Thread</code>).
118      * If this flag is <code>false</code>, there can be more then one <code>Thread</code>,
119      * but there is only one <code>DatabaseManager</code> for all <code>Thread</code>s
120      * (for the whole application).
121      */

122     private static boolean threading;
123     
124     private static boolean dodsConfigured;
125     
126     
127     static {
128         init();
129     }
130
131     /**
132      * Sets the default DatabaseManager.
133      *
134      * @param databaseManager the DatabaseManager to be set as default.
135      */

136     public static void registerDefault(DatabaseManager databaseManager) {
137         defaultDatabaseManager = databaseManager;
138         setDodsConfigured(true);
139     }
140
141     /**
142      * Sets the default DatabaseManager.
143      *
144      * @param fileName full path name of the application configuration file.
145      */

146     public static void registerDefault(String JavaDoc fileName)
147         throws ConfigException, DatabaseManagerException, SQLException JavaDoc {
148         defaultDatabaseManager = StandardDatabaseManager.newInstance(fileName);
149         setDodsConfigured(true);
150     }
151
152     /**
153      * In threading mode, this method associates the DatabaseManager object
154      * with the current thread.
155      * If default DatabaseManager is <code>null</code>, it will also be set.
156      * In non-threading mode, only default DatabaseManager will be set.
157      *
158      * @param databaseManager the DatabaseManager to associate
159      * with current thread.
160      */

161     public static void register(DatabaseManager databaseManager) {
162         if (threading) {
163             databaseManagers.put(Thread.currentThread(), databaseManager);
164             if (defaultDatabaseManager == null) {
165                 defaultDatabaseManager = databaseManager;
166             }
167             setDodsConfigured(true);
168             return;
169         }
170         defaultDatabaseManager = databaseManager;
171         setDodsConfigured(true);
172     }
173
174     /**
175      * In threading mode, this method associates the DatabaseManager object
176      * with the current thread.
177      * If default DatabaseManager is <code>null</code>, it will also be set.
178      * In non-threading mode, only default DatabaseManager will be set.
179      *
180      * @param fileName full path name of the application configuration file
181      * which will create <code>DatabaseManager</code>associate with current thread.
182      */

183     public static void startup(String JavaDoc fileName)
184         throws ConfigException, DatabaseManagerException, SQLException JavaDoc {
185             
186         LogChannel channel = null;
187         try {
188             channel = getLogChannel(fileName);
189         } catch (Exception JavaDoc ex) {
190             throw new ConfigException("Unable to invoke Logging Class defined in : "
191                     + fileName);
192         }
193         defaultLogChannel = channel;
194         
195         DatabaseManager databaseManager = StandardDatabaseManager.newInstance(fileName);
196
197         if (threading) {
198             databaseManagers.put(Thread.currentThread(), databaseManager);
199             logChannels.put(Thread.currentThread(), channel);
200             if (defaultDatabaseManager == null) {
201                 defaultDatabaseManager = databaseManager;
202             }
203             defaultLogChannel = channel;
204             setDodsConfigured(true);
205             return;
206         }
207         defaultDatabaseManager = databaseManager;
208         ((StandardDatabaseManager)databaseManager).initChaches(databaseManager.getClass().getClassLoader());
209         setDodsConfigured(true);
210     }
211
212
213     /**
214      * In threading mode, this method associates the DatabaseManager object
215      * with the current thread.
216      * If default DatabaseManager is <code>null</code>, it will also be set.
217      * In non-threading mode, only default DatabaseManager will be set.
218      *
219      * @param confURL Additional path to folder or *.jar file with configuration file. If null use DODS classpath.
220      * @param confFile Name of conf file relativ to *.jar file or to specifide folder (from confURL/DODS claspath).
221      */

222     public static void startup(URL JavaDoc confURL, String JavaDoc confFile)
223         throws ConfigException, DatabaseManagerException, SQLException JavaDoc {
224             
225         LogChannel channel = null;
226         try {
227             channel = getLogChannel(confURL, confFile);
228         } catch (Exception JavaDoc ex) {
229             throw new ConfigException("Unable to invoke Logging Class defined in : "
230                     + confFile);
231         }
232         defaultLogChannel = channel;
233         
234         DatabaseManager databaseManager = StandardDatabaseManager.newInstance(confURL, confFile);
235         if (threading) {
236             databaseManagers.put(Thread.currentThread(), databaseManager);
237             logChannels.put(Thread.currentThread(), channel);
238             if (defaultDatabaseManager == null) {
239                 defaultDatabaseManager = databaseManager;
240             }
241             defaultLogChannel = channel;
242             setDodsConfigured(true);
243             return;
244         }
245         defaultDatabaseManager = databaseManager;
246         ((StandardDatabaseManager)databaseManager).initChaches(databaseManager.getClass().getClassLoader());
247         setDodsConfigured(true);
248     }
249
250
251
252     /**
253      * Associates DatabaseManager created by the given fileName with given thread.
254      * If default DatabaseManager is null, the default DatabaseManager
255      * will also be set.
256      *
257      * @param thread the thread to associate with <code>DatabaseManager</code>.
258      * @param fileName full path name of the application configuration file
259      * which will create <code>DatabaseManager</code>associate with given thread.
260      */

261     public static void startup(Thread JavaDoc thread, String JavaDoc fileName)
262         throws ConfigException, DatabaseManagerException, SQLException JavaDoc {
263         LogChannel channel=null;
264         try {
265             channel = getLogChannel(fileName);
266         } catch (Exception JavaDoc ex) {
267             throw new ConfigException("Unable to invoke Logging Class defined in : "
268                     + fileName);
269         }
270         logChannels.put(Thread.currentThread(), channel);
271         
272         DatabaseManager databaseManager = StandardDatabaseManager.newInstance(fileName);
273         databaseManagers.put(thread, databaseManager);
274         if (defaultDatabaseManager == null) {
275             defaultLogChannel = channel;
276             defaultDatabaseManager = databaseManager;
277         }
278         ((StandardDatabaseManager)databaseManager).initChaches(databaseManager.getClass().getClassLoader());
279         setDodsConfigured(true);
280     }
281
282
283     private static LogChannel getLogChannel(String JavaDoc cf) throws Exception JavaDoc {
284         try {
285             FileInputStream JavaDoc configFIS = new FileInputStream JavaDoc(cf);
286             ConfigFile cFile = new ConfigFile(configFIS);
287             Config config = cFile.getConfig();
288             configFIS.close();
289             Config logSection = (Config) config.getSection("DatabaseManager");
290             String JavaDoc logClassName = logSection.getString("LogClassName","com.lutris.logging.StandardLogger");
291                 
292             Class JavaDoc loggerClass;
293             Class JavaDoc[] argTypeArr = {Boolean.TYPE};
294             Object JavaDoc[] argArr = {new Boolean JavaDoc(false)};
295
296             loggerClass = Class.forName(logClassName);
297             Constructor JavaDoc logConstructor = loggerClass.getConstructor(argTypeArr);
298             Logger logger = (Logger) (logConstructor.newInstance(argArr));
299
300             logger.configure(logSection);
301             return logger.getChannel("DatabaseManager");
302         } catch (Throwable JavaDoc t) {}
303         return getLogChannel(null ,cf);
304     }
305
306
307     private static LogChannel getLogChannel(URL JavaDoc confURL, String JavaDoc confFile) throws ConfigException {
308         try {
309             InputStream JavaDoc configIS = Common.getConfFileFromURL(confURL, confFile);
310             ConfigFile configFile = new ConfigFile(configIS);
311             Config config = configFile.getConfig();
312             configIS.close();
313             Config logSection = (Config) config.getSection("DatabaseManager");
314     
315             String JavaDoc logClassName = logSection.getString("LogClassName","com.lutris.logging.StandardLogger");
316                 
317             Class JavaDoc loggerClass;
318             Class JavaDoc[] argTypeArr = {Boolean.TYPE};
319             Object JavaDoc[] argArr = {new Boolean JavaDoc(false)};
320     
321             loggerClass = Class.forName(logClassName);
322             Constructor JavaDoc logConstructor = loggerClass.getConstructor(argTypeArr);
323             Logger logger = (Logger) (logConstructor.newInstance(argArr));
324     
325             logger.configure(logSection);
326             return logger.getChannel("DatabaseManager");
327         } catch (Throwable JavaDoc t) {}
328         return configureStandardLogerChannel();
329     }
330
331
332     public static LogChannel configureStandardLogerChannel()
333         throws ConfigException {
334         LogChannel channel = null;
335
336         try {
337             File JavaDoc logFile = new File JavaDoc("DatabaseManager.log");
338             StandardLogger logger = new StandardLogger(false);
339             String JavaDoc[] fileLogLevels = {"EMERGENCY", "ALERT", "CRITICAL", "ERROR",
340                 "WARNING", "NOTICE", "INFO"
341             };
342             String JavaDoc[] stdErrLogLevels = {"EMERGENCY", "ALERT", "CRITICAL",
343                 "ERROR", "WARNING", "NOTICE", "INFO"
344             };
345
346             logger.configure(logFile, fileLogLevels, stdErrLogLevels);
347             return logger.getChannel("databaseManager");
348         } catch (Exception JavaDoc ex) {
349             throw new ConfigException("Unable to invoke standard logger.");
350         }
351     }
352
353     /**
354      * Associates the given DatabaseManager object with given thread.
355      * If default DatabaseManager is null, the default DatabaseManager
356      * will also be set.
357      *
358      * @param thread the thread to associate with <code>DatabaseManager</code>.
359      * @param databaseManager the DatabaseManager to associate the <code>Thread</code>.
360      */

361     public static void register(Thread JavaDoc thread, DatabaseManager databaseManager) {
362         databaseManagers.put(thread, databaseManager);
363         if (defaultDatabaseManager == null) {
364             defaultDatabaseManager = databaseManager;
365         }
366         setDodsConfigured(true);
367     }
368
369     /**
370      * Sets the default logChannel.
371      *
372      * @param channel LogChannel that will be set as default LogChannel.
373      */

374     public static void registerDefaultLogChannel(LogChannel channel) {
375         defaultLogChannel = channel;
376     }
377
378     /**
379      * In threading mode, this method associates the <code>channel</code> object with
380      * the current thread.
381      * In non-threading mode, only default <code>channel</code> will be set.
382      *
383      * @param channel LogChannel that will be set.
384      */

385     public static void registerLogChannel(LogChannel channel) {
386         if (threading) {
387             logChannels.put(Thread.currentThread(), channel);
388         }
389         if (defaultLogChannel==null){
390                defaultLogChannel = channel;
391         }
392     }
393
394     /**
395      * Associates the given <code>channel</code> object with the given thread.
396      *
397      * @param thread the thread to associate with <code>channel</code>.
398      * @param channel the <code>channel</code> to associate the <code>Thread</code>.
399      */

400     public static void registerLogChannel(Thread JavaDoc thread, LogChannel channel) {
401         logChannels.put(thread, channel);
402           if (defaultLogChannel==null){
403                defaultLogChannel = channel;
404           }
405     }
406
407     /**
408      * Unregisters default <code>DatabaseManager</code>.
409      * Call this method to release default <code>DatabaseManager</code>.
410      *
411      * @return unregistered default <code>DatabaseManager</code>.
412      *
413      * @exception DODSException
414      * If an error occurs in unregistering the DatabaseManager.
415      */

416     public static DatabaseManager unregisterDefault()
417         throws DODSException {
418         try {
419             DatabaseManager dbManager = defaultDatabaseManager;
420
421             defaultDatabaseManager = null;
422             return dbManager;
423         } catch (Exception JavaDoc e) {
424             throw new DODSException(e);
425         }
426     }
427
428     /**
429      * In threading mode, this method unregisters <code>DatabaseManager</code>
430      * associated with the current thread.
431      * In non-threading mode, only default <code>DatabaseManager</code>
432      * will be unregistered.
433      * Call this method to release <code>DatabaseManager</code>.
434      *
435      * @return unregistered <code>DatabaseManager</code>.
436      *
437      * @exception DODSException
438      * If an error occurs in unregistering the DatabaseManager.
439      */

440     public static DatabaseManager unregister()
441         throws DODSException {
442         try {
443             DatabaseManager dbManager;
444
445             if (threading) {
446                 return (DatabaseManager) databaseManagers.remove(Thread.currentThread());
447             }
448             dbManager = defaultDatabaseManager;
449             defaultDatabaseManager = null;
450             return dbManager;
451         } catch (Exception JavaDoc e) {
452             throw new DODSException(e);
453         }
454     }
455
456     /**
457      * Unregisters <code>DatabaseManager</code> associated with the given thread.
458      * Call this method to release <code>DatabaseManager</code>.
459      *
460      * @return unregistered <code>DatabaseManager</code>.
461      *
462      * @exception DODSException
463      * If an error occurs in unregistering the DatabaseManager.
464      */

465     public static DatabaseManager unregister(Thread JavaDoc thread)
466         throws DODSException {
467         try {
468             return (DatabaseManager) databaseManagers.remove(thread);
469         } catch (Exception JavaDoc e) {
470             throw new DODSException(e);
471         }
472     }
473
474     /**
475      * Unregisters default<code>Logger</code>.
476      * Call this method to release default <code>Logger</code>.
477      *
478      * @return unregistered default <code>Logger</code>.
479      *
480      * @exception DODSException
481      * If an error occurs in unregistering the logger.
482      */

483     public static LogChannel unregisterDefaultLogChannel()
484         throws DODSException {
485         try {
486             LogChannel channel = defaultLogChannel;
487                 defaultLogChannel = null;
488             return channel;
489         } catch (Exception JavaDoc e) {
490             throw new DODSException(e);
491         }
492     }
493
494     /**
495      * In threading mode, this method unregisters <code>LogChannel</code>
496      * associated with the current thread.
497      * In non-threading mode, only default <code>LogChannel</code>
498      * will be unregistered.
499      * Call this method to release <code>LogChannel</code>.
500      *
501      * @return unregistered <code>LogChannel</code>.
502      *
503      * @exception DODSException
504      * If an error occurs in unregistering the LogChannel.
505      */

506     public static LogChannel unregisterLogChannel()
507         throws DODSException {
508         try {
509             if (threading) {
510                 return (LogChannel) logChannels.remove(Thread.currentThread());
511             }else{
512                     return unregisterDefaultLogChannel();
513             }
514         } catch (Exception JavaDoc e) {
515             throw new DODSException(e);
516         }
517     }
518
519     /**
520      * Unregisters <code>LogChannel</code> associated with the given thread.
521      * Call this method to release <code>LogChannel</code>.
522      *
523      * @return unregistered <code>LogChannel</code>.
524      *
525      * @exception DODSException
526      * If an error occurs in unregistering the LogChannel.
527      */

528     public static LogChannel unregisterLogChannel(Thread JavaDoc thread)
529         throws DODSException {
530         try {
531             return (LogChannel) logChannels.remove(thread);
532         } catch (Exception JavaDoc e) {
533             throw new DODSException(e);
534         }
535     }
536
537     /**
538      * Returns the default DatabaseManager.
539      *
540      * @return the default DatabaseManager.
541      */

542     public static DatabaseManager getDefaultDatabaseManager() {
543         checkDodsConfiguration();
544         return defaultDatabaseManager;
545     }
546
547     /**
548      * Returns the DatabaseManager object for the current thread.
549      * Returns default DatabaseManager if there is no database
550      * manager associated with the current thread. Returns null
551      * if default DatabaseManager is not set.
552      * If non-threading mode is used, default <code>DatabaseManager</code>
553      * will be returned.
554      *
555      * @return the DatabaseManager object, if available, otherwise null.
556      */

557     public static DatabaseManager getDatabaseManager() {
558         checkDodsConfiguration();
559         if (threading) {
560             DatabaseManager dbManager = (DatabaseManager) databaseManagers.get(Thread.currentThread());
561
562             if (dbManager != null) {
563                 return dbManager;
564             }
565         }
566         return defaultDatabaseManager;
567     }
568
569     /**
570      * Returns the DatabaseManager object for the given thread.
571      * Returns default DatabaseManager if there is no database
572      * manager associated with the thread. Returns null if default
573      * DatabaseManager is not set.
574      *
575      * @param thread the thread to associate with the <code>DatabaseManager</code>.
576      *
577      * @return the DatabaseManager object, if available, otherwise null.
578      */

579     public static DatabaseManager getDatabaseManager(Thread JavaDoc thread) {
580         checkDodsConfiguration();
581         DatabaseManager dbManager = (DatabaseManager) databaseManagers.get(thread);
582
583         if (dbManager != null) {
584             return dbManager;
585         }
586         return defaultDatabaseManager;
587     }
588
589     /**
590      * Returns the default logger.
591      *
592      * @return The default logger.
593      */

594     public static LogChannel getDefaultLogChannel() {
595       try{
596         if (defaultLogChannel==null){
597             defaultLogChannel=configureStandardLogerChannel();
598          }
599       } catch (ConfigException ex) {}
600         return defaultLogChannel;
601     }
602
603     /**
604      * Returns the logger object for the current thread.
605      * Returns default logger if there is no logger associated with the current
606      * thread. Returns null if default logger is not set.
607      * If non-threading mode is used, default <code>Logger</code> will be returned.
608      *
609      * @return the logger object, if available, otherwise null.
610      */

611     public static LogChannel getLogChannel() {
612         if (threading) {
613             LogChannel channel = (LogChannel) logChannels.get(Thread.currentThread());
614
615             if (channel != null) {
616                 return channel;
617             }
618         }
619         return getDefaultLogChannel();
620     }
621
622     /**
623      * Returns the logger object for the given thread.
624      * Returns default logger if there is no logger associated with the thread.
625      * Returns null if default logger is not set.
626      *
627      * @param thread the thread to associate with the logger.
628      *
629      * @return the logger object, if available, otherwise null.
630      */

631     public static LogChannel getLogChannel(Thread JavaDoc thread) {
632         LogChannel channel = (LogChannel) logChannels.get(thread);
633
634         if (channel != null) {
635             return channel;
636         }
637         return defaultLogChannel;
638     }
639
640     /**
641      * Shutdowns all <code>DatabaseManager</code>s and <code>Loggers</code>s.
642      * Call this method to release and shutdown all <code>DatabaseManager</code>s
643      * and <code>Loggers</code>s.
644      *
645      * @exception DODSException
646      * If an error occurs in releasing DatabaseManagers and loggers.
647      */

648     public static void shutdown()
649         throws DODSException {
650         try {
651             if (threading) {
652                 Set JavaDoc keys = databaseManagers.keySet();
653
654                 for (Iterator JavaDoc iter = keys.iterator(); iter.hasNext();) {
655                     Thread JavaDoc key = (Thread JavaDoc) iter.next();
656                     DatabaseManager dbManager = (DatabaseManager) databaseManagers.remove(key);
657
658                     if (dbManager != null) {
659                         dbManager.shutdown();
660                         dbManager = null;
661                     }
662                 }
663                 keys = logChannels.keySet();
664                 for (Iterator JavaDoc iter = keys.iterator(); iter.hasNext();) {
665                     Thread JavaDoc key = (Thread JavaDoc) iter.next();
666
667                     logChannels.remove(key);
668                 }
669             }
670             if (defaultDatabaseManager != null) {
671                 defaultDatabaseManager.shutdown();
672                 defaultDatabaseManager = null;
673             }
674             dodsConfigured = false;
675         } catch (Exception JavaDoc e) {
676             throw new DODSException(e);
677         }
678     }
679
680     /**
681      * Returns the mode of usage. If this flag is <code>true</code>, DODS uses multi
682      * threading mode. This means that DODS handles multiple threads, like
683      * Enhydra application server (each application in one <code>Thread</code>).
684      * If this flag is <code>false</code>, there can be more then one <code>Thread</code>,
685      * but there is only one <code>DatabaseManager</code> for all <code>Thread</code>s
686      * (for the whole application).
687      *
688      * @return <code>true</code> if threading mode is used, otherwise
689      * <code>false</code>.
690      */

691     public static boolean isThreading() {
692         return threading;
693     }
694
695     /**
696      * Sets mode of usage. If this flag is <code>true</code>, DODS uses multi
697      * threading mode. This means that DODS handles multiple threads, like
698      * Enhydra application server (each application in one <code>Thread</code>).
699      * If this flag is <code>false</code>, there can be more then one <code>Thread</code>,
700      * but there is only one <code>DatabaseManager</code> for all <code>Thread</code>s
701      * (for the whole application).
702      *
703      * @param mode mode of usage.
704      *
705      */

706     public static void setThreading(boolean mode) {
707         threading = mode;
708     }
709
710     /**
711      * Initializes DODS.
712      * Sets default logger.
713      *
714      */

715     protected static void init() {
716         dodsConfigured = false;
717         threading = false;
718         databaseManagers = new HashMap JavaDoc();
719         logChannels = new HashMap JavaDoc();
720     }
721
722
723     
724     private static void checkDodsConfiguration() {
725         String JavaDoc confFilePath = null;
726         try {
727             if (!dodsConfigured){
728                 confFilePath = System.getProperty(CommonConstants.DODS_CONFIG_FILE_PROPERTY_NAME);
729                 if (null==confFilePath) {
730                     try {
731                         Context JavaDoc initContext = new InitialContext JavaDoc();
732                         Context JavaDoc envContext = (Context JavaDoc)initContext.lookup(CommonConstants.JNDI_ENV);
733                         confFilePath = (String JavaDoc)envContext.lookup(CommonConstants.DODS_CONFIG_FILE_LOOKUP);
734                     }catch (Exception JavaDoc e) {}
735                 }
736                 if (confFilePath!=null) {
737                     DODS.startup(confFilePath);
738                 }else {
739                     DODS.startup((URL JavaDoc)null,CommonConstants.DEFAULT_CONFIG_FILE_NAME);
740                 }
741             }
742         }catch (Exception JavaDoc e) {
743             dodsConfigured = false;
744         }
745     }
746     
747     
748     /**
749      * @return Returns the dodsConfigured.
750      */

751     protected static boolean isDodsConfigured() {
752         return dodsConfigured;
753     }
754     
755     
756     /**
757      * @param dodsConfigured The dodsConfigured to set.
758      */

759     protected static void setDodsConfigured(boolean configured) {
760         DODS.dodsConfigured = configured;
761     }
762         
763 }
764
Popular Tags