[jdom-interest] Document changes tonight

Jason Hunter jhunter at acm.org
Fri Aug 11 10:02:57 PDT 2000

> No. An entity can't be the root, and can't exists outside the root.

Thanks for the verification, that's how I implemented it.

> >Also: What do people think about making the default Document()
> >constructor public?  It's currently protected, and the logic for not
> >having it public was that every document needed a root -- but then all
> >over the place we call new Document(null) so we can construct the
> >document in pieces like this:
> >
> >new Document(null)
> >  .addContent(new Comment("before"))
> >  .addContent(new Element("root"))
> >  .addContent(new Comment("after"));
> >
> >We shouldn't have a null parameter to the constructor be some sort of
> >secret enabler like this, imho.
> >
> You're right. But I recommend going in the other direction. The
> constructor should throw an exception, probably NullPointerException
> but maybe IllegalArgumentException if it's passed null as a root
> element.

I presume you're following the logic that with JDOM you should only be
able to create valid documents, and that documents must be valid after
all operations, right?  That has an appeal, but it would make creating a
document like the above a real pain.  If the doc you wanted to create
had anything but a single root element (like any comments or PIs) to
ensure the right ordering of objects you'd have to create the contents
in your own list, create a Document with a *dummy* root, and then use
setMixedContent() to replace the contents.  Do we really want it to be
that painful?  Maybe you can propose a less painful solution that gives
this functionality and keeps to the philosophy of "always valid".


More information about the jdom-interest mailing list