vgritsenko    01/08/14 20:55:22

  Modified:    src/org/apache/cocoon/components/source Tag:
                        cocoon_20_branch SitemapSource.java
  Log:
  exception handling
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.12  +34 -35    
xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java,v
  retrieving revision 1.1.2.11
  retrieving revision 1.1.2.12
  diff -u -r1.1.2.11 -r1.1.2.12
  --- SitemapSource.java        2001/07/29 16:25:01     1.1.2.11
  +++ SitemapSource.java        2001/08/15 03:55:22     1.1.2.12
  @@ -50,7 +50,7 @@
    * Description of a source which is defined by a pipeline.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.11 $ $Date: 2001/07/29 16:25:01 $
  + * @version CVS $Revision: 1.1.2.12 $ $Date: 2001/08/15 03:55:22 $
    */
   
   public final class SitemapSource
  @@ -87,6 +87,9 @@
       /** The redirect <code>Source</code> */
       private Source redirectSource;
   
  +    /** The <code>ProcessingException</code> if unable to get resource */
  +    private ProcessingException exception;
  +
       /**
        * Construct a new object
        */
  @@ -166,8 +169,9 @@
        */
       public InputStream getInputStream()
       throws ProcessingException, IOException {
  -        if ((this.eventPipeline == null || this.pipeline == null) && 
this.redirectSource == null) {
  -            throw new ProcessingException("could not lookup pipeline components.");
  +        // VG: Why exception is not thrown in constructor?
  +        if (this.exception != null) {
  +            throw this.exception;
           }
           SitemapComponentSelector serializerSelector = null;
           Serializer serializer = null;
  @@ -183,18 +187,14 @@
               return new ByteArrayInputStream(os.toByteArray());
           } catch (ComponentException cme) {
               throw new ProcessingException("could not lookup pipeline components", 
cme);
  +        } catch (ProcessingException e) {
  +            throw e;
           } catch (Exception e) {
  -            throw new ProcessingException("Exception during processing of 
"+this.systemId, e);
  +            throw new ProcessingException("Exception during processing of " + 
this.systemId, e);
           } finally {
               if (serializer != null) serializerSelector.release(serializer);
               if (serializerSelector != null) 
this.manager.release(serializerSelector);
  -            if (this.eventPipeline != null) 
this.manager.release(this.eventPipeline);
  -            if (this.pipeline != null) this.manager.release(this.pipeline);
  -            this.eventPipeline = null;
  -            this.pipeline = null;
  -            this.lastModificationDate = 0;
  -            this.environment.reset();
  -            this.redirectSource = null;
  +            reset();
           }
       }
   
  @@ -226,13 +226,7 @@
        * and content length.
        */
       public void refresh() {
  -        if (eventPipeline != null) this.manager.release(eventPipeline);
  -        if (pipeline != null) this.manager.release(pipeline);
  -        this.lastModificationDate = 0;
  -        this.eventPipeline = null;
  -        this.pipeline = null;
  -        this.environment.reset();
  -        redirectSource = null;
  +        reset();
           try {
               // initialize the pipelines
               this.eventPipeline = 
(EventPipeline)this.manager.lookup(EventPipeline.ROLE);
  @@ -278,14 +272,12 @@
               } finally {
                   this.environment.popURI();
               }
  +        } catch (ProcessingException e) {
  +            reset();
  +            this.exception = e;
           } catch (Exception e) {
  -            e.printStackTrace();
  -            if (this.eventPipeline != null) 
this.manager.release(this.eventPipeline);
  -            if (this.pipeline != null) this.manager.release(this.pipeline);
  -            this.eventPipeline = null;
  -            this.pipeline = null;
  -            this.redirectSource = null;
  -            this.environment.reset();
  +            reset();
  +            this.exception = new ProcessingException("Could not get sitemap source 
" + this.systemId, e);
           }
       }
   
  @@ -304,8 +296,8 @@
        */
       public void stream(XMLConsumer consumer)
       throws ProcessingException, SAXException, IOException {
  -        if ((this.eventPipeline == null || this.pipeline == null) && 
this.redirectSource == null) {
  -            throw new ProcessingException("could not lookup pipeline components.");
  +        if (this.exception != null) {
  +            throw this.exception;
           }
           try {
   
  @@ -322,16 +314,12 @@
               }
           } catch (ComponentException cme) {
               throw new ProcessingException("could not lookup pipeline components", 
cme);
  +        } catch (ProcessingException e) {
  +            throw e;
           } catch (Exception e) {
  -            throw new ProcessingException("Exception during processing of 
"+this.systemId, e);
  +            throw new ProcessingException("Exception during processing of " + 
this.systemId, e);
           } finally {
  -            if (this.eventPipeline != null) 
this.manager.release(this.eventPipeline);
  -            if (this.pipeline != null) this.manager.release(this.pipeline);
  -            this.eventPipeline = null;
  -            this.pipeline = null;
  -            this.lastModificationDate = 0;
  -            this.environment.reset();
  -            this.redirectSource = null;
  +            reset();
           }
       }
   
  @@ -341,6 +329,17 @@
       public void stream(ContentHandler contentHandler)
       throws ProcessingException, SAXException, IOException {
           this.stream(new ContentHandlerWrapper(contentHandler));
  +    }
  +
  +    private void reset() {
  +        if (this.eventPipeline != null) this.manager.release(this.eventPipeline);
  +        if (this.pipeline != null) this.manager.release(this.pipeline);
  +        this.eventPipeline = null;
  +        this.pipeline = null;
  +        this.lastModificationDate = 0;
  +        this.environment.reset();
  +        this.redirectSource = null;
  +        this.exception = null;
       }
   }
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to