[jdom-interest] wrong error msg

rpcee rpcee at operamail.com
Thu Nov 8 10:30:00 PST 2001


In Document.java, addContent(Comment) contains the error message  "The element 
already has an existing parent " ...

I haven't thought enough about the next bit...

Comment and ProcessingInstruction appear to have duplicated code in 
addContent() at least, if there were an interface (terrible names follow) they 
both implemented you could remove the duplicated code, eg:

interface Addable {
   String getName(); // "PI" or "Comment" for err msgs
   Element getParent();
   Document getDocument();
}


interface DocumentAndElementAddable extends Addable {
   Element setParent(Element parent);
}

interface DocumentAddable  extends Addable {
   Document setDocument(Document document);
}

interface DocumentAndElementAddable extends DocumentAddable,ElementAddable {
}


then addContent(DocumentAndElementAddable) in Document and Element.java to 
replace the addContent(Comment) and addContent(ProcessingInstruction)

In the XNIBuilder I had a method something along the lines of add(Object 
content) which I removed in favour of specific add(Element) etc methods. If 
there were interfaces ElementAddable and DocumentAddable I could again have 
just 2 calls addContent(ElementAddable) or addContent(DocumentAddable) + 
addContent(String). The Element method could be extracted from 
setContentList().

pointless bit:
Element and Document are both "things to which you can add content":
interface ContentAddable {
   void addContent(Addable);
}




More information about the jdom-interest mailing list