[jdom-interest] problem with detaching Attributes in JDOM Beta 8, Release Candida te #1 ???

Alex Rosen arosen at silverstream.com
Thu Mar 14 08:38:28 PST 2002


I fixed the problem in AttributeList - one of the remove() methods wasn't
detaching the parent. These patches also contain a couple of very minor
fixes:

- In ContentList, rearranged the instanceof tests to be more in order of
expected frequency (specifically I moved up the check for Text nodes higher
up). May result in a tiny speedup.

- Pet peeve: The argument to AttributeList.removeParent() should *always* be
an Attribute, or else something's very wrong with the JDOM code; we were
checking the object's type (in order to avoid the ClassCastException), but
doing nothing in the error case. This is worse than not checking - it was
making in fail silently. I removed the check, so now it would throw a
ClassCastException. (You could also keep the check and throw a different,
more helpful exception. I've never been a fan of that - this exception would
indicate a serious bug in the JDOM code itself, not the use of JDOM. I don't
know if it's worth the added code and string size...)

Alex

> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Patrick McFarlane
> Sent: Wednesday, March 13, 2002 9:40 PM
> To: 'jdom-interest at jdom.org'
> Subject: [jdom-interest] problem with detaching Attributes in
> JDOM Beta
> 8, Release Candida te #1 ???
>
>
> Hello,
>
>  I'm currently using code like the following to remove an
> attribute from one
> element and then add it to another.
>
> 		Element currCompElem......
> 		Element refElem = ew.getReferencedElement();
> 		Attribute nameAttr = currCompElem.getAttribute("name");
> 		nameAttr.detach();
> 		refElem.setAttribute(nameAttr);
>
>  I was able to use this code in JDOM Beta 7 without error.
> However with JDOM
> Beta 8 I get the following error...
>
> java.lang.ExceptionInInitializerError:
> org.jdom.IllegalAddException: The
> attribute already has an existing parent "component"
>         at org.jdom.AttributeList.add(AttributeList.java,
> Compiled Code)
>         at org.jdom.AttributeList.add(AttributeList.java,
> Compiled Code)
>         at org.jdom.AttributeList.set(AttributeList.java:445)
>         at org.jdom.AttributeList.add(AttributeList.java,
> Compiled Code)
>         at org.jdom.Element.setAttribute(Element.java, Compiled Code)
>         at
> com.lendex.xml.templates.XMLTemplateObjectCreator.buildCompone
> nt(XMLTemplate
> ObjectCreator.java:195)
>
> any ideas???
>
> thanks,
> 	patrick
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ContentList.diff
Type: application/octet-stream
Size: 2184 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20020314/7a7ea086/ContentList.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AttributeList.diff
Type: application/octet-stream
Size: 1087 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20020314/7a7ea086/AttributeList.obj


More information about the jdom-interest mailing list