[jdom-interest] Making setMixedContent appear atomic
Jason Hunter
jhunter at collab.net
Mon Apr 16 19:19:10 PDT 2001
> So we would force people to code their own transaction
> try {
> List backup = tranferElement.getMixedContent();
> //duplicate the data
> tranferElement.setMixedContent(createPayCheque());
> } catch (IllegalAddException iae) {
> //restore the duplicate.
> // Oops, better save the original doc, we might need it.
> // save the original document
> }
>
> Somehow that doesn't seem to bad.
That's not enough though. The setMixedContent() call affects parentage,
removing exisitng parents of old content and adding new parents to new
content. If the above was all that's necessary, writing it atomic
wouldn't be hard.
One thing we're forgetting here is I already implemented the "atomic"
behavior, before this discussion ensued. It's really no less efficient
than before, and the code is reasonable.
The only issue with the impl that makes this debate worthwhile is how
the "atomic" code might affect subclasses where addContent() does
something different with parentage. My short answer: tell people
subclassing Element/Document to override setMixedContent(). :-) I
suppose if they were changing addContent() in such a way that changed
parentage behavior, they'd probably be overriding it anyway.
-jh-
More information about the jdom-interest
mailing list