1 16 17 package org.springframework.context.access; 18 19 import javax.naming.NamingException ; 20 21 import org.springframework.beans.BeansException; 22 import org.springframework.beans.factory.access.BeanFactoryLocator; 23 import org.springframework.beans.factory.access.BeanFactoryReference; 24 import org.springframework.beans.factory.access.BootstrapException; 25 import org.springframework.context.ApplicationContext; 26 import org.springframework.context.support.ClassPathXmlApplicationContext; 27 import org.springframework.jndi.JndiLocatorSupport; 28 import org.springframework.util.StringUtils; 29 30 42 public class ContextJndiBeanFactoryLocator extends JndiLocatorSupport implements BeanFactoryLocator { 43 44 48 public static final String BEAN_FACTORY_PATH_DELIMITERS = ",; \t\n"; 49 50 51 60 public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException { 61 try { 62 String beanFactoryPath = (String ) lookup(factoryKey, String .class); 63 if (logger.isTraceEnabled()) { 64 logger.trace("Bean factory path from JNDI environment variable [" + factoryKey + 65 "] is: " + beanFactoryPath); 66 } 67 String [] paths = StringUtils.tokenizeToStringArray(beanFactoryPath, BEAN_FACTORY_PATH_DELIMITERS); 68 return createBeanFactory(paths); 69 } 70 catch (NamingException ex) { 71 throw new BootstrapException("Define an environment variable [" + factoryKey + "] containing " + 72 "the class path locations of XML bean definition files", ex); 73 } 74 } 75 76 89 protected BeanFactoryReference createBeanFactory(String [] resources) throws BeansException { 90 ApplicationContext ctx = createApplicationContext(resources); 91 return new ContextBeanFactoryReference(ctx); 92 } 93 94 101 protected ApplicationContext createApplicationContext(String [] resources) throws BeansException { 102 return new ClassPathXmlApplicationContext(resources); 103 } 104 105 } 106 | Popular Tags |