[jdom-interest] RE: non-deterministic behaviour
Dreiske, Dale
Dale.Dreiske at disney.com
Thu Apr 12 18:14:43 PDT 2001
Here's my feedback in the form of a modified copy of the setMixedContent
method. After reading through today's digest of the mailing list the answer
seems too simple; I think I must be missing something. My modification keeps
the original List until it knows the new one is acceptable; no double
iteration; no cloning. Did I miss some anything?
Dale.
<-- CODE -->
public Element setMixedContent(List mixedContent) {
if (mixedContent == null) {
return this;
}
/* Save list with original content */
List oldContent = content;
content = new LinkedList();
for (Iterator i = mixedContent.iterator(); i.hasNext(); ) {
Object obj = i.next();
if (obj instanceof Element) {
addContent((Element)obj);
}
else if (obj instanceof String) {
addContent((String)obj);
}
else if (obj instanceof Comment) {
addContent((Comment)obj);
}
else if (obj instanceof ProcessingInstruction) {
addContent((ProcessingInstruction)obj);
}
else if (obj instanceof CDATA) {
addContent((CDATA)obj);
}
else if (obj instanceof Entity) {
addContent((Entity)obj);
}
else {
/* Drop the new and put back the old content before throwing
exception. */
content.clear();
content = oldContent;
throw new IllegalAddException(
"An Element may directly contain only objects of type "
+
"String, Element, Comment, CDATA, Entity, and " +
"ProcessingInstruction: " + obj.getClass().getName() +
" is not allowed");
}
}
/* New mixed content is good, get rid of the old */
if (oldContent != null) {
oldContent.clear();
}
return this;
}
More information about the jdom-interest
mailing list