001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.xbean.spring.context.impl;
018
019import java.util.Collections;
020import java.util.List;
021
022import org.springframework.beans.BeansException;
023import org.springframework.beans.factory.BeanFactory;
024import org.springframework.beans.factory.support.DefaultListableBeanFactory;
025import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
026import org.springframework.core.io.Resource;
027
028public class XBeanXmlBeanFactory extends DefaultListableBeanFactory {
029
030    /**
031     * Create a new XBeanXmlBeanFactory with the given resource,
032     * which must be parsable using DOM.
033     * @param resource XML resource to load bean definitions from
034     * @throws BeansException in case of loading or parsing errors
035     */
036    public XBeanXmlBeanFactory(Resource resource) throws BeansException {
037        this(resource, null, Collections.EMPTY_LIST);
038    }
039
040    /**
041     * Create a new XBeanXmlBeanFactory with the given input stream,
042     * which must be parsable using DOM.
043     * @param resource XML resource to load bean definitions from
044     * @param parentBeanFactory parent bean factory
045     * @throws BeansException in case of loading or parsing errors
046     */
047    public XBeanXmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
048        this(resource, parentBeanFactory, Collections.EMPTY_LIST);
049    }
050
051    /**
052     * Create a new XBeanXmlBeanFactory with the given input stream,
053     * which must be parsable using DOM.
054     * @param resource XML resource to load bean definitions from
055     * @param xmlPreprocessors the preprocessors to apply the DOM before passing to Spring for processing
056     * @throws BeansException in case of loading or parsing errors
057     */
058    public XBeanXmlBeanFactory(Resource resource, List xmlPreprocessors) throws BeansException {
059        this(resource, null, xmlPreprocessors);
060    }
061
062    /**
063     * Create a new XBeanXmlBeanFactory with the given input stream,
064     * which must be parsable using DOM.
065     * @param resource XML resource to load bean definitions from
066     * @param parentBeanFactory parent bean factory
067     * @param xmlPreprocessors the preprocessors to apply the DOM before passing to Spring for processing
068     * @throws BeansException in case of loading or parsing errors
069     */
070    public XBeanXmlBeanFactory(Resource resource, BeanFactory parentBeanFactory, List xmlPreprocessors) throws BeansException {
071        super(parentBeanFactory);
072        XmlBeanDefinitionReader reader = XBeanHelper.createBeanDefinitionReader(null, this, xmlPreprocessors);
073        reader.loadBeanDefinitions(resource);
074    }
075
076}