Ejemplo n.º 1
0
  @Override
  public void serialize(
      final QName parentQName,
      final OMFactory factory,
      final MTOMAwareXMLStreamWriter xmlWriter,
      final boolean serializeType)
      throws XMLStreamException, ADBException {
    final String namespace = parentQName.getNamespaceURI();
    final String localName = parentQName.getLocalPart();

    if (!namespace.equals("")) {
      String prefix = xmlWriter.getPrefix(namespace);

      if (prefix == null) {
        prefix = RigStateType.generatePrefix(namespace);
        xmlWriter.writeStartElement(prefix, localName, namespace);
        xmlWriter.writeNamespace(prefix, namespace);
        xmlWriter.setPrefix(prefix, namespace);
      } else {
        xmlWriter.writeStartElement(namespace, localName);
      }
    } else {
      xmlWriter.writeStartElement(localName);
    }

    if (serializeType) {
      final String namespacePrefix =
          this.registerPrefix(xmlWriter, "http://remotelabs.eng.uts.edu.au/rigmanagement");
      if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)) {
        this.writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            namespacePrefix + ":RigStateType",
            xmlWriter);
      } else {
        this.writeAttribute(
            "xsi", "http://www.w3.org/2001/XMLSchema-instance", "type", "RigStateType", xmlWriter);
      }
    }

    if (this.rigStateType == null) {
      throw new ADBException("Value cannot be null !!");
    } else {
      xmlWriter.writeCharacters(this.rigStateType);
    }

    xmlWriter.writeEndElement();
  }
Ejemplo n.º 2
0
  private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);
    if (prefix == null) {
      prefix = RigStateType.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }

      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }