Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Subclassing Element

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Marc Ramsey" <marc AT ranlog.com>
  • To: <xom-interest AT lists.ibiblio.org>, "Elliotte Rusty Harold" <elharo AT metalab.unc.edu>
  • Cc:
  • Subject: Re: [XOM-interest] Subclassing Element
  • Date: Wed, 10 Sep 2003 16:27:38 -0700

> >NodeFactory provides a very convenient mechanism for building documents
> >using application-specific subclasses of Element. Two Element/Node
methods
> >which I'd like to override to create usable subclasses, detach() and
copy(),
> >are currently declared final. Is there any possibility that these can be
> >changed to non-final in a future release?
> >
>
> You're going to have to provide a convincing use-case for that if you
> want me to consider it.

In my particular case, I'm creating subclasses of Element to build indices
of id attributes on subtrees, and to provide other functionality, like
accessors for non-string Attribute values. I could do this by using a
parallel model tree structure where each node references the corresponding
Element, but subclassing Element is quite a bit simpler.

The API documentation for NodeFactory states that:

Subclassing this class allows builders to produce instance of subclasses
(for example, HTMLElement) instead of the base classes.

The definition of Element.copy() is:

public final Node copy() {
return new Element(this);
}

Clearly, any time an element is copied, any subclasses of Element created
via a NodeFactory subclass will be replaced by a generic Element. For
instance, calling copy() on a Document will always result in a document
built from Elements. Obviously, I could subclass Document, and add myCopy
methods to my subclasses. But, if a future release of XOM uses copy() in an
unanticipated circumstance (as in CanonicalXMLSerializer), it may cause
problems.

I'd like to override the detach() method primarily to allow clean management
of subtree indices stored within Element subclasses.

Thanks,
Marc





Archive powered by MHonArc 2.6.24.

Top of Page