public IXArchElement cloneElement(int depth) {
    synchronized (DOMUtils.getDOMLock(elt)) {
      Document doc = elt.getOwnerDocument();
      if (depth == 0) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        JavaSourceCodeImplementationImpl cloneImpl = new JavaSourceCodeImplementationImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      } else if (depth == 1) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        JavaSourceCodeImplementationImpl cloneImpl = new JavaSourceCodeImplementationImpl(cloneElt);
        cloneImpl.setXArch(getXArch());

        NodeList nl = elt.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
          Node n = nl.item(i);
          Node cloneNode = (Node) n.cloneNode(false);
          cloneNode = doc.importNode(cloneNode, true);
          cloneElt.appendChild(cloneNode);
        }
        return cloneImpl;
      } else /* depth = infinity */ {
        Element cloneElt = (Element) elt.cloneNode(true);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        JavaSourceCodeImplementationImpl cloneImpl = new JavaSourceCodeImplementationImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      }
    }
  }
  public void clearValue() {
    synchronized (DOMUtils.getDOMLock(elt)) {
      // Get rid of any text nodes that are children of the element.
      elt.normalize();
    }
    NodeList nl = elt.getChildNodes();
    for (int i = (nl.getLength() - 1); i >= 0; i--) {
      Node n = nl.item(i);
      if (n.getNodeType() == Node.TEXT_NODE) {
        synchronized (DOMUtils.getDOMLock(elt)) {
          elt.removeChild(n);
        }

        IXArch context = getXArch();
        if (context != null) {
          context.fireXArchEvent(
              new XArchEvent(
                  this,
                  XArchEvent.CLEAR_EVENT,
                  XArchEvent.SIMPLE_TYPE_VALUE_CHANGED,
                  "$SIMPLETYPEVALUE$",
                  null,
                  XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this)));
        }
      }
    }
  }
 public String getValue() {
   synchronized (DOMUtils.getDOMLock(elt)) {
     elt.normalize();
     NodeList nl = elt.getChildNodes();
     for (int i = (nl.getLength() - 1); i >= 0; i--) {
       Node n = nl.item(i);
       if (n.getNodeType() == Node.TEXT_NODE) {
         return n.getNodeValue();
       }
     }
     return null;
   }
 }
  public void setChangeSet(edu.uci.isr.xarch.instance.IXMLLink value) {
    if (!(value instanceof DOMBased)) {
      throw new IllegalArgumentException("Cannot handle non-DOM-based xArch entities.");
    }
    {
      edu.uci.isr.xarch.instance.IXMLLink oldElt = getChangeSet();
      DOMUtils.removeChildren(elt, ChangesetsConstants.NS_URI, CHANGE_SET_ELT_NAME);

      IXArch context = getXArch();
      if (context != null) {
        context.fireXArchEvent(
            new XArchEvent(
                this,
                XArchEvent.CLEAR_EVENT,
                XArchEvent.ELEMENT_CHANGED,
                "changeSet",
                oldElt,
                XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this),
                true));
      }
    }
    Element newChildElt = (Element) (((DOMBased) value).getDOMNode());
    newChildElt =
        DOMUtils.cloneAndRename(newChildElt, ChangesetsConstants.NS_URI, CHANGE_SET_ELT_NAME);
    ((DOMBased) value).setDOMNode(newChildElt);

    synchronized (DOMUtils.getDOMLock(elt)) {
      elt.appendChild(newChildElt);
      DOMUtils.order(elt, getSequenceOrder());
    }

    IXArch context = getXArch();
    if (context != null) {
      context.fireXArchEvent(
          new XArchEvent(
              this,
              XArchEvent.SET_EVENT,
              XArchEvent.ELEMENT_CHANGED,
              "changeSet",
              value,
              XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this)));
    }
  }
  public void setValue(String value) {
    synchronized (DOMUtils.getDOMLock(elt)) {
      {
        String oldValue = getValue();
        if (oldValue == null ? value == null : oldValue.equals(value)) return;
        synchronized (DOMUtils.getDOMLock(elt)) {
          // Get rid of any text nodes that are children of the element.
          elt.normalize();
        }
        NodeList nl = elt.getChildNodes();
        for (int i = (nl.getLength() - 1); i >= 0; i--) {
          Node n = nl.item(i);
          if (n.getNodeType() == Node.TEXT_NODE) {
            synchronized (DOMUtils.getDOMLock(elt)) {
              elt.removeChild(n);
            }

            IXArch context = getXArch();
            if (context != null) {
              context.fireXArchEvent(
                  new XArchEvent(
                      this,
                      XArchEvent.CLEAR_EVENT,
                      XArchEvent.SIMPLE_TYPE_VALUE_CHANGED,
                      "$SIMPLETYPEVALUE$",
                      null,
                      XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this),
                      true));
            }
          }
        }
      }
      elt.normalize();
      Document doc = elt.getOwnerDocument();
      Text txt = doc.createTextNode(value);
      elt.appendChild(txt);
    }

    IXArch context = getXArch();
    if (context != null) {
      context.fireXArchEvent(
          new XArchEvent(
              this,
              XArchEvent.SET_EVENT,
              XArchEvent.SIMPLE_TYPE_VALUE_CHANGED,
              "$SIMPLETYPEVALUE$",
              value,
              XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this)));
    }
  }
 public XArchInstanceMetadata getInstanceMetadata() {
   return new XArchInstanceMetadata(XArchUtils.getPackageTitle(elt.getNamespaceURI()));
 }