1 22 23 package org.jboss.spring.factory; 24 25 import org.springframework.beans.BeansException; 26 import org.springframework.beans.factory.config.ConfigurableBeanFactory; 27 import org.springframework.beans.factory.support.BeanDefinitionRegistry; 28 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 29 import org.springframework.core.io.Resource; 30 import org.w3c.dom.Document ; 31 32 35 public class NamedXmlBeanDefinitionReader extends XmlBeanDefinitionReader 36 implements Nameable, Instantiable 37 { 38 39 private NamedXmlBeanDefinitionParser parser; 40 41 public NamedXmlBeanDefinitionReader(BeanDefinitionRegistry beanFactory) 42 { 43 super(beanFactory); 44 if (!(beanFactory instanceof ConfigurableBeanFactory)) 45 { 46 throw new IllegalArgumentException ("BeanFactory must implement ConfigurableBeanFactory!"); 47 } 48 parser = new NamedXmlBeanDefinitionParser((ConfigurableBeanFactory) beanFactory); 49 } 50 51 public int registerBeanDefinitions(Document doc, Resource resource) throws BeansException 52 { 53 int countBefore = this.getBeanFactory().getBeanDefinitionCount(); 54 parser.registerBeanDefinitions(doc, createReaderContext(resource)); 55 return this.getBeanFactory().getBeanDefinitionCount() - countBefore; 56 } 57 58 public String getName() 59 { 60 return parser.getName(); 61 } 62 63 public boolean doInstantiate() 64 { 65 return parser.doInstantiate(); 66 } 67 68 } 69 | Popular Tags |