1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.xbean.spring.context;
18
19 import java.io.IOException;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.xbean.spring.context.SpringApplicationContext;
24 import org.apache.xbean.spring.context.impl.XBeanHelper;
25 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
26 import org.springframework.beans.factory.xml.ResourceEntityResolver;
27 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
28
29 /**
30 * An XBean version of the regular Spring class to provide improved XML
31 * handling.
32 *
33 * @author James Strachan
34 * @author Dain Sundstrom
35 * @version $Id$
36 * @since 2.0
37 */
38 public class XmlWebApplicationContext extends org.springframework.web.context.support.XmlWebApplicationContext implements SpringApplicationContext {
39 private final List xmlPreprocessors;
40
41 /**
42 * Creates a XmlWebApplicationContext which loads the configuration from the a web application context.
43 */
44 public XmlWebApplicationContext() {
45 this.xmlPreprocessors = Collections.EMPTY_LIST;
46 }
47
48 /**
49 * Creates a XmlWebApplicationContext which loads the configuration from the a web application context.
50 * @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
51 */
52 public XmlWebApplicationContext(List xmlPreprocessors) {
53 this.xmlPreprocessors = xmlPreprocessors;
54 }
55
56 /**
57 * {@inheritDoc}
58 */
59 protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
60 // Create a new XmlBeanDefinitionReader for the given BeanFactory.
61 XmlBeanDefinitionReader beanDefinitionReader = XBeanHelper.createBeanDefinitionReader(this, beanFactory, xmlPreprocessors);
62
63 // Configure the bean definition reader with this context's
64 // resource loading environment.
65 beanDefinitionReader.setResourceLoader(this);
66 beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
67
68 // Allow a subclass to provide custom initialization of the reader,
69 // then proceed with actually loading the bean definitions.
70 initBeanDefinitionReader(beanDefinitionReader);
71 loadBeanDefinitions(beanDefinitionReader);
72 }
73
74 }