Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Subclassing and check methods

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Bradley S. Huffman" <hip AT cs.okstate.edu>
  • To: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Subclassing and check methods
  • Date: Fri, 12 Mar 2004 09:37:52 -0600

Elliotte Rusty Harold writes:

> At 11:21 PM -0600 3/11/04, Bradley S. Huffman wrote:
>
> > public String getLocalName() {
> > return myLocalName;
> > }
>
>
> That wouldn't work. The getter methods remain final and cannot be
> overridden.

Yes, I was confused with the "accessor/mutator" usage, and it was late :-)

But one thing I've been pondering for a while is whether XML models should
have
setters like setLocalName, and now I have a use-case where it may cause a
problem.

If I subclass Element and override checkInsertChild to check that elements
with local name "foo" can only contain children with local name "bar", what
do I do about setLocalName? Think about the case of replacing nodes in a
document. Obviously I can create a "foo" element by recycling a existing
element and using setLocalName, skipping the checks in checkInsertChild
completely.

At first I thought this would be a odd-ball case that would rarely happen. But
with all the "performance" threads on the JDOM mailing list, I can see people
recommending ("in the name of performance") that users do a "fast" replace
with
setLocalName/setNamespaceURI instead of actually removing a node from the
document, adding it's children to a newly constructed node, and inserting the
new node back into the document.

Then again this may be something that can be handled with a note in the
javadocs.

Brad




Archive powered by MHonArc 2.6.24.

Top of Page