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

Jason Hunter jhunter at collab.net
Thu Aug 31 10:54:31 PDT 2000


I have to run but on a glance it looks proper to me.

-jh-

"David W. Smiley" wrote:
> 
> (corrected subject line)
> 
> I just now realized this is overall a more complicated issue.  I've
> decided to present the following _pseuodocode_ instead:
> 
> private:
> /** 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
> package-private:
> Element getRootElement() {
>   return (parentElement == null ? this : parent.getRootElement());
> }
> public:
> addElement(Element b) {
>   if (b.parentElement == null && b != getRootElement())
>         ...add element...
>   else throw
> }
> removeElement(Element b) {
>   if (b not a child of this)
>         throw
>   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