[jdom-interest] detach() [eg]

Brett McLaughlin brett at newInstance.com
Sun Apr 29 14:43:50 PDT 2001


> Brett McLaughlin wrote:
> >
> > I still want to vocally say that I think detach() is not in line with
the
> > rest of the API; at least not on the element being detached. I still
don't
> > see why removeContent() is not fine.
>
> Because we don't have Document.removeContent(Element)!  So you can't use
> the method for removing a root.

Agreed. I'm not saying that removeContent() solves the Document/root element
problem, or the ISE issue. That's secondary to me at this point. I am
saying, though, that I think detach() on an Element would make me think it
detaches an element from the object detach() is being invoked on. In other
words, I would expect to do Element.detach(theElementToDetach). And then
you're really duplicating removeContent(), so I'd say keep removeContent().

The Document issue is a different one, and can be handled as such when you
move the method to the element parent being detached. Then you use
setRootElement(Element newRoot) to do a detach. And that's not a big issue,
because then you aren't in this case where "does the Document hang around?
What do I do? etc..."

And no, I'm not saying this is optimal either... but I think it's better
than detach(), which feels like a backwards set of semantics to me. Maybe
I've just not hit the use-case that makes me flip my perspective. I wish I
would so I could see your side better ;-)

-Brett

>
> Why don't we have the method?  Because to do so opens up the same kettle
> of fish about well-formedness.
>
> You could propose we add Document.removeContent(Element) but to be
> clear: that doesn't help us avoid the IllegalStateException condition.
>
> You could probably convince me to add Document.removeContent(Element)
> but I'd want it to be in addition to the detach() method on Element
> which I think is necessary to make moving objects simpler.  As I said in
> my previous email, I don't like writing triple-case code block for a
> simple move.  You could think of detach() as a convenience which you
> could avoid if you so chose, just like method chaining.  :-)
>
> -jh-




More information about the jdom-interest mailing list