cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r587720 - in /cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon: components/treeprocessor/sitemap/ core/container/spring/avalon/ core/container/spring/logger/
Date Wed, 24 Oct 2007 00:47:27 GMT
Author: vgritsenko
Date: Tue Oct 23 17:47:26 2007
New Revision: 587720

URL: http://svn.apache.org/viewvc?rev=587720&view=rev
Log:
Replacing avalon logger in the spring context with Commons Logging log.
Switching avalon bridge code to use commons logging log.
AvalonUtils.LOGGER_ROLE is removed.

Added:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/ChildLoggerFactoryBean.java
      - copied, changed from r586658, cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java
  (contents, props changed)
      - copied, changed from r586658, cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java
  (with props)
Removed:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
Modified:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ErrorHandlerHelper.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ErrorHandlerHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ErrorHandlerHelper.java?rev=587720&r1=587719&r2=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ErrorHandlerHelper.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ErrorHandlerHelper.java
Tue Oct 23 17:47:26 2007
@@ -19,10 +19,10 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.logging.Log;
 
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.Processor;
@@ -31,7 +31,7 @@
 import org.apache.cocoon.components.notification.NotifyingBuilder;
 import org.apache.cocoon.components.treeprocessor.InvokeContext;
 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
-import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
+import org.apache.cocoon.core.container.spring.logger.LoggerUtils;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.util.AbstractLogEnabled;
@@ -49,7 +49,7 @@
     /**
      * Logger for handled errors
      */
-    protected Logger handledErrorsLogger;
+    protected Log handledErrorsLogger;
 
     /**
      * Error handling node for the ResourceNotFoundException
@@ -68,7 +68,7 @@
      */
     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
