@Test public void testStartElementThrowsEmptyStackException() throws Throwable { try { xMLPackager.startElement("testXMLPackagerNs", "field", "testXMLPackagerQName", atts); fail("Expected EmptyStackException to be thrown"); } catch (EmptyStackException ex) { assertNull(ex.getMessage(), "ex.getMessage()"); } }
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) { throw new SAXException ("Invalid id " + id); } } if (name.equals (ISOMSG_TAG)) { if (fieldNumber >= 0) { if (stk.empty()) throw new SAXException ("inner without outer"); 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) throw new SAXException ("invalid field"); value = value == null ? "" : value; ISOComponent ic; if (TYPE_BINARY.equals (type)) { ic = new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte ( value.getBytes(), 0, value.length()/2 ) ); } else if (TYPE_AMOUNT.equals (type)) { ic = new ISOAmount( fieldNumber, Integer.parseInt (atts.getValue(CURRENCY_ATTR)), new BigDecimal (value) ); } else { ic = new ISOField (fieldNumber, ISOUtil.stripUnicode(value)); } m.set (ic); stk.push (ic); } else if (HEADER_TAG.equals (name)) { BaseHeader bh = new BaseHeader(); bh.setAsciiEncoding (ASCII_ENCODING.equalsIgnoreCase(atts.getValue(ENCODING_ATTR))); stk.push (bh); } } catch (ISOException e) { throw new SAXException ("ISOException unpacking "+fieldNumber); } }
XMLPackager extends DefaultHandler implements ISOPackager, LogSource { 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) { throw new SAXException ("Invalid id " + id); } } if (name.equals (ISOMSG_TAG)) { if (fieldNumber >= 0) { if (stk.empty()) throw new SAXException ("inner without outer"); 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) throw new SAXException ("invalid field"); value = value == null ? "" : value; ISOComponent ic; if (TYPE_BINARY.equals (type)) { ic = new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte ( value.getBytes(), 0, value.length()/2 ) ); } else if (TYPE_AMOUNT.equals (type)) { ic = new ISOAmount( fieldNumber, Integer.parseInt (atts.getValue(CURRENCY_ATTR)), new BigDecimal (value) ); } else { ic = new ISOField (fieldNumber, ISOUtil.stripUnicode(value)); } m.set (ic); stk.push (ic); } else if (HEADER_TAG.equals (name)) { BaseHeader bh = new BaseHeader(); bh.setAsciiEncoding (ASCII_ENCODING.equalsIgnoreCase(atts.getValue(ENCODING_ATTR))); stk.push (bh); } } catch (ISOException e) { throw new SAXException ("ISOException unpacking "+fieldNumber); } } }
XMLPackager extends DefaultHandler implements ISOPackager, LogSource { 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) { throw new SAXException ("Invalid id " + id); } } if (name.equals (ISOMSG_TAG)) { if (fieldNumber >= 0) { if (stk.empty()) throw new SAXException ("inner without outer"); 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) throw new SAXException ("invalid field"); value = value == null ? "" : value; ISOComponent ic; if (TYPE_BINARY.equals (type)) { ic = new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte ( value.getBytes(), 0, value.length()/2 ) ); } else if (TYPE_AMOUNT.equals (type)) { ic = new ISOAmount( fieldNumber, Integer.parseInt (atts.getValue(CURRENCY_ATTR)), new BigDecimal (value) ); } else { ic = new ISOField (fieldNumber, ISOUtil.stripUnicode(value)); } m.set (ic); stk.push (ic); } else if (HEADER_TAG.equals (name)) { BaseHeader bh = new BaseHeader(); bh.setAsciiEncoding (ASCII_ENCODING.equalsIgnoreCase(atts.getValue(ENCODING_ATTR))); stk.push (bh); } } catch (ISOException e) { throw new SAXException ("ISOException unpacking "+fieldNumber); } } XMLPackager(); }
XMLPackager extends DefaultHandler implements ISOPackager, LogSource { 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) { throw new SAXException ("Invalid id " + id); } } if (name.equals (ISOMSG_TAG)) { if (fieldNumber >= 0) { if (stk.empty()) throw new SAXException ("inner without outer"); 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) throw new SAXException ("invalid field"); value = value == null ? "" : value; ISOComponent ic; if (TYPE_BINARY.equals (type)) { ic = new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte ( value.getBytes(), 0, value.length()/2 ) ); } else if (TYPE_AMOUNT.equals (type)) { ic = new ISOAmount( fieldNumber, Integer.parseInt (atts.getValue(CURRENCY_ATTR)), new BigDecimal (value) ); } else { ic = new ISOField (fieldNumber, ISOUtil.stripUnicode(value)); } m.set (ic); stk.push (ic); } else if (HEADER_TAG.equals (name)) { BaseHeader bh = new BaseHeader(); bh.setAsciiEncoding (ASCII_ENCODING.equalsIgnoreCase(atts.getValue(ENCODING_ATTR))); stk.push (bh); } } catch (ISOException e) { throw new SAXException ("ISOException unpacking "+fieldNumber); } } XMLPackager(); void forceBinary(int ... bfields); byte[] pack(ISOComponent c); synchronized int unpack(ISOComponent c, byte[] b); synchronized void unpack(ISOComponent c, InputStream in); void startElement(String ns, String name, String qName, Attributes atts); void characters(char ch[], int start, int length); void endElement(String ns, String name, String qname); String getFieldDescription(ISOComponent m, int fldNumber); void setLogger(Logger logger, String realm); String getRealm(); Logger getLogger(); ISOMsg createISOMsg(); String getDescription(); void setXMLParserFeature(String fname, boolean val); }
XMLPackager extends DefaultHandler implements ISOPackager, LogSource { 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) { throw new SAXException ("Invalid id " + id); } } if (name.equals (ISOMSG_TAG)) { if (fieldNumber >= 0) { if (stk.empty()) throw new SAXException ("inner without outer"); 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) throw new SAXException ("invalid field"); value = value == null ? "" : value; ISOComponent ic; if (TYPE_BINARY.equals (type)) { ic = new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte ( value.getBytes(), 0, value.length()/2 ) ); } else if (TYPE_AMOUNT.equals (type)) { ic = new ISOAmount( fieldNumber, Integer.parseInt (atts.getValue(CURRENCY_ATTR)), new BigDecimal (value) ); } else { ic = new ISOField (fieldNumber, ISOUtil.stripUnicode(value)); } m.set (ic); stk.push (ic); } else if (HEADER_TAG.equals (name)) { BaseHeader bh = new BaseHeader(); bh.setAsciiEncoding (ASCII_ENCODING.equalsIgnoreCase(atts.getValue(ENCODING_ATTR))); stk.push (bh); } } catch (ISOException e) { throw new SAXException ("ISOException unpacking "+fieldNumber); } } XMLPackager(); void forceBinary(int ... bfields); byte[] pack(ISOComponent c); synchronized int unpack(ISOComponent c, byte[] b); synchronized void unpack(ISOComponent c, InputStream in); void startElement(String ns, String name, String qName, Attributes atts); void characters(char ch[], int start, int length); void endElement(String ns, String name, String qname); String getFieldDescription(ISOComponent m, int fldNumber); void setLogger(Logger logger, String realm); String getRealm(); Logger getLogger(); ISOMsg createISOMsg(); String getDescription(); void setXMLParserFeature(String fname, boolean val); static final String ISOMSG_TAG; static final String ISOFIELD_TAG; static final String ID_ATTR; static final String VALUE_ATTR; static final String TYPE_ATTR; static final String TYPE_BINARY; static final String TYPE_BITMAP; static final String TYPE_AMOUNT; static final String CURRENCY_ATTR; static final String HEADER_TAG; static final String ENCODING_ATTR; static final String ASCII_ENCODING; }