cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r497338 - in /cocoon/trunk/blocks: cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/ cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/util/ cocoo...
Date Thu, 18 Jan 2007 08:03:26 GMT
Author: cziegeler
Date: Thu Jan 18 00:03:26 2007
New Revision: 497338

URL: http://svn.apache.org/viewvc?view=rev&rev=497338
Log:
Reduce dependencies to Avalon

Modified:
    cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
    cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
    cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-impl/src/main/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
    cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java

Modified: cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java?view=diff&rev=497338&r1=497337&r2=497338
==============================================================================
--- cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
(original)
+++ cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
Thu Jan 18 00:03:26 2007
@@ -718,13 +718,7 @@
         setupView(scope, cocoon, null);
         // FIXME (SW): should we deprecate this method in favor of PipelineUtil?
         PipelineUtil pipeUtil = new PipelineUtil();
-        try {
-            pipeUtil.contextualize(this.avalonContext);
-            pipeUtil.service(this.manager);
-            pipeUtil.processToStream(uri, bizData, out);
-        } finally {
-            pipeUtil.dispose();
-        }
+        pipeUtil.processToStream(uri, bizData, out);
     }
 
     private void setupView(Scriptable scope, FOM_Cocoon cocoon, FOM_WebContinuation kont)
{

Modified: cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/util/PipelineUtil.java?view=diff&rev=497338&r1=497337&r2=497338
==============================================================================
--- cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
(original)
+++ cocoon/trunk/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
Thu Jan 18 00:03:26 2007
@@ -21,21 +21,16 @@
 import java.io.OutputStream;
 import java.util.Map;
 
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
 import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.components.flow.javascript.JavaScriptFlowHelper;
 import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
+import org.springframework.web.context.WebApplicationContext;
 import org.w3c.dom.Document;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -47,44 +42,7 @@
  *
  * @version $Id$
  */
-public class PipelineUtil implements Contextualizable, Serviceable, Disposable {
-
-    private Context context;
-    private ServiceManager manager;
-    private SourceResolver resolver;
-
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.activity.Disposable#dispose()
-     */
-    public void dispose() {
-        if (this.manager != null) {
-            this.manager.release(this.resolver);
-            this.manager = null;
-            this.resolver = null;
-        }
-    }
-
-    public void contextualize(Context context) throws ContextException {
-        this.context = context;
-
-    }
-
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-        this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
-    }
-
-    /**
-     * Check that this object has been correctly set up.
-     *
-     * @throws IllegalStateException if not already set up.
-     */
-    private void checkSetup() {
-        if (this.manager == null) {
-            throw new IllegalStateException("Instances of " + getClass().getName() +
-                                            " must be setup using either cocoon.createObject()
or cocoon.setupObject().");
-        }
-    }
+public class PipelineUtil {
 
     /**
      * Process a pipeline to a stream.
@@ -96,9 +54,8 @@
      */
     public void processToStream(String uri, Object viewData, OutputStream output)
     throws IOException {
-        checkSetup();
-
-        Map objectModel = ContextHelper.getObjectModel(this.context);
+        final Map objectModel = getObjectModel();
+        final SourceResolver resolver = getSourceResolver();
 
         // Keep the previous view data, if any (is it really necessary?), and set the new
one
         Object oldViewData = FlowHelper.getContextObject(objectModel);
@@ -107,7 +64,7 @@
         Source src = null;
         InputStream input = null;
         try {
-            src = this.resolver.resolveURI("cocoon:/" + uri);
+            src = resolver.resolveURI("cocoon:/" + uri);
             input = src.getInputStream();
             IOUtils.copy(input, output);
         } finally {
@@ -119,10 +76,7 @@
 
             // Restore the previous view data
             FlowHelper.setContextObject(objectModel, oldViewData);
-
-            if (src != null) {
-                this.resolver.release(src);
-            }
+            resolver.release(src);
         }
     }
 
@@ -135,21 +89,19 @@
      */
     public void processToSAX(String uri, Object viewData, ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
-        checkSetup();
+        final Map objectModel = getObjectModel();
+        final SourceResolver resolver = getSourceResolver();
 
-        Map objectModel = ContextHelper.getObjectModel(this.context);
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, JavaScriptFlowHelper.unwrap(viewData));
 
         Source src = null;
         try {
-            src = this.resolver.resolveURI("cocoon:/" + uri);
+            src = resolver.resolveURI("cocoon:/" + uri);
             SourceUtil.toSAX(src, handler);
         } finally {
             FlowHelper.setContextObject(objectModel, oldViewData);
-            if (src != null) {
-                this.resolver.release(src);
-            }
+            resolver.release(src);
         }
     }
 
@@ -161,22 +113,37 @@
      * @return the document
      */
     public Document processToDOM(String uri, Object viewData) throws ProcessingException,
SAXException, IOException  {
-        checkSetup();
-
-        Map objectModel = ContextHelper.getObjectModel(this.context);
+        final Map objectModel = getObjectModel();
+        final SourceResolver resolver = getSourceResolver();
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, JavaScriptFlowHelper.unwrap(viewData));
 
         Source src = null;
 
         try {
-            src = this.resolver.resolveURI("cocoon:/" + uri);
+            src = resolver.resolveURI("cocoon:/" + uri);
             return SourceUtil.toDOM(src);
         } finally {
             FlowHelper.setContextObject(objectModel, oldViewData);
-            if (src != null) {
-                this.resolver.release(src);
-            }
+            resolver.release(src);
         }
+    }
+
+    /**
+     * Helper method to get the current source resolver.
+     */
+    protected static SourceResolver getSourceResolver() {
+        final WebApplicationContext webAppContext = WebAppContextUtils.getCurrentWebApplicationContext();
+        return (SourceResolver)webAppContext.getBean(SourceResolver.ROLE);        
+    }
+
+    /**
+     * Helper method to get the current object model.
+     */
+    protected static Map getObjectModel() {
+        final WebApplicationContext webAppContext = WebAppContextUtils.getCurrentWebApplicationContext();
+        final ProcessInfoProvider infoProvider =
+            (ProcessInfoProvider)webAppContext.getBean(ProcessInfoProvider.ROLE);
+        return infoProvider.getObjectModel();
     }
 }

