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 */ 017 package org.apache.xbean.spring.context; 018 019 import java.io.IOException; 020 import java.util.Collections; 021 import java.util.List; 022 023 import org.apache.xbean.spring.context.SpringApplicationContext; 024 import org.apache.xbean.spring.context.impl.XBeanHelper; 025 import org.springframework.beans.factory.support.DefaultListableBeanFactory; 026 import org.springframework.beans.factory.xml.ResourceEntityResolver; 027 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 028 029 /** 030 * An XBean version of the regular Spring class to provide improved XML 031 * handling. 032 * 033 * @author James Strachan 034 * @author Dain Sundstrom 035 * @version $Id$ 036 * @since 2.0 037 */ 038 public class XmlWebApplicationContext extends org.springframework.web.context.support.XmlWebApplicationContext implements SpringApplicationContext { 039 private final List xmlPreprocessors; 040 041 /** 042 * Creates a XmlWebApplicationContext which loads the configuration from the a web application context. 043 */ 044 public XmlWebApplicationContext() { 045 this.xmlPreprocessors = Collections.EMPTY_LIST; 046 } 047 048 /** 049 * Creates a XmlWebApplicationContext which loads the configuration from the a web application context. 050 * @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing 051 */ 052 public XmlWebApplicationContext(List xmlPreprocessors) { 053 this.xmlPreprocessors = xmlPreprocessors; 054 } 055 056 /** 057 * {@inheritDoc} 058 */ 059 protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException { 060 // Create a new XmlBeanDefinitionReader for the given BeanFactory. 061 XmlBeanDefinitionReader beanDefinitionReader = XBeanHelper.createBeanDefinitionReader(this, beanFactory, xmlPreprocessors); 062 063 // Configure the bean definition reader with this context's 064 // resource loading environment. 065 beanDefinitionReader.setResourceLoader(this); 066 beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); 067 068 // Allow a subclass to provide custom initialization of the reader, 069 // then proceed with actually loading the bean definitions. 070 initBeanDefinitionReader(beanDefinitionReader); 071 loadBeanDefinitions(beanDefinitionReader); 072 } 073 074 }