Example #1
0
  /**
   * Returns the map of attributes names and values for attributes which value is neither null or
   * the default value. These attributes are considered having a non default value and must be
   * written out.
   *
   * @return map of attributes indexed by name that must be persisted
   */
  private Map<String, String> attributesToWrite() {

    Map<String, String> attributesToWrite = new HashMap<String, String>();
    Map<String, String> localAttr = new HashMap<String, String>(attributes);
    for (Map.Entry<String, String> a : localAttr.entrySet()) {
      ConfigModel.AttributeLeaf am = model.attributes.get(a.getKey());
      String dv = am.getDefaultValue();
      if (dv == null || !dv.equals(a.getValue())) {
        attributesToWrite.put(a.getKey(), a.getValue());
      }
    }
    return attributesToWrite;
  }
Example #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();
  }