[jdom-interest] Text class (Modified)

Ken Rune Helland kenh at csc.no
Mon May 28 01:04:23 PDT 2001


At 04:42 PM 5/27/2001 -0500, Brett McLaughlin wrote:
>OK. So now we're at:
>
>public class Text {
>
>

<SNIP>



>     public Object clone() {
>         Text newText = new Text(value);
>         newText.setParent(parent);
>     }

For easy subclassing this shoud be:

     public Object clone() {
         Text newText = null;
          try{
                 newText = (Text) super.clone();
          }catch(CloneNotSupportedException e){
            // wont happen
         }

          // must replace references copied by clone
          newText.value = new StringBuffer( this.value.toString );
         newText.setParent(null);

         return newText;
     }

also Text must "implements Cloneable".

Also I asume Text as other clones i JDOM will be without parent
until inserted in a Element.

And the detach metod:

public Text detach() {
         Element p = getParent();
         if (p != null) {
             p.removeContent(this);
         }
          setParent(null);
         return this;
     }


KenR





More information about the jdom-interest mailing list