You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gk...@apache.org on 2008/03/08 16:14:44 UTC

svn commit: r634984 - in /cocoon/whiteboard/micro/core: cocoon-core/src/main/java/org/apache/cocoon/components/source/ cocoon-core/src/main/java/org/apache/cocoon/components/source/helpers/ cocoon-core/src/main/java/org/apache/cocoon/servlet/ cocoon-co...

Author: gkossakowski
Date: Sat Mar  8 07:14:42 2008
New Revision: 634984

URL: http://svn.apache.org/viewvc?rev=634984&view=rev
Log:
Get rid of all methods involved in mantaining current Sitemap-specific ServiceManager
and current Processor. There is only one ServiceManger and Processor is properly scoped bean so code using it does not need to check wether the current one is used.

This way any references to the Processor could be removed from EnvironmentHelper and from EnvironmentStack which made whole Environment much simpler.

Modified:
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/helpers/DelaySourceRefresher.java
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/IncludeTransformer.java
    cocoon/whiteboard/micro/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
    cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
    cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
    cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java
    cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
    cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentInfo.java

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java Sat Mar  8 07:14:42 2008
@@ -21,10 +21,13 @@
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.cocoon.xml.IncludeXMLConsumer;
 import org.apache.cocoon.xml.dom.DOMBuilder;
 import org.apache.excalibur.source.Source;
+import org.springframework.web.context.support.WebApplicationContextUtils;
 import org.w3c.dom.Document;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -37,17 +40,6 @@
 public abstract class SourceUtil extends org.apache.cocoon.components.source.util.SourceUtil{
 
     /**
-     * Get the current sitemap component manager.
-     * This method returns the current sitemap component manager. This
-     * is the manager that holds all the components of the currently
-     * processed (sub)sitemap.
-     * @deprecated This method will be removed.
-     */
-    static private ServiceManager getSitemapServiceManager() {
-        return EnvironmentHelper.getSitemapServiceManager(); 
-    }
-
-    /**
      * Generates SAX events from the given source.
      *
      * <p><b>NOTE</b>: If the implementation can produce lexical events,
@@ -60,7 +52,7 @@
     static public void toSAX(Source         source,
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
-        toSAX(getSitemapServiceManager(),
+        toSAX(getServiceManager(),
               source, null, handler);
     }
 
@@ -79,7 +71,7 @@
                              String         mimeTypeHint,
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
-        toSAX(getSitemapServiceManager(),
+        toSAX(getServiceManager(),
               source, mimeTypeHint, handler);
     }
 
@@ -139,5 +131,12 @@
         }
 
         return document;
+    }
+    
+    /**
+     * @return the global service manager
+     */
+    static private ServiceManager getServiceManager() {
+        return (ServiceManager)WebAppContextUtils.getCurrentWebApplicationContext().getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
     }
 }

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/helpers/DelaySourceRefresher.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/helpers/DelaySourceRefresher.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/helpers/DelaySourceRefresher.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/helpers/DelaySourceRefresher.java Sat Mar  8 07:14:42 2008
@@ -321,16 +321,10 @@
                 } catch (ContextException e) {
                     throw new CascadingRuntimeException("No context found", e);
                 }
-                Processor processor;
-                try {
-                    processor = (Processor) manager.lookup(Processor.ROLE);
-                } catch (ServiceException e) {
-                    throw new CascadingRuntimeException("No processor found", e);
-                }
 
                 env.startingProcessing();
                 try {
-                    EnvironmentHelper.enterProcessor(processor, env);
+                    EnvironmentHelper.enterProcessor(env);
                 } catch (ProcessingException e) {
                     throw new CascadingRuntimeException("Can not enter processor", e);
                 }
