cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r439981 - in /cocoon/trunk: blocks/cocoon-portal/cocoon-portal-wsrp-impl/src/main/java/org/apache/cocoon/portal/wsrp/adapter/ core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ core/cocoon-core/src/main/java/org/apache/...
Date Mon, 04 Sep 2006 08:52:27 GMT
Author: cziegeler
Date: Mon Sep  4 01:52:21 2006
New Revision: 439981

URL: http://svn.apache.org/viewvc?view=rev&rev=439981
Log:
Continue new implementation

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
  (with props)
Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-wsrp-impl/src/main/java/org/apache/cocoon/portal/wsrp/adapter/WSRPAdapter.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-wsrp-impl/src/main/java/org/apache/cocoon/portal/wsrp/adapter/WSRPAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-wsrp-impl/src/main/java/org/apache/cocoon/portal/wsrp/adapter/WSRPAdapter.java?view=diff&rev=439981&r1=439980&r2=439981
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-wsrp-impl/src/main/java/org/apache/cocoon/portal/wsrp/adapter/WSRPAdapter.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-wsrp-impl/src/main/java/org/apache/cocoon/portal/wsrp/adapter/WSRPAdapter.java
Mon Sep  4 01:52:21 2006
@@ -802,7 +802,6 @@
         if (component instanceof RequiresPortalService) {
             ((RequiresPortalService)component).setPortalService(this.portalService);
         }
-        ContainerUtil.contextualize(component, context);
         ContainerUtil.service(component, manager);
         ContainerUtil.initialize(component);
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java?view=diff&rev=439981&r1=439980&r2=439981
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
Mon Sep  4 01:52:21 2006
@@ -16,10 +16,15 @@
  */
 package org.apache.cocoon.core.container.spring;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.util.Stack;
 
 import javax.servlet.ServletContext;
 
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.core.io.InputStreamResource;
 import org.springframework.core.io.Resource;
 import org.springframework.util.ClassUtils;
 import org.springframework.util.ResourceUtils;
@@ -45,9 +50,13 @@
     /** The class loader for this context (or null). */
     protected final ClassLoader classLoader;
 
