cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r382811 - in /cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon: components/treeprocessor/sitemap/ core/ core/container/spring/
Date Fri, 03 Mar 2006 13:48:52 GMT
Author: cziegeler
Date: Fri Mar  3 05:48:51 2006
New Revision: 382811

URL: http://svn.apache.org/viewcvs?rev=382811&view=rev
Log:
Clean up method names and variable names
Add support for beanpostprocessor beans

Modified:
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/NameForAliasAware.java

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=382811&r1=382810&r2=382811&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Fri Mar  3 05:48:51 2006
@@ -141,7 +141,7 @@
         final ConfigurationInfo ci = ConfigReader.readConfiguration(c, parentConfigInfo,
ae);
 
         final ConfigurableBeanFactory sitemapContext = 
-            BeanFactoryUtil.createApplicationContext(ae, ci, parentContext, false);
+            BeanFactoryUtil.createBeanFactory(ae, ci, parentContext, false);
         newManager = (ServiceManager) sitemapContext.getBean(ServiceManager.class.getName());
         Logger sitemapLogger = sitemapLogger = (Logger)sitemapContext.getBean(Logger.class.getName());
 

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java?rev=382811&r1=382810&r2=382811&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java Fri Mar  3
05:48:51 2006
@@ -614,7 +614,7 @@
         env.settings = this.settings;
         ConfigurableBeanFactory rootContext = BeanFactoryUtil.createRootApplicationContext(env);
         ConfigurationInfo result = ConfigReader.readConfiguration(settings.getConfiguration(),
env);
-        ConfigurableBeanFactory mainContext = BeanFactoryUtil.createApplicationContext(env,
result, rootContext, true);
+        ConfigurableBeanFactory mainContext = BeanFactoryUtil.createBeanFactory(env, result,
rootContext, true);
 
         return mainContext;
     }

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java?rev=382811&r1=382810&r2=382811&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
Fri Mar  3 05:48:51 2006
@@ -49,9 +49,9 @@
 import org.springframework.web.context.WebApplicationContext;
 
 /**
- * This utility class helps in creating new Spring {@link BeanFactory} objects which support
- * the Avalon style component configuration. It also offers help in setting up the root
- * logger for Cocoon.
+ * This utility class helps in creating new Spring {@link ConfigurableBeanFactory} objects
+ * which support the Avalon style component configuration. It also offers help in setting
+ * up the root logger for Cocoon.
  *
  * @since 2.2
  * @version $Id$
@@ -67,10 +67,10 @@
      * @return A new bean factory.
      * @throws Exception
      */