@@ -350,9 +344,6 @@
                 } finally {
                     EnvironmentHelper.leaveProcessor();
                     env.finishingProcessing();
-                    if (manager != null) {
-                        manager.release(processor);
-                    }
                 }
             }
         }

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java Sat Mar  8 07:14:42 2008
@@ -336,7 +336,7 @@
     protected boolean process(Environment environment) throws Exception {
         environment.startingProcessing();
         final int environmentDepth = EnvironmentHelper.markEnvironment();
-        EnvironmentHelper.enterProcessor(this.processor, environment);
+        EnvironmentHelper.enterProcessor(environment);
         try {
             boolean result;
 

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/IncludeTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/IncludeTransformer.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/IncludeTransformer.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/IncludeTransformer.java Sat Mar  8 07:14:42 2008
@@ -31,13 +31,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceValidity;
-import org.springframework.web.context.request.RequestAttributes;
-import org.springframework.web.context.request.RequestContextHolder;
-
 import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.Processor;
 import org.apache.cocoon.caching.CacheableProcessingComponent;
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.components.source.impl.MultiSourceValidity;
@@ -52,7 +46,10 @@
 import org.apache.cocoon.xml.SaxBuffer;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.cocoon.xml.util.NamespacesTable;
-
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceValidity;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
@@ -251,9 +248,6 @@
     /** The {@link Environment} used within parallel threads */
     protected Environment environment;
 
-    /** The {@link Processor} used within parallel threads */
-    private Processor processor;
-
     /** The value to be appended to the caching key. */
     private String key;
 
@@ -318,7 +312,6 @@
         if (this.pipe.parallel) {
             this.attributes = RequestContextHolder.getRequestAttributes();
             this.environment = EnvironmentHelper.getCurrentEnvironment();
-            this.processor = EnvironmentHelper.getCurrentProcessor();
         }
         this.namespaces = new NamespacesTable();
         this.resolver = resolver;
@@ -359,7 +352,6 @@
         // and released their Sources.
         this.resolver = null;
 
-        this.processor = null;
         this.environment = null;
         this.attributes = null;
 
@@ -1088,7 +1080,7 @@
 
                     // Setup this thread's environment
                     RequestContextHolder.setRequestAttributes(attributes);
-                    EnvironmentHelper.enterProcessor(processor, environment);
+                    EnvironmentHelper.enterProcessor(environment);
                     try {
                         element.process(this);
 

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java Sat Mar  8 07:14:42 2008
@@ -329,9 +329,8 @@
         // the processing context stack
         MockEnvironment env = new MockEnvironment();
         env.setObjectModel(this.getObjectModel());
-        Processor processor = new MockProcessor(this.getBeanFactory());
         
-        EnvironmentHelper.enterProcessor(processor, env);
+        EnvironmentHelper.enterProcessor(env);
 
         try {
             ServiceSelector selector = null;

Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java Sat Mar  8 07:14:42 2008
@@ -128,7 +128,7 @@
         InvokeContext context = new InvokeContext();
 
         try {
-            EnvironmentHelper.enterProcessor(this, environment);
+            EnvironmentHelper.enterProcessor(environment);
             final Redirector oldRedirector = context.getRedirector();
             try {
                 context.setRedirector(new ForwardRedirector(environment));

Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java Sat Mar  8 07:14:42 2008
@@ -271,7 +271,7 @@
         // If these components try to access the current processor or the
         // current service manager they must get this one - which is currently
         // in the process of initialization.
-        EnvironmentHelper.enterProcessor(this, env);
+        EnvironmentHelper.enterProcessor(env);
 
         try {
 

Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java Sat Mar  8 07:14:42 2008
@@ -25,6 +25,7 @@
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 
 /**
  * This is the {@link Context} implementation for Cocoon components.
@@ -72,7 +73,7 @@
             }
             return env.getObjectModel();
         } else if ( ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER.equals(key)) {
-            final ServiceManager manager = EnvironmentHelper.getSitemapServiceManager();
+            final ServiceManager manager = getServiceManager();
             if ( manager == null ) {
                 throw new ContextException("Unable to locate " + key + " (No environment available)");
             }
@@ -97,5 +98,12 @@
             }
         }
         return super.get( key );
+    }
+    
+    /**
+     * @return the global service manager
+     */
+    static private ServiceManager getServiceManager() {
+        return (ServiceManager)WebAppContextUtils.getCurrentWebApplicationContext().getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
     }
 }

Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java Sat Mar  8 07:14:42 2008
@@ -26,9 +26,7 @@
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.components.source.util.SourceUtil;
-import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
 import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -192,18 +190,14 @@
      *
      * @throws ProcessingException if processor is null
      */
-    public static void enterProcessor(Processor   processor,
-                                      Environment env)
+    public static void enterProcessor(Environment env)
     throws ProcessingException {
-        if (null == processor) {
-            throw new ProcessingException("Processor is not set.");
-        }
         EnvironmentStack stack = (EnvironmentStack) environmentStack.get();
         if (stack == null) {
             stack = new EnvironmentStack();
             environmentStack.set(stack);
         }
-        stack.pushInfo(new EnvironmentInfo(processor, stack.getOffset(), env));
+        stack.pushInfo(new EnvironmentInfo(stack.getOffset(), env));
         stack.setOffset(stack.size() - 1);
     }
 
@@ -227,14 +221,8 @@
     public static void enterEnvironment(Environment env)
     throws ProcessingException {
         final EnvironmentStack stack = (EnvironmentStack) environmentStack.get();
-        EnvironmentInfo info;
-        if (stack != null && !stack.isEmpty()) {
-            info = stack.getCurrentInfo();
-        } else {
-            throw new ProcessingException("There must be a current processing environment.");
-        }
 
-        stack.pushInfo(new EnvironmentInfo(info.processor, stack.getOffset(), env));
+        stack.pushInfo(new EnvironmentInfo(stack.getOffset(), env));
         stack.setOffset(stack.size() - 1);
     }
 
@@ -288,34 +276,6 @@
         if (stack != null && !stack.empty()) {
             final EnvironmentInfo info = stack.getCurrentInfo();
             return info.environment;
-        }
-        return null;
-    }
-
-    /**
-     * Return the current processor
-     * INTERNAL METHOD. Do not use this, can be removed without warning or deprecation cycle.
-     */
-    public static Processor getCurrentProcessor() {
-        final EnvironmentStack stack = (EnvironmentStack) environmentStack.get();
-        if (stack != null && !stack.isEmpty()) {
-            final EnvironmentInfo info = stack.getCurrentInfo();
-            return info.processor;
-        }
-        return null;
-    }
-
-    /**
-     * Get the current sitemap component manager.
-     * This method return the current sitemap component manager. This
-     * is the manager that holds all the components of the currently
-     * processed (sub)sitemap.
-     * INTERNAL METHOD. Do not use this, can be removed without warning or deprecation cycle.
-     */
-    static public ServiceManager getSitemapServiceManager() {
-        final EnvironmentStack stack = (EnvironmentStack) environmentStack.get();
-        if (stack != null && !stack.isEmpty()) {
-            return (ServiceManager) WebAppContextUtils.getCurrentWebApplicationContext().getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
         }
         return null;
     }

Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentInfo.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentInfo.java?rev=634984&r1=634983&r2=634984&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentInfo.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentInfo.java Sat Mar  8 07:14:42 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.cocoon.environment.internal;
 
-import org.apache.cocoon.Processor;
 import org.apache.cocoon.environment.Environment;
 
 /**
@@ -31,14 +30,11 @@
  */
 public class EnvironmentInfo {
 
-    public final Processor      processor;
     public final int            oldStackCount;
     public final Environment    environment;
 
-    public EnvironmentInfo(Processor   processor, 
-                           int         oldStackCount,
+    public EnvironmentInfo(int         oldStackCount,
                            Environment environment) {
-        this.processor = processor;
         this.oldStackCount = oldStackCount;
         this.environment = environment;
     }