001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.beans.factory.xml;
018
019import org.springframework.beans.BeansException;
020import org.springframework.beans.factory.BeanFactory;
021import org.springframework.beans.factory.support.DefaultListableBeanFactory;
022import org.springframework.core.io.Resource;
023
024/**
025 * Convenience extension of {@link DefaultListableBeanFactory} that reads bean definitions
026 * from an XML document. Delegates to {@link XmlBeanDefinitionReader} underneath; effectively
027 * equivalent to using an XmlBeanDefinitionReader with a DefaultListableBeanFactory.
028 *
029 * <p>The structure, element and attribute names of the required XML document
030 * are hard-coded in this class. (Of course a transform could be run if necessary
031 * to produce this format). "beans" doesn't need to be the root element of the XML
032 * document: This class will parse all bean definition elements in the XML file.
033 *
034 * <p>This class registers each bean definition with the {@link DefaultListableBeanFactory}
035 * superclass, and relies on the latter's implementation of the {@link BeanFactory} interface.
036 * It supports singletons, prototypes, and references to either of these kinds of bean.
037 * See {@code "spring-beans-3.x.xsd"} (or historically, {@code "spring-beans-2.0.dtd"}) for
038 * details on options and configuration style.
039 *
040 * <p><b>For advanced needs, consider using a {@link DefaultListableBeanFactory} with
041 * an {@link XmlBeanDefinitionReader}.</b> The latter allows for reading from multiple XML
042 * resources and is highly configurable in its actual XML parsing behavior.
043 *
044 * @author Rod Johnson
045 * @author Juergen Hoeller
046 * @author Chris Beams
047 * @since 15 April 2001
048 * @see org.springframework.beans.factory.support.DefaultListableBeanFactory
049 * @see XmlBeanDefinitionReader
050 * @deprecated as of Spring 3.1 in favor of {@link DefaultListableBeanFactory} and
051 * {@link XmlBeanDefinitionReader}
052 */
053@Deprecated
054@SuppressWarnings({"serial", "all"})
055public class XmlBeanFactory extends DefaultListableBeanFactory {
056
057        private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this);
058
059
060        /**
061         * Create a new XmlBeanFactory with the given resource,
062         * which must be parsable using DOM.
063         * @param resource XML resource to load bean definitions from
064         * @throws BeansException in case of loading or parsing errors
065         */
066        public XmlBeanFactory(Resource resource) throws BeansException {
067                this(resource, null);
068        }
069
070        /**
071         * Create a new XmlBeanFactory with the given input stream,
072         * which must be parsable using DOM.
073         * @param resource XML resource to load bean definitions from
074         * @param parentBeanFactory parent bean factory
075         * @throws BeansException in case of loading or parsing errors
076         */
077        public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
078                super(parentBeanFactory);
079                this.reader.loadBeanDefinitions(resource);
080        }
081
082}