-        this.handledErrorsLogger = ((Logger) this.manager.lookup(AvalonUtils.LOGGER_ROLE)).getChildLogger("handled");
+        this.handledErrorsLogger = LoggerUtils.getChildLogger(this.manager, "handled");
     }
 
     void set404Handler(ProcessingNode node) {

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java?rev=587720&r1=587719&r2=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonBeanPostProcessor.java
Tue Oct 23 17:47:26 2007
@@ -28,13 +28,10 @@
 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.logger.LogEnabled;
 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.MutableSettings;
-import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.spring.configurator.ResourceUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
@@ -47,6 +44,13 @@
 import org.springframework.core.io.ResourceLoader;
 import org.springframework.web.context.support.ServletContextResourcePatternResolver;
 
+import org.apache.cocoon.configuration.MutableSettings;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.container.spring.logger.LoggerUtils;
+import org.apache.cocoon.spring.configurator.ResourceUtils;
+import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.cocoon.util.avalon.CLLoggerWrapper;
+
 /**
  * This is a Spring BeanPostProcessor adding support for the Avalon lifecycle
  * interfaces.
@@ -54,7 +58,8 @@
  * @since 2.2
  * @version $Id$
  */
-public class AvalonBeanPostProcessor implements DestructionAwareBeanPostProcessor, BeanFactoryAware
{
+public class AvalonBeanPostProcessor extends AbstractLogEnabled
+                                     implements DestructionAwareBeanPostProcessor, BeanFactoryAware
{
 
     protected static final Configuration EMPTY_CONFIG;
     static {
@@ -63,7 +68,6 @@
         EMPTY_CONFIG = config;
     }
 
-    protected Logger logger;
     protected Context context;
     protected BeanFactory beanFactory;
     protected ConfigurationInfo configurationInfo;
@@ -101,19 +105,15 @@
         this.context = context;
     }
 
-    public void setLogger(Logger logger) {
-        this.logger = logger;
-    }
-
     public void init() {
         if (true) {
             return;
         }
 
         // replace properties in configuration objects
-        if (this.logger.isDebugEnabled()) {
-            this.logger.debug("Processing component configurations.");
-            this.logger.debug("Trying to read properties from directory: " + this.location);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Processing component configurations.");
+            getLogger().debug("Trying to read properties from directory: " + this.location);
         }
         final Properties mergedProps = new Properties();
         final ServletContextResourcePatternResolver resolver = new ServletContextResourcePatternResolver(resourceLoader);
@@ -124,8 +124,8 @@
             if (resources != null) {
                 Arrays.sort(resources, ResourceUtils.getResourceComparator());
                 for (int i = 0; i < resources.length; i++) {
-                    if (this.logger.isDebugEnabled()) {
-                        this.logger.debug("Reading property file: " + resources[i]);
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("Reading property file: " + resources[i]);
                     }
                     final Properties p = new Properties();
                     p.load(resources[i].getInputStream());
@@ -221,11 +221,13 @@
                 return bean;
             }
 
-            if (info.getLoggerCategory() != null) {
-                ContainerUtil.enableLogging(bean, this.logger.getChildLogger(info.getLoggerCategory()));
-            } else {
-                ContainerUtil.enableLogging(bean, this.logger);
+            if (bean instanceof LogEnabled) {
+                ContainerUtil.enableLogging(bean,
+                                            new CLLoggerWrapper(LoggerUtils.getChildLogger(beanFactory,
info.getLoggerCategory())));
+            } else if (bean instanceof AbstractLogEnabled && info.getLoggerCategory()
!= null) {
+                ((AbstractLogEnabled) bean).setLogger(LoggerUtils.getChildLogger(beanFactory,
info.getLoggerCategory()));
             }
+
             ContainerUtil.contextualize(bean, this.context);
             ContainerUtil.service(bean, (ServiceManager) this.beanFactory.getBean(ServiceManager.class.getName()));
 

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java?rev=587720&r1=587719&r2=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
Tue Oct 23 17:47:26 2007
@@ -33,9 +33,6 @@
     /** Bean name for the Avalon context. */
     public static final String CONTEXT_ROLE = "org.apache.avalon.framework.context.Context";
 
-    /** Bean name for the logger. */
-    public static final String LOGGER_ROLE = "org.apache.avalon.framework.logger.Logger";
-
     /** Bean name for the service manager. */
     public static final String SERVICE_MANAGER_ROLE = "org.apache.avalon.framework.service.ServiceManager";
 

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java?rev=587720&r1=587719&r2=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/BridgeElementParser.java
Tue Oct 23 17:47:26 2007
@@ -26,10 +26,22 @@
 import org.apache.avalon.excalibur.pool.Poolable;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.thread.ThreadSafe;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.BeanDefinitionReader;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.core.io.ResourceLoader;
+
 import org.apache.cocoon.acting.Action;
 import org.apache.cocoon.components.pipeline.ProcessingPipeline;
 import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
 import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.container.spring.logger.LoggerFactoryBean;
+import org.apache.cocoon.core.container.spring.logger.LoggerUtils;
 import org.apache.cocoon.core.container.spring.pipeline.PipelineComponentInfoFactoryBean;
 import org.apache.cocoon.core.container.spring.pipeline.PipelineComponentInfoInitializer;
 import org.apache.cocoon.generation.Generator;
@@ -39,15 +51,7 @@
 import org.apache.cocoon.serialization.Serializer;
 import org.apache.cocoon.spring.configurator.impl.AbstractElementParser;
 import org.apache.cocoon.transformation.Transformer;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionReader;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.core.io.ResourceLoader;
+
 import org.w3c.dom.Element;
 
 /**
@@ -131,8 +135,7 @@
         this.registerComponentInfo(info, registry);
 
         // and finally add avalon bean post processor
-        final RootBeanDefinition beanDef = this.createBeanDefinition(AvalonBeanPostProcessor.class,
"init", true);
-        beanDef.getPropertyValues().addPropertyValue("logger", new RuntimeBeanReference(AvalonUtils.LOGGER_ROLE));
+        final RootBeanDefinition beanDef = createBeanDefinition(AvalonBeanPostProcessor.class,
"init", true);
         beanDef.getPropertyValues().addPropertyValue("context", new RuntimeBeanReference(AvalonUtils.CONTEXT_ROLE));
         beanDef.getPropertyValues().addPropertyValue("configurationInfo", new RuntimeBeanReference(ConfigurationInfo.class.getName()));
         beanDef.getPropertyValues().addPropertyValue("resourceLoader", resourceLoader);
@@ -162,12 +165,12 @@
      */
     protected void addLogger(BeanDefinitionRegistry registry,
                              String                 loggerCategory) {
-        final RootBeanDefinition beanDef = createBeanDefinition(AvalonLoggerFactoryBean.class,
null, false);
+        final RootBeanDefinition beanDef = createBeanDefinition(LoggerFactoryBean.class,
"init", false);
         if (loggerCategory != null) {
             beanDef.getPropertyValues().addPropertyValue("category", loggerCategory);
         }
 
-        register(beanDef, AvalonUtils.LOGGER_ROLE, registry);
+        register(beanDef, LoggerUtils.LOGGER_ROLE, registry);
     }
 
     public void createConfig(ConfigurationInfo      info,

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java?rev=587720&r1=587719&r2=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
Tue Oct 23 17:47:26 2007
@@ -18,12 +18,16 @@
  */
 package org.apache.cocoon.core.container.spring.avalon;
 
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.excalibur.source.SourceResolver;
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.core.io.ResourceLoader;
 import org.springframework.web.context.WebApplicationContext;
+
+import org.apache.cocoon.core.container.spring.logger.ChildLoggerFactoryBean;
+import org.apache.cocoon.core.container.spring.logger.LoggerUtils;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
+
 import org.w3c.dom.Element;
 
 /**
@@ -39,36 +43,37 @@
     protected void addContext(Element element, BeanDefinitionRegistry registry) {
         // we get the uriPrefix from the configuration
         final String uriPrefix = element.getAttribute("uriPrefix");
-        RootBeanDefinition beanDefinition = this.createBeanDefinition(AvalonSitemapContextFactoryBean.class,
-                                                                      "init",
-                                                                      false);
+        RootBeanDefinition beanDefinition = createBeanDefinition(AvalonSitemapContextFactoryBean.class,
+                                                                 "init",
+                                                                 false);
         beanDefinition.getPropertyValues().addPropertyValue("uriPrefix", uriPrefix);
-        this.register(beanDefinition, AvalonUtils.CONTEXT_ROLE, registry);
+        register(beanDefinition, AvalonUtils.CONTEXT_ROLE, registry);
     }
 
     /**
      * Add the logger bean.
+     *
      * @param registry       The bean registry.
      * @param loggerCategory The optional category for the logger.
      */
     protected void addLogger(BeanDefinitionRegistry registry,
                              String                 loggerCategory) {
-        final RootBeanDefinition beanDef = this.createBeanDefinition(AvalonChildLoggerFactoryBean.class,
"init", false);
+        final RootBeanDefinition beanDef = createBeanDefinition(ChildLoggerFactoryBean.class,
"init", false);
         if (loggerCategory != null) {
             beanDef.getPropertyValues().addPropertyValue("category", loggerCategory);
         }
-        this.register(beanDef, AvalonUtils.LOGGER_ROLE, registry);
+        register(beanDef, LoggerUtils.LOGGER_ROLE, registry);
     }
 
     /**
-     * @see org.apache.cocoon.core.container.spring.avalon.BridgeElementParser#readConfiguration(java.lang.String,
org.springframework.core.io.ResourceLoader)
+     * @see BridgeElementParser#readConfiguration(String, ResourceLoader)
      */
     protected ConfigurationInfo readConfiguration(String location, ResourceLoader resourceLoader)
     throws Exception {
         WebApplicationContext parentContext = WebAppContextUtils.getCurrentWebApplicationContext();
-        return ConfigurationReader.readSitemap((ConfigurationInfo)parentContext.getBean(ConfigurationInfo.class.getName()),
+        return ConfigurationReader.readSitemap((ConfigurationInfo) parentContext.getBean(ConfigurationInfo.class.getName()),
                                                location,
-                                               new SourceResourceLoader(resourceLoader, (SourceResolver)parentContext.getBean(SourceResolver.ROLE)));
+                                               new SourceResourceLoader(resourceLoader, (SourceResolver)
parentContext.getBean(SourceResolver.ROLE)));
     }
 
     protected String getConfigurationLocation() {

Copied: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/ChildLoggerFactoryBean.java
(from r586658, cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/ChildLoggerFactoryBean.java?p2=cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/ChildLoggerFactoryBean.java&p1=cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java&r1=586658&r2=587720&rev=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonChildLoggerFactoryBean.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/ChildLoggerFactoryBean.java
Tue Oct 23 17:47:26 2007
@@ -14,9 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.core.container.spring.avalon;
+package org.apache.cocoon.core.container.spring.logger;
 
-import org.apache.avalon.framework.logger.Logger;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeansException;
@@ -26,59 +25,54 @@
 import org.springframework.beans.factory.HierarchicalBeanFactory;
 
 /**
- * Spring factory bean to setup a child Avalon logger.
+ * Spring factory bean to setup a child Commons Logging 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());
+public class ChildLoggerFactoryBean extends LoggerFactoryBean
+                                    implements FactoryBean, BeanFactoryAware {
 
     /** The bean factory. */
-    protected BeanFactory beanFactory;
-
-    protected Logger logger;
+    private BeanFactory factory;
 
-    /** The logging category. */
-    protected String category;
 
-    
-    public void setCategory(String category) {
-        this.category = category;
+    public ChildLoggerFactoryBean() {
+        // Child logger has no default category: uses parent's category.
+        setCategory(null);
     }
 
     /**
-     * @see BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     * @see BeanFactoryAware#setBeanFactory(BeanFactory)
      */
     public void setBeanFactory(BeanFactory factory) throws BeansException {
-        this.beanFactory = factory;
+        this.factory = factory;
     }
 
-    protected void init() throws Exception {
-        // get parent factory
-        final BeanFactory parentFactory = ((HierarchicalBeanFactory) this.beanFactory).getParentBeanFactory();
-        final Logger parentLogger = (Logger) parentFactory.getBean(AvalonUtils.LOGGER_ROLE);
-        if (this.category == null) {
-            this.logger = parentLogger;
-        } else {
-            this.logger = parentLogger.getChildLogger(this.category);
-        }
+    public void init() {
+        final BeanFactory parent = ((HierarchicalBeanFactory) this.factory).getParentBeanFactory();
+
+        // Construct full category
+        final LoggerFactoryBean bean = (LoggerFactoryBean) parent.getBean("&" + LoggerUtils.LOGGER_ROLE);
+        setCategory(LoggerUtils.getChildCategory(bean, getCategory()));
+
+        // Initialize logger
+        setLogger(LogFactory.getLog(getCategory()));
     }
 
     /**
-     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     * @see FactoryBean#getObject()
      */
     public Object getObject() throws Exception {
-        return this.logger;
+        final BeanFactory parent = ((HierarchicalBeanFactory) this.factory).getParentBeanFactory();
+        return LoggerUtils.getChildLogger(parent, getCategory());
     }
 
     /**
      * @see org.springframework.beans.factory.FactoryBean#getObjectType()
      */
     public Class getObjectType() {
-        return Logger.class;
+        return Log.class;
     }
 
     /**

Copied: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java
(from r586658, cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java?p2=cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java&p1=cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java&r1=586658&r2=587720&rev=587720&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonLoggerFactoryBean.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java
Tue Oct 23 17:47:26 2007
@@ -14,45 +14,62 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.core.container.spring.avalon;
+package org.apache.cocoon.core.container.spring.logger;
 
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.cocoon.util.avalon.CLLoggerWrapper;
+import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.FactoryBean;
 
 /**
- * Spring factory bean to setup the Avalon logger.
+ * Spring factory bean to setup the Commons Logging logger with specified
+ * category.
+ *
+ * <p>If category was not set, default category 'cocoon' is used.
  *
  * @since 2.2
  * @version $Id$
  */
-public class AvalonLoggerFactoryBean implements FactoryBean {
+public class LoggerFactoryBean implements FactoryBean {
 
     /** The logging category. */
-    protected String category = "cocoon";
+    private String category = "cocoon";
+
+    /** The log instance */
+    private Log logger;
 
 
+    public String getCategory() {
+        return this.category;
+    }
+    
     public void setCategory(String category) {
         this.category = category;
     }
 
+    protected void setLogger(Log logger) {
+        this.logger = logger;
+    }
+
+    public void init() {
+        setLogger(LogFactory.getLog(this.category));
+    }
+
     /**
-     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     * @see FactoryBean#getObject()
      */
     public Object getObject() throws Exception {
-        return new CLLoggerWrapper(LogFactory.getLog(this.category));
+        return this.logger;
     }
 
     /**
-     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     * @see FactoryBean#getObjectType()
      */
     public Class getObjectType() {
-        return Logger.class;
+        return Log.class;
     }
 
     /**
-     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     * @see FactoryBean#isSingleton()
      */
     public boolean isSingleton() {
         return true;

Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java?rev=587720&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java
(added)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java
Tue Oct 23 17:47:26 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.core.container.spring.logger;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.BeanFactory;
+
+import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
+
+/**
+ * Commons Logging logger utilities.
+ *
+ * @since 2.2
+ * @version $Id$
+ */
+public class LoggerUtils {
+
+    /** Bean name for the logger factory returning commons logging Log. */
+    public static final String LOGGER_ROLE = "org.apache.cocoon.core.container.spring.logger.Log";
+
+    /**
+     * Create a child logger based on the logger configured in the Spring bean factory.
+     *
+     * @param factory Current Spring bean factory
+     * @param category Desired logger sub category
+     * @return Logger for the child category of current bean factory configured logger.
+     */
+    public static Log getChildLogger(BeanFactory factory, String category) {
+        LoggerFactoryBean parent = (LoggerFactoryBean) factory.getBean("&" + LoggerUtils.LOGGER_ROLE);
+        return getChildLogger(parent, category);
+    }
+
+    /**
+     * @deprecated 
+     */
+    public static Log getChildLogger(ServiceManager manager, String category) throws ServiceException
{
+        LoggerFactoryBean parent = (LoggerFactoryBean) manager.lookup("&" + LoggerUtils.LOGGER_ROLE);
+        return getChildLogger(parent, category);
+    }
+
+    private static Log getChildLogger(LoggerFactoryBean parent, String category) {
+        return LogFactory.getLog(getChildCategory(parent, category));
+    }
+
+    static String getChildCategory(LoggerFactoryBean parent, String category) {
+        if (category != null && category.length() > 0) {
+            return parent.getCategory() + "." + category;
+        }
+
+        return parent.getCategory();
+    }
+}

Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/logger/LoggerUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date



Mime
View raw message