-    public static ConfigurableBeanFactory createApplicationContext(AvalonEnvironment  env,
-                                                                   ConfigurationInfo  info,
-                                                                   BeanFactory        parent,
-                                                                   boolean            addCocoon)
+    public static ConfigurableBeanFactory createBeanFactory(AvalonEnvironment env,
+                                                            ConfigurationInfo info,
+                                                            BeanFactory       parent,
+                                                            boolean           addCocoon)
     throws Exception {
         final String xmlConfig = (new XmlConfigCreator(env.logger)).createConfig(info, addCocoon);
         Resource rsc = new ByteArrayResource(xmlConfig.getBytes("utf-8"));
@@ -78,17 +78,18 @@
         if ( info.rootLogger != null ) {
             logger = env.logger.getChildLogger(info.rootLogger);
         }
-        CocoonBeanFactory context = new CocoonBeanFactory(rsc, 
+        CocoonBeanFactory factory = new CocoonBeanFactory(rsc, 
                                                           parent,
                                                           logger,
                                                           info,
                                                           env.context,
                                                           env.settings);
         if ( info.rootLogger != null ) {
-            context.registerSingleton(Logger.class.getName(), logger);
+            factory.registerSingleton(Logger.class.getName(), logger);
         }
-        prepareApplicationContext(context, info);
-        return context;
+        prepareBeanFactory(factory, info);
+        factory.preInstantiateSingletons();
+        return factory;
     }
 
     /**
@@ -108,6 +109,7 @@
         factory.registerSingleton(ProcessingUtil.CONTEXT_ROLE, env.context);
         factory.registerSingleton(ProcessingUtil.LOGGER_ROLE, env.logger);
         factory.registerSingleton(ProcessingUtil.SETTINGS_ROLE, env.settings);
+        factory.preInstantiateSingletons();
         return factory;
     }
 
@@ -137,7 +139,6 @@
         try {
             return initLogger(context, settings);
         } catch (Exception ce) {
-            ce.printStackTrace();
             throw new CoreInitializationException("Cannot setup log4j logging system.", ce);
         }
     }
@@ -202,13 +203,13 @@
         return loggerManager.getLoggerForCategory(accesslogger);
     }
 
-    protected static void prepareApplicationContext(CocoonBeanFactory context,
-                                                    ConfigurationInfo configInfo) {
+    protected static void prepareBeanFactory(CocoonBeanFactory factory,
+                                             ConfigurationInfo configInfo) {
         // TODO - we should find a better way
         // add ProcessorComponentInfo
         ProcessorComponentInfo parentInfo = null;
-        if ( context.getParentBeanFactory() != null && context.getParentBeanFactory().containsBean(ProcessorComponentInfo.ROLE)
) {
-            parentInfo = (ProcessorComponentInfo)context.getParentBeanFactory().getBean(ProcessorComponentInfo.ROLE);
+        if ( factory.getParentBeanFactory() != null && factory.getParentBeanFactory().containsBean(ProcessorComponentInfo.ROLE)
) {
+            parentInfo = (ProcessorComponentInfo)factory.getParentBeanFactory().getBean(ProcessorComponentInfo.ROLE);
         }
         ProcessorComponentInfo info = new ProcessorComponentInfo(parentInfo);
         final Iterator i = configInfo.getComponents().values().iterator();
@@ -216,20 +217,20 @@
             final ComponentInfo current = (ComponentInfo)i.next();
             info.componentAdded(current.getRole(), current.getComponentClassName(), current.getConfiguration());
         }
-        prepareSelector(info, context, configInfo, Generator.ROLE);
-        prepareSelector(info, context, configInfo, Transformer.ROLE);
-        prepareSelector(info, context, configInfo, Serializer.ROLE);
-        prepareSelector(info, context, configInfo, ProcessingPipeline.ROLE);
-        prepareSelector(info, context, configInfo, Action.ROLE);
-        prepareSelector(info, context, configInfo, Selector.ROLE);
-        prepareSelector(info, context, configInfo, Matcher.ROLE);
-        prepareSelector(info, context, configInfo, Reader.ROLE);
+        prepareSelector(info, factory, configInfo, Generator.ROLE);
+        prepareSelector(info, factory, configInfo, Transformer.ROLE);
+        prepareSelector(info, factory, configInfo, Serializer.ROLE);
+        prepareSelector(info, factory, configInfo, ProcessingPipeline.ROLE);
+        prepareSelector(info, factory, configInfo, Action.ROLE);
+        prepareSelector(info, factory, configInfo, Selector.ROLE);
+        prepareSelector(info, factory, configInfo, Matcher.ROLE);
+        prepareSelector(info, factory, configInfo, Reader.ROLE);
         info.lock();
-        context.registerSingleton(ProcessorComponentInfo.ROLE, info);
+        factory.registerSingleton(ProcessorComponentInfo.ROLE, info);
     }
 
     protected static void prepareSelector(ProcessorComponentInfo info,
-                                          CocoonBeanFactory      context,
+                                          CocoonBeanFactory      factory,
                                           ConfigurationInfo      configInfo,
                                           String                 category) {
         final ComponentInfo component = (ComponentInfo)configInfo.getComponents().get(category
+ "Selector");

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java?rev=382811&r1=382810&r2=382811&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
Fri Mar  3 05:48:51 2006
@@ -15,6 +15,10 @@
  */
 package org.apache.cocoon.core.container.spring;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.avalon.framework.configuration.Configurable;
@@ -33,14 +37,15 @@
 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.context.ApplicationContext;
+import org.springframework.core.OrderComparator;
 import org.springframework.core.io.Resource;
 
 /**
- * This is a Cocoon specific implementation of a Spring {@link ApplicationContext}.
+ * This is a Cocoon specific implementation of a Spring {@link DefaultListableBeanFactory}.
  *
  * @since 2.2
  * @version $Id$
@@ -108,6 +113,24 @@
         }
         // default: we just return the alias
         return alias;
+    }
+
+    /**
+     * Instantiate and invoke all registered BeanPostProcessor beans,
+     * respecting explicit order if given.
+     * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#preInstantiateSingletons()
+     */
+    public void preInstantiateSingletons() throws BeansException {
+        // Actually fetch and register the BeanPostProcessor beans.
+        // Do not initialize FactoryBeans here: We need to leave all regular beans
+        // uninitialized to let the bean post-processors apply to them!
+        final Map beanProcessorMap = this.getBeansOfType(BeanPostProcessor.class, true, false);
+        final List beanProcessors = new ArrayList(beanProcessorMap.values());
+        Collections.sort(beanProcessors, new OrderComparator());
+        for (Iterator it = beanProcessors.iterator(); it.hasNext();) {
+            this.addBeanPostProcessor((BeanPostProcessor) it.next());
+        }
+        super.preInstantiateSingletons();
     }
 
     /**

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/NameForAliasAware.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/NameForAliasAware.java?rev=382811&r1=382810&r2=382811&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/NameForAliasAware.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/NameForAliasAware.java
Fri Mar  3 05:48:51 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed 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.
@@ -19,11 +19,12 @@
  * $Id$
  */
 public interface NameForAliasAware {
+
     /**
-     * Give the real component name given a alias name, return the given name if
+     * Give the real component name given an alias name, return the given name if
      * its not an alias.
-     * @param alias
-     * @return
+     * @param alias The alias for the component.
+     * @return The real component name.
      */
-    public String getNameForAlias(String alias);
+    String getNameForAlias(String alias);
 }



Mime
View raw message