[jdom-interest] copying moving elements to a subclass

David Kavanagh dak at dotech.com
Mon Aug 5 06:14:03 PDT 2002

I'm not sure if this helps, I also extended DefaultJDOMFactory to create 
my own nodes. I also have a base node class that my actual node classes 
extend. So, they are all instances of Element. I have a mapping between 
XML tag name and the class that implements it. So, my factory still 
returns Element, but they are really a class that matches the name of 
the element parsed. So, my tree (using your naming) might have a 
MainNode with children of SubNode1, Subnode2, etc...
Unless you need to do something I haven't thought of, you should be able 
to set up your factory to return you the objects you need instead of 
walking the tree and converting nodes after parsing.


Jasmeet.Singh at eontec.com wrote:

> hi
> I have a following situation
> 1. A document is read. This document is constructed using 
> MyCustomJDOMFactory
> 2.The hierarchy of nodes is : Element has a subclass MainNode and 
> MainNode has subclasses SubNode, SubNode1 etc etc
> 3. While constructing the document, the MyCustomJDOMFactory creates 
> instance of MainNode.
> Now I want MainNode to be converted into SubNode so that the methods 
> of SubNode can be executed.
> I am doing it this way
> class SubNode extends MainNode {
> public SubNode(String rootElement, List contentList){
> super(rootElement);
> setContent(contentList)
> }
> }
> When the above constructor is invoked with content from a node i.ie
> new SubNode(node.getName(),node.getContent()) .. I get an 
> IllegalAddException().. This comes as the element being added already 
> has an existing parent. hence I detatched the element. But the same 
> error is repeated
> new SubNode(node.getName(),node.detach().getContent())
> Is this the right way of achieving the above objective.  
> Also, I cannot use SubNode instances in MyCustomJDOMFactory as there 
> may be a few more SubNode1 SubNode2.. under the MainNode. and all of 
> them will have different operations.
> thanks
> jasmeet
> _______________________________________________ To control your 
> jdom-interest membership: 
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020805/69173142/attachment.htm

More information about the jdom-interest mailing list