<artifactId>spring-context</artifactId>\r
<version>2.5.1</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-web</artifactId>\r
+ <version>2.5.1</version>\r
+ <optional>true</optional>\r
+ </dependency>\r
<dependency>\r
<groupId>commons-lang</groupId>\r
<artifactId>commons-lang</artifactId>\r
--- /dev/null
+package org.codehaus.plexus.spring;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Utility method to convert plexus descriptors to spring bean context.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class PlexusApplicationContextDelegate
+{
+ /** Logger used by this class. */
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ private PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;
+
+ /**
+ * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
+ */
+ protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
+ throws BeansException, IOException
+ {
+ logger.info( "Registering plexus to spring XML translation" );
+ reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );
+ reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );
+ }
+
+ /**
+ * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+ */
+ protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory, ApplicationContext context )
+ {
+ // Register a PlexusContainerAdapter bean to allow context lookups using plexus API
+ PlexusContainerAdapter plexus = new PlexusContainerAdapter();
+ plexus.setApplicationContext( context );
+ beanFactory.registerSingleton( "plexusContainer", plexus );
+
+ // Register a beanPostProcessor to handle plexus interface-based lifecycle management
+ lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();
+ lifecycleBeanPostProcessor.setBeanFactory( context );
+ beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );
+
+ // Register a PorpertyEditor to support plexus XML <configuration> set as CDATA in
+ // a spring context XML file.
+ beanFactory.addPropertyEditorRegistrar( new PlexusConfigurationPropertyEditor() );
+ }
+
+ /**
+ * @see org.springframework.context.support.AbstractApplicationContext#doClose()
+ */
+ protected void doClose()
+ {
+ try
+ {
+ lifecycleBeanPostProcessor.destroy();
+ }
+ catch ( Throwable ex )
+ {
+ logger.error( "Exception thrown from PlexusLifecycleBeanPostProcessor handling ContextClosedEvent", ex );
+ }
+ }
+}
import javax.xml.transform.Source;\r
import javax.xml.transform.Transformer;\r
import javax.xml.transform.TransformerFactory;\r
+import javax.xml.transform.TransformerFactoryConfigurationError;\r
import javax.xml.transform.dom.DOMResult;\r
import javax.xml.transform.dom.DOMSource;\r
import javax.xml.transform.stream.StreamSource;\r
\r
protected Document convertPlexusDescriptorToSpringBeans( Document doc )\r
{\r
- if ( !"component-set".equals( doc.getDocumentElement().getNodeName() ) )\r
+ if ( "component-set".equals( doc.getDocumentElement().getNodeName() ) )\r
{\r
- return doc;\r
+ return translatePlexusDescriptor( doc );\r
+ }\r
+ if ( "plexus".equals( doc.getDocumentElement().getNodeName() ) )\r
+ {\r
+ return translatePlexusDescriptor( doc );\r
}\r
\r
+ return doc;\r
+ }\r
+\r
+ private Document translatePlexusDescriptor( Document doc )\r
+ throws TransformerFactoryConfigurationError\r
+ {\r
try\r
{\r
Source xmlSource = new DOMSource( doc );\r
public class PlexusClassPathXmlApplicationContext\r
extends ClassPathXmlApplicationContext\r
{\r
- private PlexusLifecycleBeanPostProcessor lifecycleBeanPostProcessor;\r
+ private static PlexusApplicationContextDelegate delegate = new PlexusApplicationContextDelegate();\r
\r
public PlexusClassPathXmlApplicationContext( String path, Class clazz )\r
throws BeansException\r
super( path, clazz );\r
}\r
\r
-\r
-\r
-\r
public PlexusClassPathXmlApplicationContext( String configLocation )\r
throws BeansException\r
{\r
protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )\r
throws BeansException, IOException\r
{\r
- logger.info( "Registering plexus to spring XML translation" );\r
- reader.setDocumentReaderClass( PlexusBeanDefinitionDocumentReader.class );\r
- reader.setValidationMode( XmlBeanDefinitionReader.VALIDATION_NONE );\r
+ delegate.loadBeanDefinitions( reader );\r
super.loadBeanDefinitions( reader );\r
}\r
\r
*/\r
protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )\r
{\r
- // Register a PlexusContainerAdapter bean to allow context lookups using plexus API\r
- PlexusContainerAdapter plexus = new PlexusContainerAdapter();\r
- plexus.setApplicationContext( this );\r
- beanFactory.registerSingleton( "plexusContainer", plexus );\r
-\r
- // Register a beanPostProcessor to handle plexus interface-based lifecycle management\r
- lifecycleBeanPostProcessor = new PlexusLifecycleBeanPostProcessor();\r
- lifecycleBeanPostProcessor.setBeanFactory( this );\r
- beanFactory.addBeanPostProcessor( lifecycleBeanPostProcessor );\r
-\r
- // Register a PorpertyEditor to support plexus XML <configuration> set as CDATA in\r
- // a spring context XML file.\r
- beanFactory.addPropertyEditorRegistrar( new PlexusConfigurationPropertyEditor() );\r
+ delegate.postProcessBeanFactory( beanFactory, this );\r
}\r
\r
/**\r
*/\r
protected void doClose()\r
{\r
- try\r
- {\r
- lifecycleBeanPostProcessor.destroy();\r
- }\r
- catch ( Throwable ex )\r
- {\r
- logger.error( "Exception thrown from PlexusLifecycleBeanPostProcessor handling ContextClosedEvent", ex );\r
- }\r
+ delegate.doClose();\r
super.doClose();\r
}\r
\r
import java.util.List;
import java.util.Map;
+import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
*/
public class PlexusContainerAdapter
- implements PlexusContainer, ApplicationContextAware, InitializingBean
+ implements PlexusContainer, ApplicationContextAware
{
private Context context = new SimpleContext();
super();
}
- /**
- * {@inheritDoc}
- * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
- */
- public void afterPropertiesSet()
- throws Exception
- {
- context = new SimpleContext();
- }
-
/**
* {@inheritDoc}
* @see org.codehaus.plexus.PlexusContainer#addComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor)
private class SimpleContext implements Context
{
- /** the plexus container key in the context */
- private static final String PLEXUS = "plexus";
/**
* {@inheritDoc}
*/
public boolean contains( Object key )
{
- return PLEXUS.equals( key );
+ return PlexusConstants.PLEXUS_KEY.equals( key );
}
/**
public Object get( Object key )
throws ContextException
{
- return PLEXUS.equals( key ) ? PlexusContainerAdapter.this : null;
+ return PlexusConstants.PLEXUS_KEY.equals( key ) ? PlexusContainerAdapter.this : null;
}
/**
import org.springframework.context.ConfigurableApplicationContext;
-;
-
/**
* Mimic org.codehaus.plexus.PlexusTestCase as simple replacement for test
* cases.
* Utility method to convert plexus descriptors to spring bean context.\r
*\r
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>\r
- * @since 1.1\r
*/\r
public class PlexusToSpringUtils\r
{\r
--- /dev/null
+package org.codehaus.plexus.spring;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.web.context.support.XmlWebApplicationContext;
+
+/**
+ * A custom XmlWebApplicationContext to support plexus
+ * <tr>components.xml</tt> descriptors in Spring, with no changes required to
+ * neither plexus nor spring beans.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class PlexusWebApplicationContext
+ extends XmlWebApplicationContext
+{
+ private static PlexusApplicationContextDelegate delegate = new PlexusApplicationContextDelegate();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
+ */
+ protected void loadBeanDefinitions( XmlBeanDefinitionReader reader )
+ throws BeansException, IOException
+ {
+ delegate.loadBeanDefinitions( reader );
+ super.loadBeanDefinitions( reader );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.context.support.AbstractApplicationContext#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+ */
+ protected void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory )
+ {
+ delegate.postProcessBeanFactory( beanFactory, this );
+ super.postProcessBeanFactory( beanFactory );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.context.support.AbstractApplicationContext#doClose()
+ */
+ protected void doClose()
+ {
+ delegate.doClose();
+ super.doClose();
+ }
+
+}
to handle IoC containers incompatibilities.\r
-->\r
\r
-<xsl:template match="/component-set" >\r
+<xsl:template match="/" >\r
<spring:beans xmlns:spring="http://www.springframework.org/schema/beans"\r
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
xmlns="http://plexus.codehaus.org/spring"\r
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
http://plexus.codehaus.org/spring http://plexus.codehaus.org/schemas/spring-1.0.xsd"\r
default-lazy-init="true">\r
- <xsl:for-each select="components/component">\r
+ <xsl:for-each select="//component">\r
\r
<component>\r
<xsl:attribute name="role">\r
-<component-set>\r
+<?xml version="1.0" encoding="UTF-8"?>\r
+\r
+<plexus>\r
+\r
<components>\r
<component>\r
<role>org.codehaus.plexus.spring.PlexusBean</role>\r
</requirements>\r
</component>\r
</components>\r
-</component-set>\r
+\r
+</plexus>\r