incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r792831 - in /sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter: Generator.java Serializer.java Transformer.java impl/HtmlGeneratorFactory.java impl/HtmlSerializerFactory.java impl/PipelineImpl.java
Date Fri, 10 Jul 2009 08:34:24 GMT
Author: cziegeler
Date: Fri Jul 10 08:34:23 2009
New Revision: 792831

URL: http://svn.apache.org/viewvc?rev=792831&view=rev
Log:
Pipeline components can be disposed after a pipeline run.

Modified:
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Generator.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Serializer.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Transformer.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlGeneratorFactory.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Generator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Generator.java?rev=792831&r1=792830&r2=792831&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Generator.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Generator.java
Fri Jul 10 08:34:23 2009
@@ -55,4 +55,13 @@
      * Notify the generator that parsing is finished.
      */
     void finished() throws IOException, SAXException;
+
+    /**
+     * Dispose the generator.
+     * This method is always invoked by the rewriter in order to
+     * allow the generator to release any resources etc. After
+     * this method has been called the instance is considered
+     * unusable.
+     */
+    void dispose();
 }

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Serializer.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Serializer.java?rev=792831&r1=792830&r2=792831&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Serializer.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Serializer.java
Fri Jul 10 08:34:23 2009
@@ -32,4 +32,13 @@
      */
     void init(ProcessingContext context, ProcessingComponentConfiguration config)
     throws IOException;
+
+    /**
+     * Dispose the serializer.
+     * This method is always invoked by the rewriter in order to
+     * allow the serializer to release any resources etc. After
+     * this method has been called the instance is considered
+     * unusable.
+     */
+    void dispose();
 }

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Transformer.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Transformer.java?rev=792831&r1=792830&r2=792831&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Transformer.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Transformer.java
Fri Jul 10 08:34:23 2009
@@ -38,4 +38,13 @@
      * @param handler Another transformer or a serializer.
      */
     void setContentHandler(ContentHandler handler);
+
+    /**
+     * Dispose the transformer.
+     * This method is always invoked by the rewriter in order to
+     * allow the transformer to release any resources etc. After
+     * this method has been called the instance is considered
+     * unusable.
+     */
+    void dispose();
 }

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlGeneratorFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlGeneratorFactory.java?rev=792831&r1=792830&r2=792831&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlGeneratorFactory.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlGeneratorFactory.java
Fri Jul 10 08:34:23 2009
@@ -673,5 +673,12 @@
             ioe.initCause(se);
             return ioe;
         }
+
+        /**
+         * @see org.apache.sling.rewriter.Generator#dispose()
+         */
+        public void dispose() {
+            // nothing to do
+        }
     }
 }

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java?rev=792831&r1=792830&r2=792831&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
Fri Jul 10 08:34:23 2009
@@ -210,5 +210,12 @@
                 throws SAXException {
             // not used atm
         }
+
+        /**
+         * @see org.apache.sling.rewriter.Serializer#dispose()
+         */
+        public void dispose() {
+            // nothing to do
+        }
     }
 }

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java?rev=792831&r1=792830&r2=792831&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
Fri Jul 10 08:34:23 2009
@@ -47,6 +47,12 @@
     /** The starting point of the pipeline. */
     private Generator generator;
 
+    /** The transformers. */
+    private Transformer[] transformers;
+
+    /** The end point. */
+    private Serializer serializer;
+
     /** The first component in the pipeline after the generator */
     private ContentHandler firstContentHandler;
 
@@ -76,12 +82,11 @@
         final Transformer[][] rewriters = this.factoryCache.getRewriterTransformers();
 
         final ProcessingComponentConfiguration generatorConfig = config.getGeneratorConfiguration();
-        final Generator generator = this.getPipelineComponent(Generator.class, generatorConfig.getType());
+        this.generator = this.getPipelineComponent(Generator.class, generatorConfig.getType());
         LOGGER.debug("Using generator type {}: {}.", generatorConfig.getType(), generator);
         generator.init(processingContext, generatorConfig);
 
         final int transformerCount = (transformerConfigs == null ? 0 : transformerConfigs.length)
+ rewriters[0].length + rewriters[1].length;
-        final Transformer[] transformers;
         if ( transformerCount > 0 ) {
             // add all pre rewriter transformers
             transformers = new Transformer[transformerCount];
@@ -111,7 +116,7 @@
         }
 
         final ProcessingComponentConfiguration serializerConfig = config.getSerializerConfiguration();
-        final Serializer serializer = this.getPipelineComponent(Serializer.class, serializerConfig.getType());
+        this.serializer = this.getPipelineComponent(Serializer.class, serializerConfig.getType());
         LOGGER.debug("Using serializer type {}: {}.", serializerConfig.getType(), serializer);
         serializer.init(processingContext, serializerConfig);
 
@@ -137,8 +142,6 @@
         final ComponentType component;
         if ( typeClass == Generator.class ) {
             component = (ComponentType)this.factoryCache.getGenerator(type);
-            // we keep the generator
-            this.generator = (Generator)component;
         } else if ( typeClass == Transformer.class ) {
             component = (ComponentType)this.factoryCache.getTransformer(type);
         } else if ( typeClass == Serializer.class ) {
@@ -172,14 +175,30 @@
      * @see org.apache.sling.rewriter.Processor#finished()
      */
     public void finished() throws IOException {
+        IOException ioe = null;
         try {
             this.generator.finished();
         } catch (SAXException se) {
             if ( se.getCause() != null && se.getCause() instanceof IOException )
{
-                throw (IOException)se.getCause();
+                ioe = (IOException)se.getCause();
+            } else {
+                ioe = new IOException("Pipeline exception: " + se.getMessage());
+                ioe.initCause(se);
             }
-            final IOException ioe = new IOException("Pipeline exception.");
-            ioe.initCause(se);
+        }
+        // now dispose component
+        if ( this.generator != null ) {
+            this.generator.dispose();
+        }
+        if ( this.transformers != null ) {
+            for(final Transformer transformer : this.transformers ) {
+                transformer.dispose();
+            }
+        }
+        if ( this.serializer != null ) {
+            this.serializer.dispose();
+        }
+        if ( ioe != null ) {
             throw ioe;
         }
     }



Mime
View raw message