コード例 #1
0
  /**
   * Get an XML string representation.
   *
   * @return XML string representation
   */
  @Override
  public String toXML() {
    StringBuilder bldr = new StringBuilder();

    bldr.append("<").append(getElementName()).append(" ");

    if (getNamespace() != null) bldr.append("xmlns='").append(getNamespace()).append("'");

    // add the rest of the attributes if any
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
      bldr.append(" ").append(entry.getKey()).append("='").append(entry.getValue()).append("'");
    }

    bldr.append(">");

    if (userCount != 0)
      bldr.append("<")
          .append(ELEMENT_USER_COUNT)
          .append(">")
          .append(userCount)
          .append("</")
          .append(ELEMENT_USER_COUNT)
          .append(">");

    if (active != -1)
      bldr.append("<")
          .append(ELEMENT_ACTIVE)
          .append(">")
          .append((active > 0))
          .append("</")
          .append(ELEMENT_ACTIVE)
          .append(">");

    if (locked != -1)
      bldr.append("<")
          .append(ELEMENT_LOCKED)
          .append(">")
          .append((active > 0))
          .append("</")
          .append(ELEMENT_LOCKED)
          .append(">");

    for (PacketExtension ext : getChildExtensions()) {
      bldr.append(ext.toXML());
    }

    bldr.append("</").append(getElementName()).append(">");
    return bldr.toString();
  }