コード例 #1
0
  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);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      } else if (depth == 1) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(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);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      }
    }
  }
コード例 #2
0
  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)));
    }
  }