[jdom-interest] detach() [eg]

Scott Means smeans at moonlightideas.com
Sun Apr 22 07:39:08 PDT 2001


> Date: Sat, 21 Apr 2001 09:11:50 -0400
> To: jdom-interest at jdom.org
> From: Elliotte Rusty Harold <elharo at metalab.unc.edu>
> Subject: Re: [jdom-interest] detach() [eg]
> 
> I propose the following compromise:
> 
> 1. If detach() is called on the root element, then an exception is thrown.
> 
> 2. We add a method to Document that detaches and replaces the root 
> element with a different element; e.g.
Just to add my $.02, I agree with Rusty. Throwing an exception is the right
thing to do. The only minor modification I would suggest is that rather
than adding a new method, the existing setRootElement() method be changed
to:
    Element setRootElement(Element rootElement)

Instead of returning a reference to the document object, it could return
the old root element. This metaphor should be familiar to anybody who's
done low-level graphics programming on Windows (most GDI calls work this
way.) I agree that the ability to chain method calls is nice (sometimes),
but I see returning the parent object as a convenience feature when the
method would otherwise return void. As for the other Document calls that
return the Document object (setDocType, setMixedContent, and
setProcessingInstructions), maybe they should return the previous object in
question as well.

Maybe that was more than $.02, but without my Sunday-morning rant, my whole
week is shot! :-)

=======================================
Scott Means (smeans at moonlightideas.com)





More information about the jdom-interest mailing list