Modified: cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-impl/src/main/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-impl/src/main/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java?view=diff&rev=497338&r1=497337&r2=497338
==============================================================================
--- cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-impl/src/main/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
(original)
+++ cocoon/trunk/blocks/cocoon-javaflow/cocoon-javaflow-impl/src/main/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java
Thu Jan 18 00:03:26 2007
@@ -130,16 +130,12 @@
     }
 
     public void processPipelineTo( String uri, Object bizdata, OutputStream out ) {
-        CocoonContinuationContext context = getContext();
         PipelineUtil pipeUtil = new PipelineUtil();
         try {
-            pipeUtil.contextualize(context.getAvalonContext());
-            pipeUtil.service(context.getServiceManager());
             pipeUtil.processToStream(uri, bizdata, out);
         } catch (Exception e) {
             throw new CascadingRuntimeException("Cannot process pipeline to '" + uri + "'",
e);
         } finally {
-            pipeUtil.dispose();
         }
     }
 

Modified: cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java?view=diff&rev=497338&r1=497337&r2=497338
==============================================================================
--- cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
(original)
+++ cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/main/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
Thu Jan 18 00:03:26 2007
@@ -756,13 +756,7 @@
         throws Exception {
         setupView(scope, cocoon, null);
         PipelineUtil pipeUtil = new PipelineUtil();
-        try {
-            pipeUtil.contextualize(this.avalonContext);
-            pipeUtil.service(this.manager);
-            pipeUtil.processToStream(uri, bizData, out);
-        } finally {
-            pipeUtil.dispose();
-        }
+        pipeUtil.processToStream(uri, bizData, out);
     }
     
     private void setupView(Scriptable scope,



Mime
View raw message