コード例 #1
0
  @Override
  public DbData readData(InputStream in) throws XMLStreamException {
    XMLStreamReader sr = _staxInFactory.createXMLStreamReader(in);
    DbData result = new DbData();

    sr.nextTag();
    expectTag(FIELD_TABLE, sr);

    try {
      while (sr.nextTag() == XMLStreamReader.START_ELEMENT) {
        result.addRow(readRow(sr));
      }
    } catch (IllegalArgumentException iae) {
      throw new XMLStreamException("Data problem: " + iae.getMessage(), sr.getLocation());
    }

    sr.close();
    return result;
  }
コード例 #2
0
  private final DbRow readRow(XMLStreamReader sr) throws XMLStreamException {
    expectTag(FIELD_ROW, sr);
    DbRow row = new DbRow();
    while (sr.nextTag() == XMLStreamReader.START_ELEMENT) {
      String elemName = sr.getLocalName();
      String value = sr.getElementText();

      try {
        if (!row.assign(elemName, value)) {
          throw new XMLStreamException(
              "Unexpected element <" + elemName + ">: not one of recognized field names");
        }
      } catch (IllegalArgumentException iae) {
        throw new XMLStreamException(
            "Typed access problem with input '" + value + "': " + iae.getMessage(),
            sr.getLocation(),
            iae);
      }
    }
    return row;
  }