1 22 package org.jboss.kernel.plugins.config.property; 23 24 import java.util.Iterator ; 25 import java.util.Properties ; 26 import java.util.TreeSet ; 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 49 public class PropertyKernelConfig extends AbstractKernelConfig 50 { 51 56 public PropertyKernelConfig(Properties properties) 57 { 58 super(new PropertyConfiguration(properties)); 59 initializeProperties(); 60 } 61 62 protected Properties getProperties() 63 { 64 PropertyConfiguration config = (PropertyConfiguration) configuration; 65 return config.getProperties(); 66 } 67 68 protected void initializeProperties() 69 { 70 Properties properties = getProperties(); 71 72 if (properties.isEmpty() == false && log.isTraceEnabled()) 73 { 74 log.trace("Dumping properties"); 75 TreeSet <Object > names = new TreeSet <Object >(properties.keySet()); 76 for (Iterator i = names.iterator(); i.hasNext();) 77 { 78 String name = (String ) i.next(); 79 log.trace(name + "=" + properties.get(name)); 80 } 81 } 82 } 83 84 public KernelBus createKernelBus() throws Throwable 85 { 86 return (KernelBus) getImplementation( 87 KernelConstants.KERNEL_BUS_PROPERTY, 88 KernelConstants.KERNEL_BUS_CLASS 89 ); 90 } 91 92 public KernelConfigurator createKernelConfigurator() throws Throwable 93 { 94 return (KernelConfigurator) getImplementation( 95 KernelConstants.KERNEL_CONFIGURATOR_PROPERTY, 96 KernelConstants.KERNEL_CONFIGURATOR_CLASS 97 ); 98 } 99 100 public KernelController createKernelController() throws Throwable 101 { 102 return (KernelController) getImplementation( 103 KernelConstants.KERNEL_CONTROLLER_PROPERTY, 104 KernelConstants.KERNEL_CONTROLLER_CLASS 105 ); 106 } 107 108 public KernelEventManager createKernelEventManager() throws Throwable 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 117 { 118 return (KernelInitializer) getImplementation( 119 KernelConstants.KERNEL_INITIALIZER_PROPERTY, 120 KernelConstants.KERNEL_INITIALIZER_CLASS 121 ); 122 } 123 124 public KernelRegistry createKernelRegistry() throws Throwable 125 { 126 return (KernelRegistry) getImplementation( 127 KernelConstants.KERNEL_REGISTRY_PROPERTY, 128 KernelConstants.KERNEL_REGISTRY_CLASS 129 ); 130 } 131 132 public KernelMetaDataRepository createKernelMetaDataRepository() throws Throwable 133 { 134 return (KernelMetaDataRepository) getImplementation( 135 KernelConstants.KERNEL_METADATA_REPOSITORY_PROPERTY, 136 KernelConstants.KERNEL_METADATA_REPOSITORY_CLASS 137 ); 138 } 139 140 148 protected Object getImplementation(String type, String defaultType) throws Throwable 149 { 150 Properties properties = getProperties(); 151 152 String className = properties.getProperty(type, defaultType); 153 if (log.isTraceEnabled()) 154 log.trace(type + " using implementation " + className); 155 156 ClassLoader 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 170 protected BeanMetaData getBeanMetaData(BeanInfo info, String className) throws Exception 171 { 172 return null; 173 } 174 } 175 | Popular Tags |