You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/08/22 23:18:08 UTC
svn commit: r433756 - in
/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring:
CocoonBeanFactory.java avalon/AvalonBeanPostProcessor.java
Author: cziegeler
Date: Tue Aug 22 14:18:07 2006
New Revision: 433756
URL: http://svn.apache.org/viewvc?rev=433756&view=rev
Log:
Factor out bean post processor
Added:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java (with props)
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java?rev=433756&r1=433755&r2=433756&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java Tue Aug 22 14:18:07 2006
@@ -23,22 +23,13 @@
import javax.servlet.ServletContext;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.parameters.Parameterizable;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.container.spring.avalon.AvalonBeanPostProcessor;
import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.OrderComparator;
@@ -98,10 +89,11 @@
this.avalonContext = avalonContext;
if ( this.avalonConfiguration != null ) {
- AvalonPostProcessor processor = new AvalonPostProcessor(this.avalonConfiguration.getComponents(),
- this.avalonContext,
- this.avalonLogger,
- this);
+ AvalonBeanPostProcessor processor = new AvalonBeanPostProcessor();
+ processor.setBeanFactory(this);
+ processor.setLogger(this.avalonLogger);
+ processor.setContext(this.avalonContext);
+ processor.setConfigurationInfo(this.avalonConfiguration);
this.addBeanPostProcessor(processor);
this.registerSingleton(ConfigurationInfo.class.getName(), this.avalonConfiguration);
}
@@ -130,93 +122,5 @@
this.addBeanPostProcessor((BeanPostProcessor) it.next());
}
super.preInstantiateSingletons();
- }
-
- /**
- * This is a Spring BeanPostProcessor adding support for the Avalon lifecycle interfaces.
- */
- protected static final class AvalonPostProcessor implements DestructionAwareBeanPostProcessor {
-
- protected static final Configuration EMPTY_CONFIG = new DefaultConfiguration("empty");
-
- protected final Logger logger;
- protected final Context context;
- protected final CocoonBeanFactory beanFactory;
- protected final Map components;
-
- public AvalonPostProcessor(Map components,
- Context context,
- Logger logger,
- CocoonBeanFactory factory) {
- this.components = components;
- this.context = context;
- this.logger = logger;
- this.beanFactory = factory;
- }
-
- /**
- * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
- */
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- try {
- ContainerUtil.start(bean);
- } catch (Exception e) {
- throw new BeanInitializationException("Unable to start bean " + beanName, e);
- }
- return bean;
- }
-
- /**
- * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
- */
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- final ComponentInfo info = (ComponentInfo)this.components.get(beanName);
- try {
- if ( info == null ) {
- // no info so we just return the bean and don't apply any lifecycle interfaces
- return bean;
- }
- if ( info.getLoggerCategory() != null ) {
- ContainerUtil.enableLogging(bean, this.logger.getChildLogger(info.getLoggerCategory()));
- } else {
- ContainerUtil.enableLogging(bean, this.logger);
- }
- ContainerUtil.contextualize(bean, this.context);
- ContainerUtil.service(bean, (ServiceManager)this.beanFactory.getBean(ServiceManager.class.getName()));
- Configuration config = info.getConfiguration();
- if ( config == null ) {
- config = EMPTY_CONFIG;
- }
- if ( bean instanceof Configurable ) {
- ContainerUtil.configure(bean, config);
- } else if ( bean instanceof Parameterizable ) {
- Parameters p = info.getParameters();
- if ( p == null ) {
- p = Parameters.fromConfiguration(config);
- info.setParameters(p);
- }
- ContainerUtil.parameterize(bean, p);
- }
- ContainerUtil.initialize(bean);
- } catch (Exception e) {
- throw new BeanCreationException("Unable to initialize Avalon component with role " + beanName, e);
- }
- return bean;
- }
-
- /**
- * @see org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor#postProcessBeforeDestruction(java.lang.Object, java.lang.String)
- */
- public void postProcessBeforeDestruction(Object bean, String beanName)
- throws BeansException {
- try {
- ContainerUtil.stop(bean);
- } catch (Exception e) {
- throw new BeanInitializationException("Unable to stop bean " + beanName, e);
- }
- ContainerUtil.dispose(bean);
- }
}
}
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java?rev=433756&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java Tue Aug 22 14:18:07 2006
@@ -0,0 +1,129 @@
+package org.apache.cocoon.core.container.spring.avalon;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.core.container.spring.ComponentInfo;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
+
+/**
+ * This is a Spring BeanPostProcessor adding support for the Avalon lifecycle interfaces.
+ */
+public class AvalonBeanPostProcessor
+ implements DestructionAwareBeanPostProcessor, BeanFactoryAware {
+
+ protected static final Configuration EMPTY_CONFIG = new DefaultConfiguration("empty");
+
+ protected Logger logger;
+ protected Context context;
+ protected BeanFactory beanFactory;
+ protected ConfigurationInfo configurationInfo;
+
+ /**
+ * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+ */
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ this.beanFactory = factory;
+ }
+
+ public ConfigurationInfo getConfigurationInfo() {
+ return configurationInfo;
+ }
+
+ public void setConfigurationInfo(ConfigurationInfo configurationInfo) {
+ this.configurationInfo = configurationInfo;
+ }
+
+ public Context getContext() {
+ return context;
+ }
+
+ public void setContext(Context context) {
+ this.context = context;
+ }
+
+ public Logger getLogger() {
+ return logger;
+ }
+
+ public void setLogger(Logger logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
+ */
+ public Object postProcessAfterInitialization(Object bean, String beanName)
+ throws BeansException {
+ try {
+ ContainerUtil.start(bean);
+ } catch (Exception e) {
+ throw new BeanInitializationException("Unable to start bean " + beanName, e);
+ }
+ return bean;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
+ */
+ public Object postProcessBeforeInitialization(Object bean, String beanName)
+ throws BeansException {
+ final ComponentInfo info = (ComponentInfo)this.configurationInfo.getComponents().get(beanName);
+ try {
+ if ( info == null ) {
+ // no info so we just return the bean and don't apply any lifecycle interfaces
+ return bean;
+ }
+ if ( info.getLoggerCategory() != null ) {
+ ContainerUtil.enableLogging(bean, this.logger.getChildLogger(info.getLoggerCategory()));
+ } else {
+ ContainerUtil.enableLogging(bean, this.logger);
+ }
+ ContainerUtil.contextualize(bean, this.context);
+ ContainerUtil.service(bean, (ServiceManager)this.beanFactory.getBean(ServiceManager.class.getName()));
+ Configuration config = info.getConfiguration();
+ if ( config == null ) {
+ config = EMPTY_CONFIG;
+ }
+ if ( bean instanceof Configurable ) {
+ ContainerUtil.configure(bean, config);
+ } else if ( bean instanceof Parameterizable ) {
+ Parameters p = info.getParameters();
+ if ( p == null ) {
+ p = Parameters.fromConfiguration(config);
+ info.setParameters(p);
+ }
+ ContainerUtil.parameterize(bean, p);
+ }
+ ContainerUtil.initialize(bean);
+ } catch (Exception e) {
+ throw new BeanCreationException("Unable to initialize Avalon component with role " + beanName, e);
+ }
+ return bean;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor#postProcessBeforeDestruction(java.lang.Object, java.lang.String)
+ */
+ public void postProcessBeforeDestruction(Object bean, String beanName)
+ throws BeansException {
+ try {
+ ContainerUtil.stop(bean);
+ } catch (Exception e) {
+ throw new BeanInitializationException("Unable to stop bean " + beanName, e);
+ }
+ ContainerUtil.dispose(bean);
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
------------------------------------------------------------------------------
svn:keywords = Id