+    /** The bean definition for this context. */
+    protected final String beanDefinition;
+
     public CocoonWebApplicationContext(ClassLoader           classloader,
                                        WebApplicationContext parent,
-                                       String                url) {
+                                       String                url,
+                                       String                rootDefinition) {
         this.setParent(parent);
         if ( url.endsWith("/") ) {
             this.baseUrl = url;
@@ -55,6 +64,17 @@
             this.baseUrl = url + '/';
         }
         this.classLoader = (classloader != null ? classloader : ClassUtils.getDefaultClassLoader());
+        this.beanDefinition = rootDefinition;
+    }
+
+    /**
+     * @see org.springframework.web.context.support.XmlWebApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
+     */
+    protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException,
IOException {
+        if ( this.beanDefinition != null ) {
+            reader.loadBeanDefinitions(new InputStreamResource(new ByteArrayInputStream(this.beanDefinition.getBytes("utf-8"))));
+        }
+        super.loadBeanDefinitions(reader);
     }
 
     /**

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java?view=auto&rev=439981
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
Mon Sep  4 01:52:21 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.container.spring.avalon;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.ProcessingUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.HierarchicalBeanFactory;
+
+/**
+ * Spring factory bean to setup a child Avalon logger.
+ *
+ * @since 2.2
+ * @version $Id$
+ */
+public class AvalonChildLoggerFactoryBean
+    implements FactoryBean, BeanFactoryAware {
+
+    /** Logger (we use the same logging mechanism as Spring!) */
+    protected final Log log = LogFactory.getLog(getClass());
+
+    /** The bean factory. */
+    protected BeanFactory beanFactory;
+
+    protected Logger logger;
+
+    /** The logging category. */
+    protected String category;
+
+    /**
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory factory) throws BeansException {
+        this.beanFactory = factory;
+    }
+
+    protected void init()
+    throws Exception {
+        // get parent factory
+        final BeanFactory parentFactory = ((HierarchicalBeanFactory)this.beanFactory).getParentBeanFactory();
+        final Logger parentLogger = (Logger)parentFactory.getBean(ProcessingUtil.LOGGER_ROLE);
+        if ( this.category == null ) {
+            this.logger = parentLogger;
+        } else {
+            this.logger = parentLogger.getChildLogger(this.category);
+        }
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
+    public Object getObject() throws Exception {
+        return this.logger;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     */
+    public Class getObjectType() {
+        return Logger.class;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     */
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public void setCategory(String category) {
+        this.category = category;
+    }
+}

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java?view=diff&rev=439981&r1=439980&r2=439981
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonElementParser.java
Mon Sep  4 01:52:21 2006
@@ -60,12 +60,6 @@
      * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
org.springframework.beans.factory.xml.ParserContext)
      */
     public BeanDefinition parse(Element element, ParserContext parserContext) {
-        final String loggingConfiguration = element.getAttribute("loggingConfiguration");
-        // we only add the logger if the configuration is present
-        if ( loggingConfiguration != null && loggingConfiguration.trim().length()
> 0 ) {
-            this.addLogger(loggingConfiguration, parserContext.getRegistry());
-        }
-
         // add context
         this.addContext(element, parserContext.getRegistry());
 
@@ -82,7 +76,11 @@
         final ResourceLoader resourceLoader = parserContext.getReaderContext().getReader().getResourceLoader();
         try {
             final ConfigurationInfo info = this.readConfiguration(location, resourceLoader);
-            // first handle includes
+            // add logger
+            final String loggingConfiguration = element.getAttribute("loggingConfiguration");
+            this.addLogger(loggingConfiguration, parserContext.getRegistry(), info.getRootLogger());
+
+            // handle includes of spring configurations
             final Iterator includeIter = info.getImports().iterator();
             while ( includeIter.hasNext() ) {
                 final String uri = (String)includeIter.next();
@@ -125,14 +123,22 @@
 
     /**
      * Add the logger bean.
-     * @param configuration The location of the logging configuration.
-     * @param registry      The bean registry.
+     * @param configuration  The location of the logging configuration.
+     * @param registry       The bean registry.
+     * @param loggerCategory The optional category for the logger.
      */
-    protected void addLogger(String configuration,
-                             BeanDefinitionRegistry registry) {
-        final RootBeanDefinition beanDef = this.createBeanDefinition(AvalonLoggerFactoryBean.class,
"init", true);
-        beanDef.getPropertyValues().addPropertyValue("loggingConfiguration", configuration);
-        this.register(beanDef, ProcessingUtil.LOGGER_ROLE, registry);
+    protected void addLogger(String                 configuration,
+                             BeanDefinitionRegistry registry,
+                             String                 loggerCategory) {
+        // we only add the logger if the configuration is present
+        if ( configuration != null && configuration.trim().length() > 0 ) {
+            final RootBeanDefinition beanDef = this.createBeanDefinition(AvalonLoggerFactoryBean.class,
"init", true);
+            beanDef.getPropertyValues().addPropertyValue("configuration", configuration);
+            if ( loggerCategory != null ) {
+                beanDef.getPropertyValues().addPropertyValue("category", loggerCategory);
+            }
+            this.register(beanDef, ProcessingUtil.LOGGER_ROLE, registry);
+        }
     }
 
     public void createConfig(ConfigurationInfo      info,

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java?view=diff&rev=439981&r1=439980&r2=439981
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
Mon Sep  4 01:52:21 2006
@@ -53,7 +53,10 @@
     protected Logger logger;
 
     /** The logging configuration. */
-    protected String loggingConfiguration;
+    protected String configuration;
+
+    /** The logging category. */
+    protected String category;
 
     /**
      * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
@@ -79,7 +82,7 @@
         loggerManager.contextualize(subcontext);
 
         // Configure the log4j manager
-        String loggerConfig = this.loggingConfiguration;
+        String loggerConfig = this.configuration;
         if ( loggerConfig != null && !loggerConfig.startsWith("/") ) {
             loggerConfig = '/' + loggerConfig;
         }
@@ -97,7 +100,11 @@
             loggerManager.configure(new DefaultConfiguration("empty"));
         }
 
-        this.logger = loggerManager.getLoggerForCategory("cocoon");
+        String loggingCategory = this.category;
+        if ( loggingCategory == null ) {
+            loggingCategory = "cocoon";
+        }
+        this.logger = loggerManager.getLoggerForCategory(loggingCategory);
     }
 
     /**
@@ -125,8 +132,8 @@
         this.settings = settings;
     }
 
-    public void setLoggingConfiguration(String loggingConfiguration) {
-        this.loggingConfiguration = loggingConfiguration;
+    public void setConfiguration(String loggingConfiguration) {
+        this.configuration = loggingConfiguration;
     }
 
     protected static final class LoggerWrapper implements Logger {
@@ -248,5 +255,9 @@
         public boolean isFatalErrorEnabled() {
             return this.log.isFatalEnabled();
         }
+    }
+
+    public void setCategory(String category) {
+        this.category = category;
     }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java?view=diff&rev=439981&r1=439980&r2=439981
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
Mon Sep  4 01:52:21 2006
@@ -42,10 +42,27 @@
     }
 
     /**
+     * Add the logger bean.
+     * @param configuration  The location of the logging configuration.
+     * @param registry       The bean registry.
+     * @param loggerCategory The optional category for the logger.
+     */
+    protected void addLogger(String                 configuration,
+                             BeanDefinitionRegistry registry,
+                             String                 loggerCategory) {
+        final RootBeanDefinition beanDef = this.createBeanDefinition(AvalonChildLoggerFactoryBean.class,
"init", false);
+        if ( loggerCategory != null ) {
+            beanDef.getPropertyValues().addPropertyValue("category", loggerCategory);
+        }
+        this.register(beanDef, ProcessingUtil.LOGGER_ROLE, registry);
+    }
+
+    /**
      * @see org.apache.cocoon.core.container.spring.avalon.AvalonElementParser#readConfiguration(java.lang.String,
org.springframework.core.io.ResourceLoader)
      */
-    protected ConfigurationInfo readConfiguration(String location, ResourceLoader resourceLoader)
throws Exception {
-        return super.readConfiguration(location, resourceLoader);
+    protected ConfigurationInfo readConfiguration(String location, ResourceLoader resourceLoader)
+    throws Exception {
+        return ConfigurationReader.readSitemap(null, location, resourceLoader);
     }
 
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java?view=diff&rev=439981&r1=439980&r2=439981
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
Mon Sep  4 01:52:21 2006
@@ -19,9 +19,20 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.servlet.ServletContext;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.cocoon.classloader.ClassLoaderConfiguration;
+import org.apache.cocoon.classloader.ClassLoaderFactory;
+import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
+import org.apache.cocoon.core.container.spring.CocoonWebApplicationContext;
+import org.apache.cocoon.environment.Request;
+import org.apache.excalibur.source.SourceResolver;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.scope.RequestAttributes;
 
 
 /**
@@ -134,4 +145,55 @@
     protected static void addFooter(StringBuffer buffer) {
         buffer.append("</beans>");
     }
+
+    public static CocoonWebApplicationContext createApplicationContext(String         contextUrl,
+                                                                       String         uriPrefix,
+                                                                       Configuration  config,
+                                                                       ServletContext servletContext,
+                                                                       SourceResolver sitemapResolver,
+                                                                       Request        request)
+    throws Exception {
+        final RequestAttributes attr = new CocoonRequestAttributes(request);
+        final WebApplicationContext parentContext = CocoonWebApplicationContext.getCurrentContext(servletContext,
attr);
+
+        // get classloader
+        final ClassLoader classloader = createClassLoader(parentContext, config, servletContext,
sitemapResolver);
+        // create root bean definition
+        final String definition = createDefinition(uriPrefix);
+        final CocoonWebApplicationContext context = new CocoonWebApplicationContext(classloader,
+                                                                                    parentContext,
+                                                                                    contextUrl,
+                                                                                    definition);
+        return context;
+    }
+
+    /**
+     * Build a processing tree from a <code>Configuration</code>.
+     */
+    public static ClassLoader createClassLoader(BeanFactory    parentFactory,
+                                                Configuration  config,
+                                                ServletContext servletContext,
+                                                SourceResolver sitemapResolver)
+    throws Exception {
+        final Configuration componentConfig = config.getChild("components", false);
+        Configuration classPathConfig = null;
+
+        if ( componentConfig != null ) {
+            classPathConfig = componentConfig.getChild(CLASSLOADER_CONFIG_NAME, false);
+        }
+        // Create class loader
+        // we don't create a new class loader if there is no new configuration
+        if ( classPathConfig == null ) {
+            return Thread.currentThread().getContextClassLoader();            
+        }
+        final String factoryRole = config.getAttribute("factory-role", ClassLoaderFactory.ROLE);
+
+        // Create a new classloader
+        ClassLoaderConfiguration configBean = ClassLoaderUtils.createConfiguration(sitemapResolver,
config);
+        ClassLoaderFactory clFactory = (ClassLoaderFactory)parentFactory.getBean(factoryRole);
+        return clFactory.createClassLoader(Thread.currentThread().getContextClassLoader(),
+                                           configBean,
+                                           servletContext);
+    }
+
 }



Mime
View raw message