KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > configuration > ConfigurationFactory


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * ConfigurationFactory.java
20  *
21  * The configuration factory object. This object is responsible for retrieving
22  * the configuration information.
23  */

24
25 // The package
26
package com.rift.coad.lib.configuration;
27
28 /**
29  * The configuration factory. Responsible for the initial read of the
30  * configuration file.
31  *
32  * @author Brett Chaldecott
33  */

34 public abstract class ConfigurationFactory {
35     
36     // classes private member variables
37
private static ConfigurationFactory singleton = null;
38     
39     /**
40      * Creates a new instance of ConfigurationFactory
41      */

42     public ConfigurationFactory() {
43     }
44     
45     
46     /**
47      * This method will return the singleton reference to the configration class
48      *
49      * @return The reference to the singleton configuration class.
50      */

51     static synchronized public ConfigurationFactory getInstance() throws
52         ConfigurationException{
53         if (singleton != null) {
54             return singleton;
55         }
56         try {
57             // instanciate the singleton
58
singleton = (ConfigurationFactory)Class.forName(
59                     System.getProperty("coad.config")).
60                     newInstance();
61             return singleton;
62         } catch (Exception JavaDoc ex) {
63             throw new ConfigurationException("Failed to load the class [" +
64                     System.getProperty("coad.config") + "] because : " +
65                     ex.getMessage(),ex);
66         }
67     }
68     
69     
70     /**
71      * This method returns a reference to the configuration class scoped for the
72      * class reference.
73      *
74      * @return Configuration The reference to the configuration class.
75      * @param classRef The reference to the class that the configuration will be
76      * retrieve for
77      * @exception ConfigurationException
78      */

79     public abstract Configuration getConfig(Class JavaDoc classRef)
80         throws ConfigurationException;
81     
82 }
83
Popular Tags