KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > config > property > PropertyKernelConfig


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.config.property;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Properties JavaDoc;
26 import java.util.TreeSet JavaDoc;
27
28 import org.jboss.beans.info.spi.BeanInfo;
29 import org.jboss.beans.metadata.spi.BeanMetaData;
30 import org.jboss.config.plugins.property.PropertyConfiguration;
31 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
32 import org.jboss.kernel.plugins.config.AbstractKernelConfig;
33 import org.jboss.kernel.plugins.config.Configurator;
34 import org.jboss.kernel.spi.bootstrap.KernelInitializer;
35 import org.jboss.kernel.spi.config.KernelConfigurator;
36 import org.jboss.kernel.spi.dependency.KernelController;
37 import org.jboss.kernel.spi.event.KernelEventManager;
38 import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
39 import org.jboss.kernel.spi.registry.KernelBus;
40 import org.jboss.kernel.spi.registry.KernelRegistry;
41
42 /**
43  * Kernel configuration using properties.
44  *
45  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
46  * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a>
47  * @version $Revision: 57133 $
48  */

49 public class PropertyKernelConfig extends AbstractKernelConfig
50 {
51    /**
52     * Create a configuration
53     *
54     * @param properties the properties
55     */

56    public PropertyKernelConfig(Properties JavaDoc properties)
57    {
58       super(new PropertyConfiguration(properties));
59       initializeProperties();
60    }
61
62    protected Properties JavaDoc getProperties()
63    {
64       PropertyConfiguration config = (PropertyConfiguration) configuration;
65       return config.getProperties();
66    }
67    
68    protected void initializeProperties()
69    {
70       Properties JavaDoc properties = getProperties();
71       
72       if (properties.isEmpty() == false && log.isTraceEnabled())
73       {
74          log.trace("Dumping properties");
75          TreeSet JavaDoc<Object JavaDoc> names = new TreeSet JavaDoc<Object JavaDoc>(properties.keySet());
76          for (Iterator JavaDoc i = names.iterator(); i.hasNext();)
77          {
78             String JavaDoc name = (String JavaDoc) i.next();
79             log.trace(name + "=" + properties.get(name));
80          }
81       }
82    }
83    
84    public KernelBus createKernelBus() throws Throwable JavaDoc
85    {
86       return (KernelBus) getImplementation(
87          KernelConstants.KERNEL_BUS_PROPERTY,
88          KernelConstants.KERNEL_BUS_CLASS
89       );
90    }
91    
92    public KernelConfigurator createKernelConfigurator() throws Throwable JavaDoc
93    {
94       return (KernelConfigurator) getImplementation(
95          KernelConstants.KERNEL_CONFIGURATOR_PROPERTY,
96          KernelConstants.KERNEL_CONFIGURATOR_CLASS
97       );
98    }
99    
100    public KernelController createKernelController() throws Throwable JavaDoc
101    {
102       return (KernelController) getImplementation(
103          KernelConstants.KERNEL_CONTROLLER_PROPERTY,
104          KernelConstants.KERNEL_CONTROLLER_CLASS
105       );
106    }
107    
108    public KernelEventManager createKernelEventManager() throws Throwable JavaDoc
109    {
110       return (KernelEventManager) getImplementation(
111          KernelConstants.KERNEL_EVENT_MANAGER_PROPERTY,
112          KernelConstants.KERNEL_EVENT_MANAGER_CLASS
113       );
114    }
115    
116    public KernelInitializer createKernelInitializer() throws Throwable JavaDoc
117    {
118       return (KernelInitializer) getImplementation(
119          KernelConstants.KERNEL_INITIALIZER_PROPERTY,
120          KernelConstants.KERNEL_INITIALIZER_CLASS
121       );
122    }
123    
124    public KernelRegistry createKernelRegistry() throws Throwable JavaDoc
125    {
126       return (KernelRegistry) getImplementation(
127          KernelConstants.KERNEL_REGISTRY_PROPERTY,
128          KernelConstants.KERNEL_REGISTRY_CLASS
129       );
130    }
131    
132    public KernelMetaDataRepository createKernelMetaDataRepository() throws Throwable JavaDoc
133    {
134       return (KernelMetaDataRepository) getImplementation(
135          KernelConstants.KERNEL_METADATA_REPOSITORY_PROPERTY,
136          KernelConstants.KERNEL_METADATA_REPOSITORY_CLASS
137       );
138    }
139
140    /**
141     * Get the implementation for a type
142     *
143     * @param type the type
144     * @param defaultType the default implementation
145     * @return the implementation object
146     * @throws Throwable for any error
147     */

148    protected Object JavaDoc getImplementation(String JavaDoc type, String JavaDoc defaultType) throws Throwable JavaDoc
149    {
150       Properties JavaDoc properties = getProperties();
151
152       String JavaDoc className = properties.getProperty(type, defaultType);
153       if (log.isTraceEnabled())
154          log.trace(type + " using implementation " + className);
155
156       ClassLoader JavaDoc cl = Configurator.getClassLoader((BeanMetaData) null);
157       BeanInfo info = getBeanInfo(className, cl);
158       BeanMetaData metaData = getBeanMetaData(info, className);
159       return Configurator.instantiateAndConfigure(this, info, metaData);
160    }
161    
162    /**
163     * Get the bean metadata for the class
164     *
165     * @param info the bean info
166     * @param className the class
167     * @return the metadata
168     * @throws Exception for any error
169     */

170    protected BeanMetaData getBeanMetaData(BeanInfo info, String JavaDoc className) throws Exception JavaDoc
171    {
172       return null;
173    }
174 }
175
Popular Tags