private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);
    if (prefix == null) {
      prefix = OperationRequestType.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }

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

    return prefix;
  }
    public static OperationRequestType parse(final XMLStreamReader reader) throws Exception {
      final OperationRequestType object = new OperationRequestType();
      try {
        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }

        if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type") != null) {
          final String fullTypeName =
              reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type");
          if (fullTypeName != null) {
            String nsPrefix = null;
            if (fullTypeName.indexOf(":") > -1) {
              nsPrefix = fullTypeName.substring(0, fullTypeName.indexOf(":"));
            }
            nsPrefix = nsPrefix == null ? "" : nsPrefix;

            final String type = fullTypeName.substring(fullTypeName.indexOf(":") + 1);
            if (!"OperationRequestType".equals(type)) {
              final String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
              return (OperationRequestType) ExtensionMapper.getTypeObject(nsUri, type, reader);
            }
          }
        }

        reader.next();
        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }
        if (reader.isStartElement() && new QName("", "requestorID").equals(reader.getName())) {
          final String content = reader.getElementText();
          object.setRequestorID(ConverterUtil.convertToInt(content));
          reader.next();
        } else {
          object.setRequestorID(Integer.MIN_VALUE);
        }

        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }
        try {
          if (reader.isStartElement()) {
            object.setRequestorNSNameSequence(RequestorNSNameSequence.Factory.parse(reader));
          }
        } catch (final Exception e) {
          /* Min-occurs is 0. */
        }

        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }
        if (reader.isStartElement() && new QName("", "requestorQName").equals(reader.getName())) {
          final String content = reader.getElementText();
          object.setRequestorQName(ConverterUtil.convertToString(content));
          reader.next();
        }

        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }
        if (reader.isStartElement()) {
          throw new ADBException("Unexpected subelement " + reader.getLocalName());
        }
      } catch (final XMLStreamException e) {
        throw new Exception(e);
      }

      return object;
    }
  @Override
  public void serialize(
      final QName parentQName,
      final OMFactory factory,
      final MTOMAwareXMLStreamWriter xmlWriter,
      final boolean serializeType)
      throws XMLStreamException, ADBException {
    String prefix = parentQName.getPrefix();
    String namespace = parentQName.getNamespaceURI();

    if ((namespace != null) && (namespace.trim().length() > 0)) {
      final String writerPrefix = xmlWriter.getPrefix(namespace);
      if (writerPrefix != null) {
        xmlWriter.writeStartElement(namespace, parentQName.getLocalPart());
      } else {
        if (prefix == null) {
          prefix = OperationRequestType.generatePrefix(namespace);
        }

        xmlWriter.writeStartElement(prefix, parentQName.getLocalPart(), namespace);
        xmlWriter.writeNamespace(prefix, namespace);
        xmlWriter.setPrefix(prefix, namespace);
      }
    } else {
      xmlWriter.writeStartElement(parentQName.getLocalPart());
    }

    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 + ":OperationRequestType",
            xmlWriter);
      } else {
        this.writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            "OperationRequestType",
            xmlWriter);
      }
    }

    if (this.requestorIDTracker) {
      namespace = "";
      if (!namespace.equals("")) {
        prefix = xmlWriter.getPrefix(namespace);
        if (prefix == null) {
          prefix = OperationRequestType.generatePrefix(namespace);
          xmlWriter.writeStartElement(prefix, "requestorID", namespace);
          xmlWriter.writeNamespace(prefix, namespace);
          xmlWriter.setPrefix(prefix, namespace);
        } else {
          xmlWriter.writeStartElement(namespace, "requestorID");
        }
      } else {
        xmlWriter.writeStartElement("requestorID");
      }

      if (this.requestorID == Integer.MIN_VALUE) {
        throw new ADBException("requestorID cannot be null!!");
      } else {
        xmlWriter.writeCharacters(ConverterUtil.convertToString(this.requestorID));
      }
      xmlWriter.writeEndElement();
    }

    if (this.requestorNSNameSequenceTracker) {
      if (this.requestorNSNameSequence == null) {
        throw new ADBException("OperationRequestTypeSequence_type0 cannot be null!!");
      }
      this.requestorNSNameSequence.serialize(null, factory, xmlWriter);
    }

    if (this.requestorQNameTracker) {
      namespace = "";
      if (!namespace.equals("")) {
        prefix = xmlWriter.getPrefix(namespace);
        if (prefix == null) {
          prefix = OperationRequestType.generatePrefix(namespace);
          xmlWriter.writeStartElement(prefix, "requestorQName", namespace);
          xmlWriter.writeNamespace(prefix, namespace);
          xmlWriter.setPrefix(prefix, namespace);
        } else {
          xmlWriter.writeStartElement(namespace, "requestorQName");
        }
      } else {
        xmlWriter.writeStartElement("requestorQName");
      }

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

    xmlWriter.writeEndElement();
  }