Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] User Questions

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: Peter Murray-Rust <pm286 AT cam.ac.uk>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] User Questions
  • Date: Fri, 12 Aug 2005 08:55:24 -0400

If anyone else missed it, this refers to https://lists.ibiblio.org/sympa/arc/xom-interest/2005-August/002515.html which for some reason didn't reach me the first time.

The reason there are both a copy constructor and a copy method is that the constructor is type-safe and the constructor isn't. i.e. it's because Java 1.4 and earlier don't support covariant return types. To be able to copy any node, I have to put the copy method in Node. However the copy method in Element then must return Node, not Element. The copy constructor however always gives the right type. It is a minor ugliness, I agree. It wouldn't be necessary if Java supported covariant return types.

The more serious issue is how to handle the copy method in your Element subclass. I think what you're missing is that shallowCopy is not meant to be invoked by user code, only overridden. The regular copy method calls shallowCopy. The purpose of shallowCopy is just to get the name and namespace right. So in your example you should override shallowCopy() which does not copy any attributes or children. It simply returns an empty element. The you would invoke the copy method inherited from Element. This will call your shallowCopy() method and then add all the children and attributes. In other words, shallowCopy is used by copy. It does not replace copy.

Your copy method might work, but since it uses recursion it's vulnerable to stack overflow. The algorithm used in nu.xom.Element is non-recursive and not limited by the stack size.

--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim




Archive powered by MHonArc 2.6.24.

Top of Page