01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.beans.factory.xml;
18:
19: import org.springframework.beans.BeansException;
20: import org.springframework.beans.factory.BeanFactory;
21: import org.springframework.beans.factory.support.DefaultListableBeanFactory;
22: import org.springframework.core.io.Resource;
23:
24: /**
25: * Convenience extension of DefaultListableBeanFactory that reads bean definitions
26: * from an XML document. Delegates to XmlBeanDefinitionReader underneath; effectively
27: * equivalent to using an XmlBeanDefinitionReader with a DefaultListableBeanFactory.
28: *
29: * <p>The structure, element and attribute names of the required XML document
30: * are hard-coded in this class. (Of course a transform could be run if necessary
31: * to produce this format). "beans" doesn't need to be the root element of the XML
32: * document: This class will parse all bean definition elements in the XML file.
33: *
34: * <p>This class registers each bean definition with the DefaultListableBeanFactory
35: * superclass, and relies on the latter's implementation of the BeanFactory interface.
36: * It supports singletons, prototypes, and references to either of these kinds of bean.
37: * See "spring-beans_2_0.dtd" for details on options and configuration style.
38: *
39: * <p><b>For advanced needs, consider using a DefaultListableBeanFactory with
40: * an XmlBeanDefinitionReader.</b> The latter allows for reading from multiple XML
41: * resources and is highly configurable in its actual XML parsing behavior.
42: *
43: * @author Rod Johnson
44: * @author Juergen Hoeller
45: * @since 15 April 2001
46: * @see org.springframework.beans.factory.support.DefaultListableBeanFactory
47: * @see XmlBeanDefinitionReader
48: */
49: public class XmlBeanFactory extends DefaultListableBeanFactory {
50:
51: private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(
52: this );
53:
54: /**
55: * Create a new XmlBeanFactory with the given resource,
56: * which must be parsable using DOM.
57: * @param resource XML resource to load bean definitions from
58: * @throws BeansException in case of loading or parsing errors
59: */
60: public XmlBeanFactory(Resource resource) throws BeansException {
61: this (resource, null);
62: }
63:
64: /**
65: * Create a new XmlBeanFactory with the given input stream,
66: * which must be parsable using DOM.
67: * @param resource XML resource to load bean definitions from
68: * @param parentBeanFactory parent bean factory
69: * @throws BeansException in case of loading or parsing errors
70: */
71: public XmlBeanFactory(Resource resource,
72: BeanFactory parentBeanFactory) throws BeansException {
73: super(parentBeanFactory);
74: this.reader.loadBeanDefinitions(resource);
75: }
76:
77: }
|