KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > bootstrap > basic > BasicKernelInitializer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.kernel.plugins.bootstrap.basic;
23
24 import org.jboss.kernel.Kernel;
25 import org.jboss.kernel.plugins.bootstrap.AbstractKernelInitializer;
26 import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
27 import org.jboss.kernel.spi.config.KernelConfigurator;
28 import org.jboss.kernel.spi.dependency.KernelController;
29 import org.jboss.kernel.spi.event.KernelEventManager;
30 import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
31 import org.jboss.kernel.spi.registry.KernelBus;
32 import org.jboss.kernel.spi.registry.KernelRegistry;
33 import org.jboss.kernel.spi.registry.KernelRegistryEntry;
34
35 /**
36  * Bootstrap the kernel.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 57133 $
40  */

41 public class BasicKernelInitializer extends AbstractKernelInitializer
42 {
43    /**
44     * Create a new basic kernel factory
45     *
46     * @throws Exception for any error
47     */

48    public BasicKernelInitializer() throws Exception JavaDoc
49    {
50    }
51    
52    public void initKernel(Kernel kernel) throws Throwable JavaDoc
53    {
54       KernelMetaDataRepository metaDataRepository = createKernelMetaDataRepository(kernel);
55       if (trace)
56          log.trace("Using MetaDataRepository: " + metaDataRepository);
57       kernel.setMetaDataRepository(metaDataRepository);
58
59       KernelRegistry registry = createKernelRegistry(kernel);
60       if (trace)
61          log.trace("Using Registry: " + registry);
62       registry.setKernel(kernel);
63       kernel.setRegistry(registry);
64       
65       KernelEventManager eventManager = createKernelEventManager(kernel);
66       if (trace)
67          log.trace("Using EventManager: " + eventManager);
68       eventManager.setKernel(kernel);
69       kernel.setEventManager(eventManager);
70       
71       KernelBus bus = createKernelBus(kernel);
72       if (trace)
73          log.trace("Using Bus: " + bus);
74       bus.setKernel(kernel);
75       kernel.setBus(bus);
76       
77       KernelConfigurator configurator = createKernelConfigurator(kernel);
78       if (trace)
79          log.trace("Using Configurator: " + configurator);
80       configurator.setKernel(kernel);
81       kernel.setConfigurator(configurator);
82       
83       KernelController controller = createKernelController(kernel);
84       if (trace)
85          log.trace("Using Controller: " + controller);
86       controller.setKernel(kernel);
87       kernel.setController(controller);
88       
89       // Register everything
90
register(kernel, KernelConstants.KERNEL_CONFIG_NAME, kernel.getConfig());
91       register(kernel, KernelConstants.KERNEL_INITIALIZER_NAME, this);
92       register(kernel, KernelConstants.KERNEL_NAME, kernel);
93       register(kernel, KernelConstants.KERNEL_REGISTRY_NAME, registry);
94       register(kernel, KernelConstants.KERNEL_EVENT_MANAGER_NAME, eventManager);
95       register(kernel, KernelConstants.KERNEL_BUS_NAME, bus);
96       register(kernel, KernelConstants.KERNEL_CONFIGURATOR_NAME, configurator);
97       register(kernel, KernelConstants.KERNEL_CONTROLLER_NAME, controller);
98       register(kernel, KernelConstants.KERNEL_METADATA_REPOSITORY_NAME, metaDataRepository);
99    }
100    
101    /**
102     * Create the kernel bus
103     *
104     * @param kernel the kernel
105     * @return the kernel bus
106     * @throws Throwable for any error
107     */

108    protected KernelBus createKernelBus(Kernel kernel) throws Throwable JavaDoc
109    {
110       return kernel.getConfig().createKernelBus();
111    }
112    
113    /**
114     * Create the configurator
115     *
116     * @param kernel the kernel
117     * @return the configurator
118     * @throws Throwable for any error
119     */

120    protected KernelConfigurator createKernelConfigurator(Kernel kernel) throws Throwable JavaDoc
121    {
122       return kernel.getConfig().createKernelConfigurator();
123    }
124    
125    /**
126     * Create the kernel controller
127     *
128     * @param kernel the kernel
129     * @return the kernel controller
130     * @throws Throwable for any error
131     */

132    protected KernelController createKernelController(Kernel kernel) throws Throwable JavaDoc
133    {
134       return kernel.getConfig().createKernelController();
135    }
136    
137    /**
138     * Create the kernel event manager
139     *
140     * @param kernel the kernel
141     * @return the kernel event manager
142     * @throws Throwable for any error
143     */

144    protected KernelEventManager createKernelEventManager(Kernel kernel) throws Throwable JavaDoc
145    {
146       return kernel.getConfig().createKernelEventManager();
147    }
148    
149    /**
150     * Create the kernel registry
151     *
152     * @param kernel the kernel
153     * @return the kernel registry
154     * @throws Throwable for any error
155     */

156    protected KernelRegistry createKernelRegistry(Kernel kernel) throws Throwable JavaDoc
157    {
158       return kernel.getConfig().createKernelRegistry();
159    }
160    
161    /**
162     * Create the meta data repository
163     *
164     * @param kernel the kernel
165     * @return the meta data repository
166     * @throws Throwable for any error
167     */

168    protected KernelMetaDataRepository createKernelMetaDataRepository(Kernel kernel) throws Throwable JavaDoc
169    {
170       return kernel.getConfig().createKernelMetaDataRepository();
171    }
172
173    /**
174     * Register an object
175     *
176     * @param kernel the kernel
177     * @param name the name
178     * @param object the object
179     * @throws Throwable for any error
180     */

181    protected void register(Kernel kernel, String JavaDoc name, Object JavaDoc object) throws Throwable JavaDoc
182    {
183       register(kernel, getName(name), object);
184    }
185
186    /**
187     * Register an object
188     *
189     * @param kernel the kernel
190     * @param name the name
191     * @param object the object
192     * @throws Throwable for any error
193     */

194    protected void register(Kernel kernel, Object JavaDoc name, Object JavaDoc object) throws Throwable JavaDoc
195    {
196       KernelRegistryEntry entry = createKernelRegistryEntry(kernel, object);
197       KernelRegistry registry = kernel.getRegistry();
198       registry.registerEntry(name, entry);
199    }
200    
201    /**
202     * Get the registration name
203     *
204     * @param name the name
205     * @return the registration name
206     * @throws Throwable for any error
207     */

208    protected Object JavaDoc getName(String JavaDoc name) throws Throwable JavaDoc
209    {
210       return name;
211    }
212
213    /**
214     * Create a kernel registry entry
215     *
216     * @param kernel the kernel
217     * @param object the object
218     * @return the entry
219     * @throws Throwable for any error
220     */

221    protected KernelRegistryEntry createKernelRegistryEntry(Kernel kernel, Object JavaDoc object) throws Throwable JavaDoc
222    {
223       // @TODO add beaninfo to registry entry?
224
// KernelConfig config = kernel.getConfig();
225
// BeanInfoFactory factory = config.getDefaultBeanInfoFactory();
226
// BeanInfo info = factory.getBeanInfo(object.getClass());
227
return new AbstractKernelRegistryEntry(object);
228    }
229 }
230
Popular Tags