1 package org.codehaus.plexus.spring;
\r
4 * Licensed to the Apache Software Foundation (ASF) under one
\r
5 * or more contributor license agreements. See the NOTICE file
\r
6 * distributed with this work for additional information
\r
7 * regarding copyright ownership. The ASF licenses this file
\r
8 * to you under the Apache License, Version 2.0 (the
\r
9 * "License"); you may not use this file except in compliance
\r
10 * with the License. You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing,
\r
15 * software distributed under the License is distributed on an
\r
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
17 * KIND, either express or implied. See the License for the
\r
18 * specific language governing permissions and limitations
\r
19 * under the License.
\r
22 import java.io.IOException;
\r
24 import org.springframework.beans.BeansException;
\r
25 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
\r
26 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
\r
27 import org.springframework.context.ApplicationContext;
\r
28 import org.springframework.context.support.ClassPathXmlApplicationContext;
\r
31 * A custom ClassPathXmlApplicationContext to support plexus
\r
32 * <tr>components.xml</tt> descriptors in Spring, with no changes required to
\r
33 * neither plexus nor spring beans.
\r
35 * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
\r
37 public class PlexusClassPathXmlApplicationContext
\r
38 extends ClassPathXmlApplicationContext
\r
40 private PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;
\r
42 public PlexusClassPathXmlApplicationContext( String path, Class clazz )
\r
43 throws BeansException
\r
45 super( path, clazz );
\r
51 public PlexusClassPathXmlApplicationContext( String configLocation )
\r
52 throws BeansException
\r
54 super( configLocation );
\r
57 public PlexusClassPathXmlApplicationContext( String[] configLocations, ApplicationContext parent )
\r
58 throws BeansException
\r
60 super( configLocations, parent );
\r
63 public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh, ApplicationContext parent )
\r
64 throws BeansException
\r
66 super( configLocations, refresh, parent );
\r
69 public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh )
\r
70 throws BeansException
\r
72 super( configLocations, refresh );
\r
75 public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz, ApplicationContext parent )
\r
76 throws BeansException
\r
78 super( paths, clazz, parent );
\r
81 public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz )
\r
82 throws BeansException
\r
84 super( paths, clazz );
\r
87 public PlexusClassPathXmlApplicationContext( String[] configLocations )
\r
88 throws BeansException
\r
90 super( configLocations );
\r
96 * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
\r
98 protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
\r
99 throws BeansException, IOException
\r
101 logger.info( "Registering plexus to spring XML translation" );
\r
102 reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
\r
103 reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
\r
104 super.loadBeanDefinitions( reader );
\r
110 * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
\r
112 protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
\r
114 // Register a PlexusContainerAdapter bean to allow context lookups using plexus API
\r
115 PlexusContainerAdapter plexus = new PlexusContainerAdapter();
\r
116 plexus.setApplicationContext( this );
\r
117 beanFactory.registerSingleton( "plexusContainer", plexus );
\r
119 // Register a beanPostProcessor to handle plexus interface-based lifecycle management
\r
120 lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();
\r
121 lifecycleBeanPostProcessor.setBeanFactory( this );
\r
122 beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );
\r
124 // Register a PorpertyEditor to support plexus XML <configuration> set as CDATA in
\r
125 // a spring context XML file.
\r
126 beanFactory.addPropertyEditorRegistrar( new PlexusConfigurationPropertyEditor() );
\r
132 * @see org.springframework.context.support.AbstractApplicationContext#doClose()
\r
134 protected void doClose()
\r
138 lifecycleBeanPostProcessor.destroy();
\r
140 catch ( Throwable ex )
\r
142 logger.error( "Exception thrown from PlexusLifecycleBeanPostProcessor handling ContextClosedEvent", ex );
\r