Re: DOMWriter proposed change

Jacob Kjome <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
At 02:03 PM 10/1/2003 -0600, you wrote:
>To: [email protected]
>Subject: [Barracuda] DOMWriter proposed change
>
>Hi folks,
>
>Jake just sent an email mentioning proposed changes to DOMLoader that 
>triggered my memory about a change I was thinking of making to DOMWriter 
>and DefaultDOMWriter.
>
>Presently the DOMWriter interface provides various versions of a write() 
>method (each for different output types). However DOMWriter does not 
>provide any explanation (in the comments) as to whether or not the 
>implementing class must close the output objects or not. DefaultDOMWriter 
>solves this by providing its own "leaveWriterOpen" option that controls 
>this behavior.
>
>My proposal is that we remove the "leaveWriterOpen" option from 
>DefaultDOMWriter and provide eplanation in the comments of DOMWriter that 
>implementing class MUST NOT close the output. It should be stated clearly 
>that it is the responsibility of the class(es) using the DOMWriter to 
>manually close any output streams.

Hmm.... I kind of agree with this in principal, but I'm not sure it will 
make matters any easier for people.  It is just more gruntwork.


>My thinking behind this is that since a DOMWriter does not open (create) 
>the output stream, it should therefore also not close it. It should simply 
>map input in the form of DOM Nodes to the output.

The problem is that main use-case for the DefaultDOMWriter is...

new DefaultDOMWriter().write(dom, vec.getResponse());

Here we send the response object to the writer and let the DOMWriter open 
up the writer or output stream associated with the response.  Since the 
DOMWriter opens it, it seems like it should close it.  It is also much less 
klunky than....

new DefaultDOMWriter().write(dom, vec.getResponse());
vec.getResponse().getWriter().close();

Actually, would we close the writer or output stream here?  It all depends 
on what goes on internally in the DOMWriter implementation.

>Any objections to this change? This shouldn't affect any users unless they 
>are using DefaultDOMWriter or the DOMWriter interface on their own. Is 
>anyone using these classes directly in their code? To make the change I 
>would have to make sure I find every instance where DefaultDOMWriter is 
>used within Barracuda and make sure it does not expect the output stream 
>to be automatically closed (adding a manual close where necessary); this 
>shouldn't be too hard.

Hmm... not too hard, but I'm not sure it gains us anything.  We could even 
document that it is the responsibility of the implementation to decide how 
it deals with opening and closing of writers and output streams.

I'd like to hear what Christian has to say about this since he wrote the 
DefaultDOMWriter originally and came up with the concept of the 
setLeaveWriterOpen(boolean) method.  I suspect the reason it was done this 
way was because it is generally the rare case where one would want to 
actually leave the writer or output steam open after the call to the 
write() method.

I'm not saying I'm completely opposed to this, just skeptical that it would 
be of benefit.  I'd definitely like to hear more discussion on the topic.

Jake

>Thanks,
>-shawn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.