jeremy 02/03/22 05:14:55 Modified: src/scratchpad/src/org/apache/cocoon/transformation SourceWritingTransformer.java Log: cleaned up error handling Revision Changes Path 1.3 +21 -9 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/SourceWritingTransformer.java Index: SourceWritingTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/SourceWritingTransformer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SourceWritingTransformer.java 14 Mar 2002 22:12:00 -0000 1.2 +++ SourceWritingTransformer.java 22 Mar 2002 13:14:55 -0000 1.3 @@ -274,9 +274,6 @@ this.message = "The src attribute doesn't resolve to a writeable source"; this.wsource = (WriteableSource)this.source; this.exists = this.wsource.exists(); - - this.message = "Could not open the source for writing"; - this.os = this.wsource.getOutputStream(); // has a Serializer been specified? String local_serializer = a.getValue("",SWT_SERIALIZER_ATTRIBUTE); @@ -286,6 +283,8 @@ this.message = "that Serializer does not exist"; ComponentSelector selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector"); this.ch = (Serializer)selector.select(this.serializer_name); + this.message = "Could not open the source for writing"; + this.os = this.wsource.getOutputStream(); this.message = "could not write the file"; ((Serializer)this.ch).setOutputStream(this.os); // Is there a way to avoid this casting? this.isSerializer = true; @@ -362,6 +361,10 @@ this.source.recycle(); } } + if (!this.failed) { + this.wsource = null; + } + // Report result String result = (this.failed) ? SWT_RESULT_FAILED : SWT_RESULT_SUCCESS; String action = SWT_ACTION_NONE; @@ -380,7 +383,7 @@ super.startElement(uri, loc, raw, attrs); if (this.message != null && this.failed == true) super.characters(this.message.toCharArray(), 0, this.message.length()); super.endElement(uri, loc, raw); - getLogger().debug("SourceWritingTransformer: Source Written"); + getLogger().debug("Source Written"); } else if (this.ch != null){ this.ch.endElement(uri, loc, raw); } @@ -535,12 +538,21 @@ public void recycle() { if (this.wsource != null) { getLogger().error("cancelled by recycle() method"); - try { - this.wsource.cancel(this.ch); - } catch (Exception e) { - getLogger().error("failed to cancel in recycle() method"); - } + if (this.os != null) { + try { + this.wsource.cancel(this.os); + } catch (Exception e) { + getLogger().error("failed to cancel in recycle() method: OutputStream"); + } + } else if (this.ch != null) { + try { + this.wsource.cancel(this.ch); + } catch (Exception e) { + getLogger().error("failed to cancel in recycle() method: ContentHandler"); + } + } } + if (isSerializer) this.manager.release((Component)this.ch); this.sourceResolver = null; }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]