1 22 23 package org.jboss.spring.kernel; 24 25 import org.jboss.kernel.Kernel; 26 import org.jboss.kernel.spi.dependency.KernelController; 27 import org.jboss.spring.factory.AbstractBeanFactoryLoader; 28 import org.jboss.spring.factory.NamedXmlApplicationContext; 29 import org.springframework.beans.factory.BeanFactory; 30 import org.springframework.context.ApplicationContext; 31 import org.springframework.context.ConfigurableApplicationContext; 32 import org.springframework.core.io.Resource; 33 34 37 public class MicrocontainerLoaderImpl extends AbstractBeanFactoryLoader 38 { 39 40 protected BeanFactory createBeanFactory(String defaultName, Resource resource) 41 { 42 ConfigurableApplicationContext applicationContext = new NamedXmlApplicationContext(defaultName, resource, false); 43 MicrocontainerConfigurer microcontainerPostProcessor = new MicrocontainerConfigurer(); 44 Locator locator = new NullLocator(); 45 KernelController controller = getKernelController(); 46 Kernel kernel = getKernel(); 47 if (controller != null) 48 { 49 locator = new ControllerLocator(controller); 50 } 51 else if (kernel != null) 52 { 53 locator = new KernelLocator(kernel); 54 } 55 microcontainerPostProcessor.setLocator(locator); 56 applicationContext.addBeanFactoryPostProcessor(microcontainerPostProcessor); 57 applicationContext.refresh(); 58 return applicationContext; 59 } 60 61 protected void doClose(BeanFactory beanFactory) 62 { 63 ((ConfigurableApplicationContext) beanFactory).close(); 64 } 65 66 protected Class getExactBeanFactoryClass() 67 { 68 return ApplicationContext.class; 69 } 70 71 protected Kernel getKernel() 72 { 73 return null; 74 } 75 76 protected KernelController getKernelController() 77 { 78 return null; 79 } 80 81 } 82 | Popular Tags |