[jdom-interest] How to "crash" JDOM, part 1

David W. Smiley dsmiley at mitre.org
Thu Aug 31 09:59:54 PDT 2000

(corrected subject line)

I just now realized this is overall a more complicated issue.  I've
decided to present the following _pseuodocode_ instead:

/** If null, is a "root element", possibly a "document root element". */
Element parentElement= null;

/** Means that this element and all childs are bound to a document. To
be true, parentElement must be null. */
boolean isDocRootElement= false;

//not same as docRootElement
Element getRootElement() {
  return (parentElement == null ? this : parent.getRootElement());
addElement(Element b) {
  if (b.parentElement == null && b != getRootElement())
	...add element...
  else throw 
removeElement(Element b) {
  if (b not a child of this)
  b.parentElement= null;
Element copyElement() {
  b= super.clone();
  ...set other fields, leaving parentElement as null and
isDocRootElement as false...

Questions?  Comments?  The only real time-hit here is getRootElement(),
but that will work really fast, especially considering documents don't
get that deep.  Each ancestor in-between this and getRootElement doesn't
need to be checked because they all have an parent whereas 'b' doesn't.

-- David Smiley

More information about the jdom-interest mailing list