[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?


<-- 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) {
            else if (obj instanceof String) {
            else if (obj instanceof Comment) {
            else if (obj instanceof ProcessingInstruction) {
            else if (obj instanceof CDATA) {
            else if (obj instanceof Entity) {
            else {
                /* Drop the new and put back the old content before throwing
exception. */
  	          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) {

        return this;

More information about the jdom-interest mailing list