Ejemplo n.º 1
0
  /**
   * Writes the current object as an XML element using the given SAX writer.
   *
   * @param writer The SAX writer.
   * @throws SAXException
   */
  public void writeElement(XmlWriter writer) throws SAXException {
    final AttributesImpl attributes = new AttributesImpl();
    if ((getRelationship() != null) && !getRelationship().equals("")) {
      attributes.addAttribute("", "rel", null, "xs:token", getRelationship());
    }
    if ((getReverseRelationship() != null) && !getReverseRelationship().equals("")) {
      attributes.addAttribute("", "rev", null, "xs:token", getReverseRelationship());
    }

    if ((getResourceType() != null) && (getResourceType().toString() != null)) {
      attributes.addAttribute("", "resource_type", null, "xs:anyURI", getResourceType().toString());
    }

    if (getDocumentations().isEmpty()) {
      writer.emptyElement(APP_NAMESPACE, "link", null, attributes);
    } else {
      writer.startElement(APP_NAMESPACE, "link", null, attributes);

      for (final DocumentationInfo documentationInfo : getDocumentations()) {
        documentationInfo.writeElement(writer);
      }

      writer.endElement(APP_NAMESPACE, "link");
    }
  }
  /**
   * Writes the current object as an XML element using the given SAX writer.
   *
   * @param writer The SAX writer.
   * @throws SAXException
   */
  public void writeElement(XmlWriter writer) throws SAXException {
    AttributesImpl attributes = new AttributesImpl();

    if ((getReference() != null) && !getReference().equals("")) {
      attributes.addAttribute("", "href", null, "xs:anyURI", "#" + getReference());
      writer.emptyElement(APP_NAMESPACE, "representation", null, attributes);
    } else {
      if ((getIdentifier() != null) && !getIdentifier().equals("")) {
        attributes.addAttribute("", "id", null, "xs:ID", getIdentifier());
      }

      if (getMediaType() != null) {
        attributes.addAttribute("", "mediaType", null, "xs:string", getMediaType().toString());
      }

      if ((getProfiles() != null) && !getProfiles().isEmpty()) {
        StringBuilder builder = new StringBuilder();

        for (Iterator<Reference> iterator = getProfiles().iterator(); iterator.hasNext(); ) {
          Reference reference = iterator.next();
          builder.append(reference.toString());

          if (iterator.hasNext()) {
            builder.append(" ");
          }
        }

        attributes.addAttribute("", "profile", null, "xs:string", builder.toString());
      }

      if ((getXmlElement() != null) && !getXmlElement().equals("")) {
        attributes.addAttribute("", "element", null, "xs:QName", getXmlElement());
      }

      if (getDocumentations().isEmpty() && getParameters().isEmpty()) {
        writer.emptyElement(APP_NAMESPACE, "representation", null, attributes);
      } else {
        writer.startElement(APP_NAMESPACE, "representation", null, attributes);

        for (DocumentationInfo documentationInfo : getDocumentations()) {
          documentationInfo.writeElement(writer);
        }

        for (ParameterInfo parameterInfo : getParameters()) {
          parameterInfo.writeElement(writer);
        }

        writer.endElement(APP_NAMESPACE, "representation");
      }
    }
  }
  /**
   * Writes the current object as an XML element using the given SAX writer.
   *
   * @param writer The SAX writer.
   * @throws SAXException
   */
  public void writeElement(XmlWriter writer) throws SAXException {
    final AttributesImpl attributes = new AttributesImpl();
    if ((getValue() != null) && !getValue().equals("")) {
      attributes.addAttribute("", "id", null, "xs:string", getValue());
    }

    if (getDocumentations().isEmpty()) {
      writer.emptyElement(APP_NAMESPACE, "option", null, attributes);
    } else {
      writer.startElement(APP_NAMESPACE, "option", null, attributes);

      for (final DocumentationInfo documentationInfo : getDocumentations()) {
        documentationInfo.writeElement(writer);
      }

      writer.endElement(APP_NAMESPACE, "option");
    }
  }
  /**
   * Writes the current object as an XML element using the given SAX writer.
   *
   * @param writer The SAX writer.
   * @throws SAXException
   */
  public void writeElement(XmlWriter writer) throws SAXException {
    AttributesImpl attributes = new AttributesImpl();

    if ((getStatuses() != null) && !getStatuses().isEmpty()) {
      StringBuilder builder = new StringBuilder();

      for (Iterator<Status> iterator = getStatuses().iterator(); iterator.hasNext(); ) {
        Status status = iterator.next();
        builder.append(status.getCode());
        if (iterator.hasNext()) {
          builder.append(" ");
        }
      }

      attributes.addAttribute("", "status", null, "xs:string", builder.toString());
    }

    if (getDocumentations().isEmpty()
        && getParameters().isEmpty()
        && getRepresentations().isEmpty()) {
      writer.emptyElement(APP_NAMESPACE, "response", null, attributes);
    } else {
      writer.startElement(APP_NAMESPACE, "response", null, attributes);

      for (DocumentationInfo documentationInfo : getDocumentations()) {
        documentationInfo.writeElement(writer);
      }

      for (ParameterInfo parameterInfo : getParameters()) {
        parameterInfo.writeElement(writer);
      }

      for (RepresentationInfo representationInfo : getRepresentations()) {
        representationInfo.writeElement(writer);
      }

      writer.endElement(APP_NAMESPACE, "response");
    }
  }