Esempio n. 1
0
  private String registerPrefix(final XMLStreamWriter xmlWriter, final String namespace)
      throws XMLStreamException {
    String prefix = xmlWriter.getPrefix(namespace);

    if (prefix == null) {
      prefix = SessionFiles.generatePrefix(namespace);
      while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
        prefix = BeanUtil.getUniquePrefix();
      }

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

    return prefix;
  }
Esempio n. 2
0
    public static SessionFiles parse(final XMLStreamReader reader) throws Exception {
      final SessionFiles object = new SessionFiles();

      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 (!"SessionFiles".equals(type)) {
              // find namespace for the prefix
              final String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
              return (SessionFiles) ExtensionMapper.getTypeObject(nsUri, type, reader);
            }
          }
        }

        reader.next();
        final ArrayList<SessionFile> fileList = new ArrayList<SessionFile>();
        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }

        if (reader.isStartElement() && new QName("", "name").equals(reader.getName())) {
          final String content = reader.getElementText();
          object.setName(ConverterUtil.convertToString(content));
          reader.next();
        } else {
          throw new ADBException("Unexpected subelement " + reader.getLocalName());
        }

        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }

        if (reader.isStartElement() && new QName("", "files").equals(reader.getName())) {
          fileList.add(SessionFile.Factory.parse(reader));
          boolean noMore = false;
          while (!noMore) {
            while (!reader.isEndElement()) {
              reader.next();
            }

            reader.next();
            while (!reader.isStartElement() && !reader.isEndElement()) {
              reader.next();
            }

            if (reader.isEndElement()) {
              noMore = true;
            } else {
              if (new QName("", "files").equals(reader.getName())) {
                fileList.add(SessionFile.Factory.parse(reader));
              } else {
                noMore = true;
              }
            }
          }
          object.setFiles(
              (SessionFile[]) ConverterUtil.convertToArray(SessionFile.class, fileList));
        } else {
          throw new ADBException("Unexpected subelement " + reader.getLocalName());
        }

        while (!reader.isStartElement() && !reader.isEndElement()) {
          reader.next();
        }

        if (reader.isStartElement() && new QName("", "user").equals(reader.getName())) {
          final String content = reader.getElementText();
          object.setUser(ConverterUtil.convertToString(content));
          reader.next();
        } else {
          throw new ADBException("Unexpected subelement " + reader.getLocalName());
        }

        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;
    }
Esempio n. 3
0
  @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 = SessionFiles.generatePrefix(namespace);
        }

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

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

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

    xmlWriter.writeEndElement();
    if (this.files != null) {
      for (final SessionFile localFile : this.files) {
        if (localFile != null) {
          localFile.serialize(new QName("", "files"), factory, xmlWriter);
        } else {
          throw new ADBException("files cannot be null!!");
        }
      }
    } else {
      throw new ADBException("files cannot be null!!");
    }

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

    xmlWriter.writeEndElement();
  }