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 org.codehaus.plexus.spring.PlexusXmlBeanDefinitionReader;
23  import org.springframework.beans.BeansException;
24  import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
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  import org.springframework.context.ApplicationContext;
29  import org.springframework.context.support.FileSystemXmlApplicationContext;
30  
31  import java.io.IOException;
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       *
79       * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
80       * @see #initBeanDefinitionReader
81       * @see #loadBeanDefinitions
82       */
83      protected void loadBeanDefinitions( DefaultListableBeanFactory beanFactory )
84          throws IOException
85      {
86          // Create a new XmlBeanDefinitionReader for the given BeanFactory.
87          XmlBeanDefinitionReader beanDefinitionReader = new PlexusXmlBeanDefinitionReader( beanFactory );
88  
89          // Configure the bean definition reader with this context's
90          // resource loading environment.
91          beanDefinitionReader.setResourceLoader( this );
92          beanDefinitionReader.setEntityResolver( new ResourceEntityResolver( this ) );
93  
94          // Allow a subclass to provide custom initialization of the reader,
95          // then proceed with actually loading the bean definitions.
96          initBeanDefinitionReader( beanDefinitionReader );
97          loadBeanDefinitions( beanDefinitionReader );
98      }
99  
100     /**
101      * {@inheritDoc}
102      *
103      * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
104      */
105     protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
106     {
107         delegate.postProcessBeanFactory( beanFactory, this );
108     }
109 
110     /**
111      * {@inheritDoc}
112      *
113      * @see org.springframework.context.support.AbstractApplicationContext#doClose()
114      */
115     protected void doClose()
116     {
117         delegate.doClose();
118         super.doClose();
119     }
120 }