示例#1
0
  public void startElement(String ns, String name, String qName, Attributes atts)
      throws SAXException {
    int fieldNumber = -1;
    try {
      String id = atts.getValue(ID_ATTR);
      if (id != null) {
        try {
          fieldNumber = Integer.parseInt(id);
        } catch (NumberFormatException ex) {
        }
      }
      if (name.equals(ISOMSG_TAG)) {
        if (fieldNumber >= 0) {
          if (stk.empty()) throw new SAXException("inner without outter");

          ISOMsg inner = new ISOMsg(fieldNumber);
          ((ISOMsg) stk.peek()).set(inner);
          stk.push(inner);
        } else {
          stk.push(new ISOMsg(0));
        }
      } else if (name.equals(ISOFIELD_TAG)) {
        ISOMsg m = (ISOMsg) stk.peek();
        String value = atts.getValue(VALUE_ATTR);
        String type = atts.getValue(TYPE_ATTR);
        if (id == null || value == null) throw new SAXException("invalid field");
        if (TYPE_BINARY.equals(type)) {
          m.set(
              new ISOBinaryField(
                  fieldNumber, ISOUtil.hex2byte(value.getBytes(), 0, value.length() / 2)));
          //          m.set(new ISOBinaryField(fieldNumber, value.getBytes()));
        } else {
          m.set(new ISOField(fieldNumber, value));
        }
      }
    } catch (ISOException e) {
      throw new SAXException("ISOException unpacking " + fieldNumber);
    }
  }