1 package org.apache.maven.archiva.common.spring;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.io.IOException;
24 import org.springframework.beans.BeansException;
25 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
26 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
27 import org.springframework.context.ApplicationContext;
28 import org.springframework.context.support.ClassPathXmlApplicationContext;
31 * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
34 public class PlexusClassPathXmlApplicationContext
35 extends ClassPathXmlApplicationContext
38 // TODO enable Field injection...
39 // @see http://forum.springframework.org/showthread.php?t=50181
41 public PlexusClassPathXmlApplicationContext( String path, Class clazz )
47 public PlexusClassPathXmlApplicationContext( String configLocation )
50 super( configLocation );
53 public PlexusClassPathXmlApplicationContext( String[] configLocations, ApplicationContext parent )
56 super( configLocations, parent );
59 public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh, ApplicationContext parent )
62 super( configLocations, refresh, parent );
65 public PlexusClassPathXmlApplicationContext( String[] configLocations, boolean refresh )
68 super( configLocations, refresh );
71 public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz, ApplicationContext parent )
74 super( paths, clazz, parent );
77 public PlexusClassPathXmlApplicationContext( String[] paths, Class clazz )
80 super( paths, clazz );
83 public PlexusClassPathXmlApplicationContext( String[] configLocations )
86 super( configLocations );
90 * Register a custom BeanDefinitionDocumentReader to convert plexus
91 * descriptors to spring bean context format.
93 * Implementation note : validation must be disabled as plexus descriptors
94 * don't use DTD / XML schemas {@inheritDoc}
96 * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
99 protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
100 throws BeansException, IOException
102 reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
103 reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
104 super.loadBeanDefinitions( reader );
109 * Post-process the beanFactory to adapt plexus concepts to spring :
111 * <li>register a beanPostPorcessor to support LogEnabled interface in
116 * @see org.springframework.context.support.AbstractApplicationContext#prepareBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
119 protected void prepareBeanFactory( ConfigurableListableBeanFactory beanFactory )
121 super.prepareBeanFactory( beanFactory );
123 if ( logger.isDebugEnabled() )
125 String[] beans = getBeanFactory().getBeanDefinitionNames();
126 logger.debug( "registered beans :" );
127 for ( int i = 0; i < beans.length; i++ )
129 logger.debug( beans[i] );
133 // Register a bean post-processor to handle plexus Logger injection
134 getBeanFactory().addBeanPostProcessor( new PlexusLogEnabledBeanPostProcessor() );