KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > bootstrap > DefaultLoader


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.bootstrap;
19
20 import org.sape.carbon.core.component.ComponentKeeper;
21 import org.sape.carbon.core.component.ComponentKeeperConfiguration;
22 import org.sape.carbon.core.component.ComponentKeeperFactory;
23 import org.sape.carbon.core.config.ConfigurationRuntimeException;
24 import org.sape.carbon.core.config.ConfigurationService;
25 import org.sape.carbon.core.config.ConfigurationServiceFactory;
26 import org.sape.carbon.core.config.DefaultConfigurationServiceFactory;
27 import org.sape.carbon.core.config.InvalidConfigurationException;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33 /**
34  * <p>This is the default loader for the system.</p>
35  *
36  * Copyright 2002 Sapient
37  * @since carbon 1.0
38  * @author Douglas Voet, January 2002
39  * @version $Revision: 1.39 $($Author: ghinkl $ / $Date: 2003/10/16 13:46:24 $)
40  */

41 class DefaultLoader implements Loader {
42     /** The handle to Apache-commons logger */
43     private Log log = LogFactory.getLog(this.getClass());
44
45     /**
46      * <p>
47      * Loads the root <code>ConfigurationService</code> for the system
48      * and returns it.
49      * </p>
50      *
51      * @return a reference to the root <code>ConfigurationService</code>
52      * for the system
53      */

54     public ConfigurationService fetchConfigurationService() {
55
56         if (log.isTraceEnabled()) {
57             log.trace("Loading Carbon Configuration Service");
58         }
59
60         // declared with this scope for use in exceptions
61
Class JavaDoc configurationServiceFactoryClass = null;
62
63         String JavaDoc configurationServiceFactoryClassName =
64             BootStrapper.getInstance().
65             getDeploymentProperty(CONFIG_SERVICE_FACTORY_PROPERTY);
66
67         if (configurationServiceFactoryClassName == null
68             || configurationServiceFactoryClassName.equals("")) {
69
70             configurationServiceFactoryClassName =
71                 DefaultConfigurationServiceFactory.class.getName();
72         }
73
74         if (log.isTraceEnabled()) {
75             log.trace("ConfigurationServiceFactory to be used ["
76                             + configurationServiceFactoryClassName + "]");
77         }
78
79         try {
80             // 1) get the ConfigurationServiceFactory class
81
configurationServiceFactoryClass = Class.forName(
82                 configurationServiceFactoryClassName);
83
84             // 2) instantiate the ConfigurationServiceFactory
85
ConfigurationServiceFactory configurationServiceFactory =
86                 (ConfigurationServiceFactory)
87                 configurationServiceFactoryClass.newInstance();
88
89             // 3) return a ConfigurationService from the
90
// ConfigurationServiceFactory
91
return configurationServiceFactory.getInstance(
92                 new BootConfigurationDocument());
93
94         } catch (ClassNotFoundException JavaDoc cnfe) {
95             throw new BootStrapException(this.getClass(),
96                 "Specified ConfigurationServiceFactory ["
97                 + configurationServiceFactoryClassName
98                 + "] was not found", cnfe);
99         } catch (ClassCastException JavaDoc cce) {
100             throw new BootStrapException(this.getClass(),
101                 "Specified ConfigurationServiceFactory ["
102                 + configurationServiceFactoryClassName
103                 + "] was not of the correct type: ["
104                 + ConfigurationServiceFactory.class.getName() + "]", cce);
105         } catch (InstantiationException JavaDoc ie) {
106             throw new BootStrapException(this.getClass(),
107                 "Could not instantiate ConfigurationServiceFactory: ["
108                 + configurationServiceFactoryClassName + "]", ie);
109         } catch (IllegalAccessException JavaDoc iae) {
110             throw new BootStrapException(this.getClass(),
111                 "Could not instantiate ConfigurationServiceFactory: ["
112                 + configurationServiceFactoryClassName + "]", iae);
113         } catch (InvalidConfigurationException ice) {
114             throw new BootStrapException (this.getClass(),
115                 "Could not load root configuration document due to " +
116                 "a missing system property. The property referenced was " +
117                 "?? and must be defined if the current type of root " +
118                 "deployment is to be used.", ice);
119         }
120     }
121
122     /**
123      * <p>
124      * Loads the <code>ComponentKeeper</code> for the system and returns it.
125      * </p>
126      *
127      * @param configurationService the configuration service to fetch
128      * the keeper from
129      * @return the <code>ComponentKeeper</code> for the system
130      */

131     public ComponentKeeper fetchComponentKeeper(ConfigurationService
132                                                  configurationService) {
133
134         if (log.isTraceEnabled()) {
135             log.trace("Loading Carbon component keeper Service");
136         }
137
138         ComponentKeeperConfiguration keeperConfiguration;
139         try {
140             keeperConfiguration = (ComponentKeeperConfiguration)
141                 configurationService.fetchConfiguration(
142                 DefaultLoader.COMPONENT_KEEPER_CONFIGURATION);
143         } catch (ConfigurationRuntimeException ce) {
144             throw new BootStrapException(this.getClass(),
145                 "Caught ConfigurationException while retrieving "
146                     + "component keeper configuration", ce);
147         }
148
149         Class JavaDoc keeperFactoryClass =
150             keeperConfiguration.getComponentKeeperFactoryClass();
151
152         if (log.isTraceEnabled()) {
153             log.trace("Instantiating ComponentKeeperFactory ["
154                 + keeperFactoryClass.getName() + "]");
155         }
156
157         ComponentKeeperFactory keeperFactory;
158         try {
159             keeperFactory =
160                 (ComponentKeeperFactory) keeperFactoryClass.newInstance();
161         } catch (ClassCastException JavaDoc cce) {
162             throw new BootStrapException(this.getClass(),
163                 "Specified ComponentKeeperFactory ["
164                 + keeperFactoryClass.getName()
165                 + "] was not of the correct type: ["
166                 + ComponentKeeperFactory.class.getName() + "]", cce);
167         } catch (InstantiationException JavaDoc ie) {
168             throw new BootStrapException(this.getClass(),
169                 "Could not instantiate ComponentKeeperFactory: ["
170                 + keeperFactoryClass.getName() + "]", ie);
171         } catch (IllegalAccessException JavaDoc iae) {
172             throw new BootStrapException(this.getClass(),
173                 "Could not instantiate ComponentKeeperFactory: ["
174                 + keeperFactoryClass.getName() + "]", iae);
175         }
176
177         //Now return an instance from the factory
178
return keeperFactory.getInstance(keeperConfiguration);
179     }
180
181     /** Holds the config location of the default component keeper. */
182     public static final String JavaDoc COMPONENT_KEEPER_CONFIGURATION =
183         "/core/ComponentKeeper";
184
185     /**
186      * Holds the deployment property name for the default service factory.
187      */

188     public static final String JavaDoc CONFIG_SERVICE_FACTORY_PROPERTY =
189         "carbon.config.ServiceFactory";
190
191     /** @link dependency */
192     /*#ComponentConfiguration lnkComponentConfiguration;*/
193 }
194
Popular Tags