示例#1
0
文件: Dom.java 项目: hk2-project/hk2
  /**
   * 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();
  }