View Javadoc

1   package org.apache.maven.continuum.management.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  
24  import org.codehaus.plexus.spring.PlexusXmlBeanDefinitionReader;
25  import org.springframework.beans.BeansException;
26  import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
27  import org.springframework.beans.factory.support.DefaultListableBeanFactory;
28  import org.springframework.beans.factory.xml.ResourceEntityResolver;
29  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
30  import org.springframework.context.ApplicationContext;
31  import org.springframework.context.support.FileSystemXmlApplicationContext;
32  
33  public class PlexusFileSystemXmlApplicationContext
34      extends FileSystemXmlApplicationContext
35  {
36      private static PlexusApplicationContextDelegate delegate = new PlexusApplicationContextDelegate();
37  
38      public PlexusFileSystemXmlApplicationContext( String configLocation )
39      {
40          super( configLocation );
41      }
42  
43      public PlexusFileSystemXmlApplicationContext( String[] configLocations )
44      {
45          super( configLocations );
46      }
47  
48      public PlexusFileSystemXmlApplicationContext( String[] configLocations, ApplicationContext parent )
49      {
50          super( configLocations, parent );
51      }
52  
53      public PlexusFileSystemXmlApplicationContext( String[] configLocations, boolean refresh )
54      {
55          super( configLocations, refresh );
56      }
57  
58      public PlexusFileSystemXmlApplicationContext( String[] configLocations, boolean refresh, ApplicationContext parent )
59      {
60          super( configLocations, refresh, parent );
61      }
62  
63      /**
64       * {@inheritDoc}
65       *
66       * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
67       */
68      protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
69          throws BeansException, IOException
70      {
71          delegate.loadBeanDefinitions( reader );
72          super.loadBeanDefinitions( reader );
73      }
74  
75      /**
76       * Copied from {@link AbstractXmlApplicationContext}
77       * Loads the bean definitions via an XmlBeanDefinitionReader.
78       * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
79       * @see #initBeanDefinitionReader
80       * @see #loadBeanDefinitions
81       */
82      protected void loadBeanDefinitions( DefaultListableBeanFactory beanFactory ) throws IOException {
83          // Create a new XmlBeanDefinitionReader for the given BeanFactory.
84          XmlBeanDefinitionReader beanDefinitionReader = new PlexusXmlBeanDefinitionReader( beanFactory );
85  
86          // Configure the bean definition reader with this context's
87          // resource loading environment.
88          beanDefinitionReader.setResourceLoader( this );
89          beanDefinitionReader.setEntityResolver( new ResourceEntityResolver( this ) );
90  
91          // Allow a subclass to provide custom initialization of the reader,
92          // then proceed with actually loading the bean definitions.
93          initBeanDefinitionReader( beanDefinitionReader );
94          loadBeanDefinitions( beanDefinitionReader );
95      }
96  
97      /**
98       * {@inheritDoc}
99       *
100      * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
101      */
102     protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
103     {
104         delegate.postProcessBeanFactory( beanFactory, this );
105     }
106 
107     /**
108      * {@inheritDoc}
109      *
110      * @see org.springframework.context.support.AbstractApplicationContext#doClose()
111      */
112     protected void doClose()
113     {
114         delegate.doClose();
115         super.doClose();
116     }
117 }