ParsePosition pp = new ParsePosition (0); Object[] r = parse (sourceStr, pp); if (r == null) throw new ParseException ("couldn't parse string", pp.getErrorIndex());
int index = pos.getIndex(); if (! sourceStr.startsWith(leader, index)) { pos.setErrorIndex(index); return null; } index += leader.length();  Vector results = new Vector (elements.length, 1);  for (int i = 0; i < elements.length; ++i) { Format formatter = null; if (elements[i].setFormat != null) formatter = elements[i].setFormat; else if (elements[i].format != null) formatter = elements[i].format;  Object value = null; if (formatter instanceof ChoiceFormat) {   ChoiceFormat cf = (ChoiceFormat) formatter; String[] formats = (String[]) cf.getFormats(); double[] limits = (double[]) cf.getLimits(); MessageFormat subfmt = new MessageFormat (); subfmt.setLocale(locale); ParsePosition subpos = new ParsePosition (index);  int j; for (j = 0; value == null && j < limits.length; ++j) { subfmt.applyPattern(formats[j]); subpos.setIndex(index); value = subfmt.parse(sourceStr, subpos); } if (value != null) { index = subpos.getIndex(); value = new Double (limits[j]); } } else if (formatter != null) { pos.setIndex(index); value = formatter.parseObject(sourceStr, pos); if (value != null) index = pos.getIndex(); } else {   int next_index = sourceStr.indexOf(elements[i].trailer, index); if (next_index == -1) { pos.setErrorIndex(index); return null; } value = sourceStr.substring(index, next_index); index = next_index; }  if (value == null || ! sourceStr.startsWith(elements[i].trailer, index)) { pos.setErrorIndex(index); return null; }  if (elements[i].argNumber >= results.size()) results.setSize(elements[i].argNumber + 1); results.setElementAt(value, elements[i].argNumber);  index += elements[i].trailer.length(); }  Object[] r = new Object[results.size()]; results.copyInto(r);
  public Object[] parse (String sourceStr) throws ParseException  {    ParsePosition pp = new ParsePosition (0);    Object[] r = parse (sourceStr, pp);    if (r == null)      throw new ParseException ("couldn't parse string", pp.getErrorIndex());    return r;  }