Beispiel #1
0
 /**
  * Copy constructor, used to get a deep copy of the passed instance
  *
  * @param source the instance to copy
  */
 public Dom(Dom source, Dom parent) {
   this(source.getHabitat(), source.document, parent, source.model);
   List<Child> newChildren = new ArrayList<Child>();
   for (Child child : source.children) {
     newChildren.add(child.deepCopy(this));
   }
   setChildren(newChildren);
   attributes.putAll(source.attributes);
 }
Beispiel #2
0
  /**
   * Writes back this element.
   *
   * @param tagName The tag name of this element to be written. If null, this DOM node must be a
   *     global element and its tag name will be used.
   * @param w Receives XML infoset stream.
   */
  public void writeTo(String tagName, XMLStreamWriter w) throws XMLStreamException {
    if (tagName == null) tagName = model.tagName;
    if (tagName == null)
      throw new IllegalArgumentException(
          "Trying t write a local element " + this + " w/o a tag name");

    /**
     * If someone has explicitly called the skipFromXml then dont write the element to domain.xml
     */
    if (!writeToXml) {
      return;
    }
    w.writeStartElement(tagName);

    for (Map.Entry<String, String> attributeToWrite : attributesToWrite().entrySet()) {
      w.writeAttribute(attributeToWrite.getKey(), attributeToWrite.getValue());
    }

    List<Child> localChildren = new ArrayList<Child>(children);
    for (Child c : localChildren) c.writeTo(w);

    w.writeEndElement();
  }