[jdom-interest] detach() [eg]
Joseph Bowbeer
jozart at csi.com
Mon Apr 23 09:24:32 PDT 2001
I'm for either:
(1) Allow the root element to be detached by allowing documents to have a
null root. Assign the burden of checking for a null root to the client.
(Part of the client's precondition.)
(2) Prevent the root element from being detached.
I prefer #1. As for #2, Elliotte's first proposal seems OK, and I'm still
digesting the second proposal.
I'm against both (3) Using an implicit placeholder for the detached root, or
(4) Adding IllegalStateException to Document.
No one likes placeholder (3), except perhaps as the lesser of evils.
As for IllegalStateException (4), I don't like it because of its time bomb
nature. Compared to a null root, IllegalStateException makes it harder for
clients to determine the state of a given document (calling getRootElement
would throw an IllegalStateException, right?), and it gives the clients no
discretion in determining whether an empty document is in fact a legal
argument or not.
With the addition of IllegalStateException, client methods would need to
catch and rethrow in order to report the most appropriate exception:
void process(Document doc) {
Element root;
try {
root = doc.getRootElement();
catch (IllegalStateException ex) {
throw new IllegalArgumentException("no root: " + doc);
}
// check remaining preconditions
// ...
}
See also:
http://lists.denveronline.net/lists/jdom-interest/2001-April/005830.html
http://lists.denveronline.net/lists/jdom-interest/2001-April/005819.html
http://lists.denveronline.net/lists/jdom-interest/2001-April/005815.html
--
Joe Bowbeer
More information about the jdom-interest
mailing list