[jdom-interest] Code submision: JDOM2 the dual tree implementation...

Jason Hunter jhunter at collab.net
Tue Nov 28 13:14:44 PST 2000


James Strachan wrote:
> I'd say that validation is a complex area. Some may want to 
> validate as they build; never allowing an incorrect data structure 
> to ever be built. 

That'd be pretty hard to enforce.  To build a correct document structure
you have to build the document in pieces, and those pieces won't be
valid.  Consider adding elements to an element that requires three
children.  You're not valid until you've added the third.  Do you want
it to raise an exception after you've added just one?  Of course not. 
Do you want to require all three elts be added at once?  Of course not
-- to do so would make JDOM extremely unfriendly to use.

> Validator interface or abstract base class which is a property 
> of Document (for use in doubly linked trees) 

If validation is a property of Document, then elements are tied to
document (bad) or elements have to be imported to a document (bad) or
element have to be background-checked when added to a document (bad for
efficiency, plus impossible with a singly linked tree).

> 1) singly linked trees - have no reference to the owning document 

Thinking more about singly linked trees, with such a design I think that
while it's possible to make the attribs/pis/comments/etc immutable, it's
not possible to make Element immutable.  Assuming Element doesn't know
about its parent (because it's singly linked) that means you'll open up
the possibility of having the same Element on the same tree at two
different points.  That's extremely undesirable, because it allows the
document to have loops and that makes output, validation, and any other
action on the document much more difficult.

I think elements need to be mutable and mutable elements need to keep
track of parentage.  So a singly linked tree would be only somewhat
singly linked.

-jh-



More information about the jdom-interest mailing list