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 2007/10/11 21:05:23 UTC

svn commit: r583919 - in /cocoon/branches/cocoon-2.2: cocoon-sitemap-components/cocoon-sitemap-components-1.0.0-RC2/src/main/java/org/apache/cocoon/components/source/impl/ cocoon-sitemap-impl/cocoon-sitemap-impl-1.0.0-RC2/src/main/java/org/apache/cocoo...

Author: gkossakowski
Date: Thu Oct 11 12:05:22 2007
New Revision: 583919

URL: http://svn.apache.org/viewvc?rev=583919&view=rev
Log:
Moved management of ObjectModel to cocoon: protocol if it's used. This fixes various errors with disappearing values from OM when cocoon: protocol is used.
The side-effect of this hack is that values could be visible outside their scope in some rare cases. I haven't found any good way to avoid it due to complicated flow in SitemapSource.

Modified:
    cocoon/branches/cocoon-2.2/cocoon-sitemap-components/cocoon-sitemap-components-1.0.0-RC2/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java
    cocoon/branches/cocoon-2.2/cocoon-sitemap-impl/cocoon-sitemap-impl-1.0.0-RC2/src/main/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java

Modified: cocoon/branches/cocoon-2.2/cocoon-sitemap-components/cocoon-sitemap-components-1.0.0-RC2/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java
URL: http://svn.apache.org/viewvc/cocoon/branches/cocoon-2.2/cocoon-sitemap-components/cocoon-sitemap-components-1.0.0-RC2/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java?rev=583919&r1=583918&r2=583919&view=diff
==============================================================================
--- cocoon/branches/cocoon-2.2/cocoon-sitemap-components/cocoon-sitemap-components-1.0.0-RC2/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java (original)
+++ cocoon/branches/cocoon-2.2/cocoon-sitemap-components/cocoon-sitemap-components-1.0.0-RC2/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java Thu Oct 11 12:05:22 2007
@@ -26,11 +26,12 @@
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.ResourceNotFoundException;
-import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
 import org.apache.cocoon.components.source.util.SourceUtil;
+import org.apache.cocoon.el.objectmodel.ObjectModel;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
@@ -99,6 +100,9 @@
 
     private String mimeType;
 
+    //if we touched (marked) new OM we will need to do a clean up work
+    boolean touchedOM = false;
+
     /**
      * Construct a new object
      */
@@ -208,6 +212,17 @@
         } catch (Exception e) {
             throw new SourceException("Exception during processing of " + this.systemId, e);
         } finally {
+            if (touchedOM) {
+                //Because of complicated flow of this source it must maintain the cleaness of OM on its own
+                ObjectModel newObjectModel;
+                try {
+                    newObjectModel = (ObjectModel)manager.lookup(ObjectModel.ROLE);
+                } catch (ServiceException e) {
+                    throw new RuntimeException("Couldn't look up Object Model", e);
+                }
+                newObjectModel.cleanupLocalContext();
+                touchedOM = false;
+            }
             // Unhide wrapped environment output stream
             this.environment.setOutputStream(null);
             this.needsRefresh = true;
@@ -266,6 +281,12 @@
             this.pipelineDescription = this.processor.buildPipeline(this.environment);
             this.environment.setURI(this.pipelineDescription.prefix, this.pipelineDescription.uri);
 
+            //Because of complicated flow of this source it must maintain the cleaness of OM on its own
+            ObjectModel newObjectModel = (ObjectModel)manager.lookup(ObjectModel.ROLE);
+            newObjectModel.markLocalContext();
+            touchedOM = true;
+            manager.release(newObjectModel);
+
             String redirectURL = this.environment.getRedirectURL();
             if (redirectURL == null) {
 
@@ -354,6 +375,17 @@
         } catch (Exception e) {
             throw new SAXException("Exception during processing of " + this.systemId, e);
         } finally {
+            if (touchedOM) {
+                //Because of complicated flow of this source it must maintain the cleaness of OM on its own
+                ObjectModel newObjectModel;
+                try {
+                    newObjectModel = (ObjectModel)manager.lookup(ObjectModel.ROLE);
+                } catch (ServiceException e) {
+                    throw new SAXException("Couldn't look up Object Model", e);
+                }
+                newObjectModel.cleanupLocalContext();
+                touchedOM = false;
+            }
             this.needsRefresh = true;
         }
     }

Modified: cocoon/branches/cocoon-2.2/cocoon-sitemap-impl/cocoon-sitemap-impl-1.0.0-RC2/src/main/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java
URL: http://svn.apache.org/viewvc/cocoon/branches/cocoon-2.2/cocoon-sitemap-impl/cocoon-sitemap-impl-1.0.0-RC2/src/main/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java?rev=583919&r1=583918&r2=583919&view=diff
==============================================================================
--- cocoon/branches/cocoon-2.2/cocoon-sitemap-impl/cocoon-sitemap-impl-1.0.0-RC2/src/main/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java (original)
+++ cocoon/branches/cocoon-2.2/cocoon-sitemap-impl/cocoon-sitemap-impl-1.0.0-RC2/src/main/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java Thu Oct 11 12:05:22 2007
@@ -231,7 +231,11 @@
         final String sitemapObjectModelPathPrefix = "sitemap";
         final String sitemapObjectModelNamedPathPrefix = sitemapObjectModelPathPrefix + "/$named$";
         
-        newObjectModel.markLocalContext();
+        //if cocoon: protocol is used the isBuildingPipelineOnly() is true that means pipeline going to be set up 
+        //but not executed at the same time therefore it must be cocoon: protocol that takes responsibility for 
+        //maintaining OM's cleaness 
+        if (!isBuildingPipelineOnly())
+            newObjectModel.markLocalContext();
         
         this.mapStack.add(map);
 
@@ -294,7 +298,11 @@
         Object name = this.mapToName.get(map);
         this.mapToName.remove(map);
         this.nameToMap.remove(name);
-        this.newObjectModel.cleanupLocalContext();
+        //if cocoon: protocol is used the isBuildingPipelineOnly() is true that means pipeline going to be set up 
+        //but not executed at the same time therefore it must be cocoon: protocol that takes responsibility for 
+        //maintaining OM's cleaness 
+        if (!isBuildingPipelineOnly())
+            this.newObjectModel.cleanupLocalContext();
     }
 
     /**