1 28 29 package org.jibx.runtime.impl; 30 31 import java.io.*; 32 import java.util.*; 33 34 import org.jibx.runtime.*; 35 import org.jibx.runtime.IUnmarshaller; 36 import org.jibx.runtime.IUnmarshallingContext; 37 import org.jibx.runtime.JiBXException; 38 import org.xmlpull.v1.*; 39 40 48 49 public class UnmarshallingContext implements IUnmarshallingContext 50 { 51 54 public static final int START_DOCUMENT = 0; 55 public static final int END_DOCUMENT = 1; 56 public static final int START_TAG = 2; 57 public static final int END_TAG = 3; 58 public static final int TEXT = 4; 59 public static final int CDSECT = 5; 60 public static final int ENTITY_REF = 6; 61 public static final int IGNORABLE_WHITESPACE = 7; 62 public static final int PROCESSING_INSTRUCTION = 8; 63 public static final int COMMENT = 9; 64 public static final int DOCDECL = 10; 65 66 67 protected static final String DEFAULT_PARSER_NAME = 68 "org.xmlpull.mxp1.MXParserFactory"; 69 70 71 protected static final int INITIAL_STACK_SIZE = 20; 72 73 74 protected static final String [] EMPTY_STRING_ARRAY = new String [0]; 75 76 77 protected static XmlPullParserFactory s_factory; 78 79 80 private InputStreamWrapper m_streamWrapper; 81 82 83 protected XmlPullParser m_parser; 84 85 86 protected String m_docName; 87 88 97 99 protected String [] m_unmarshallerClasses; 100 101 103 protected IUnmarshaller[] m_unmarshallers; 104 105 108 109 protected String [] m_namespaces; 110 111 112 protected String [] m_names; 113 114 115 protected int m_globalCount; 116 117 118 protected HashMap[] m_idMaps; 119 120 122 protected String [] m_idClasses; 123 124 125 protected int m_stackDepth; 126 127 128 protected Object [] m_objectStack; 129 130 137 protected HashMap m_unmarshalMap; 138 139 140 protected Integer [] m_indexes; 141 142 143 protected String m_idref; 144 145 158 public UnmarshallingContext(int nmap, String [] umcs, String [] nss, 159 String [] names, String [] idcs) { 160 161 m_globalCount = nss.length; 163 m_unmarshallerClasses = new String [nmap]; 164 System.arraycopy(umcs, 0, m_unmarshallerClasses, 0, umcs.length); 165 m_unmarshallers = new IUnmarshaller[nmap]; 166 m_namespaces = new String [nmap]; 167 System.arraycopy(nss, 0, m_namespaces, 0, nss.length); 168 m_names = new String [nmap]; 169 System.arraycopy(names, 0, m_names, 0, names.length); 170 m_idClasses = idcs; 171 int size = idcs == null ? 1 : idcs.length; 172 m_idMaps = new HashMap[size]; 173 m_objectStack = new Object [INITIAL_STACK_SIZE]; 174 } 175 176 180 public UnmarshallingContext() { 181 this(0, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, 182 EMPTY_STRING_ARRAY); 183 } 184 185 191 private void createParser(boolean nsa) throws JiBXException { 192 if (m_parser == null) { 193 try { 194 195 if (s_factory == null) { 197 198 ClassLoader loader = Thread.currentThread(). 200 getContextClassLoader(); 201 if (loader == null) { 202 loader = UnmarshallingContext.class.getClassLoader(); 203 } 204 try { 205 String name = System.getProperty 206 (XmlPullParserFactory.PROPERTY_NAME); 207 if (name != null && (name = name.trim()).length() > 0) { 208 s_factory = XmlPullParserFactory.newInstance(name, 209 loader.getClass()); 210 } 211 } catch (Exception ex) { } 212 213 if (s_factory == null) { 215 try { 216 s_factory = XmlPullParserFactory.newInstance(); 217 } catch (Exception ex) { } 218 if (s_factory == null) { 219 try { 220 s_factory = XmlPullParserFactory.newInstance 221 (DEFAULT_PARSER_NAME, loader.getClass()); 222 } catch (Exception ex) { 223 throw new JiBXException 224 ("Unable to create parser", ex); 225 } 226 } 227 } 228 229 s_factory.setNamespaceAware(nsa); 231 } 232 m_parser = s_factory.newPullParser(); 233 234 } catch (XmlPullParserException ex) { 235 throw new JiBXException("Error creating parser", ex); 236 } 237 } 238 } 239 240 248 public static String buildNameString(String ns, String name) { 249 if (ns == null || "".equals(ns)) { 250 return "\"" + name + "\""; 251 } else { 252 return "\"{" + ns + "}" + name + "\""; 253 } 254 } 255 256 261 public String currentNameString() { 262 return buildNameString(m_parser.getNamespace(), m_parser.getName()); 263 } 264 265 270 public String buildPositionString() { 271 String base = "(line " + m_parser.getLineNumber() + ", col " + 272 m_parser.getColumnNumber(); 273 if (m_docName != null) { 274 base += ", in " + m_docName; 275 } 276 return base + ')'; 277 } 278 279 286 public void throwStartTagNameError(String ns, String name) 287 throws JiBXException { 288 throw new JiBXException("Expected " + buildNameString(ns, name) + 289 " start tag, found " + currentNameString() + " start tag " + 290 buildPositionString()); 291 } 292 293 300 public void throwEndTagNameError(String ns, String name) 301 throws JiBXException { 302 throw new JiBXException("Expected " + buildNameString(ns, name) + 303 " end tag, found " + currentNameString() + " end tag " + 304 buildPositionString()); 305 } 306 307 313 private void advance() throws JiBXException { 314 try { 315 m_parser.nextToken(); 316 } catch (IOException ex) { 317 throw new JiBXException("Error accessing document", ex); 318 } catch (XmlPullParserException ex) { 319 throw new JiBXException 320 ("Error parsing document " + buildPositionString(), ex); 321 } 322 } 323 324 334 private boolean verifyNamespace(String ns) { 335 if (ns == null || "".equals(ns)) { 336 return m_parser.getNamespace().length() == 0; 337 } else { 338 return ns.equals(m_parser.getNamespace()); 339 } 340 } 341 342 350 private String getAttributeValue(String ns, String name) { 351 if (ns == null) { 352 return m_parser.getAttributeValue("", name); 353 } else { 354 return m_parser.getAttributeValue(ns, name); 355 } 356 } 357 358 370 public void setDocument(InputStream ins, String enc, boolean nsa) 371 throws JiBXException { 372 try { 373 createParser(nsa); 374 if (m_streamWrapper == null) { 375 m_streamWrapper = new InputStreamWrapper(); 376 } 377 m_streamWrapper.setInput(ins, enc); 378 m_parser.setInput(m_streamWrapper.getReader()); 379 reset(); 380 } catch (XmlPullParserException e) { 381 throw new JiBXException("Error setting document", e); 382 } catch (IOException e) { 383 throw new JiBXException("Error initializing input stream", e); 384 } 385 } 386 387 395 public void setDocument(InputStream ins, String enc) throws JiBXException { 396 setDocument(ins, enc, true); 397 } 398 399 409 public void setDocument(Reader rdr, boolean nsa) throws JiBXException { 410 try { 411 createParser(nsa); 412 m_parser.setInput(rdr); 413 reset(); 414 } catch (XmlPullParserException ex) { 415 throw new JiBXException("Error setting document", ex); 416 } 417 } 418 419 425 public void setDocument(Reader rdr) throws JiBXException { 426 setDocument(rdr, true); 427 } 428 429 438 public void setDocument(InputStream ins, String name, String enc) 439 throws JiBXException { 440 setDocument(ins, enc); 441 m_docName = name; 442 } 443 444 451 public void setDocument(Reader rdr, String name) throws JiBXException { 452 setDocument(rdr); 453 m_docName = name; 454 } 455 456 464 public void setFromContext(UnmarshallingContext parent) { 465 m_parser = parent.m_parser; 466 m_docName = parent.m_docName; 467 } 468 469 474 public void reset() { 475 for (int i = 0; i < m_idMaps.length; i++) { 476 m_idMaps[i] = null; 477 } 478 for (int i = m_globalCount; i < m_unmarshallers.length; i++) { 479 m_namespaces[i] = null; 480 m_names[i] = null; 481 m_unmarshallers[i] = null; 482 } 483 m_unmarshalMap = null; 484 m_idref = null; 485 for (int i = 0; i < m_objectStack.length; i++) { 486 m_objectStack[i] = null; 487 } 488 m_stackDepth = 0; 489 } 490 491 499 public String toStart() throws JiBXException { 500 try { 501 if (m_parser.getEventType() == XmlPullParser.START_TAG) { 502 return m_parser.getName(); 503 } 504 while (true) { 505 m_parser.next(); 506 switch (m_parser.getEventType()) { 507 508 case XmlPullParser.START_TAG: 509 return m_parser.getName(); 510 511 case XmlPullParser.END_TAG: 512 throw new JiBXException("Expected start tag, " + 513 "found end tag " + currentNameString() + 514 " " + buildPositionString()); 515 516 case XmlPullParser.END_DOCUMENT: 517 throw new JiBXException("Expected start tag, " + 518 "found end of document " + buildPositionString()); 519 520 } 521 } 522 } catch (IOException ex) { 523 throw new JiBXException("Error accessing document", ex); 524 } catch (XmlPullParserException ex) { 525 throw new JiBXException 526 ("Error parsing document " + buildPositionString(), ex); 527 } 528 } 529 530 538 public String toEnd() throws JiBXException { 539 try { 540 if (m_parser.getEventType() == XmlPullParser.END_TAG) { 541 return m_parser.getName(); 542 } 543 while (true) { 544 m_parser.next(); 545 switch (m_parser.getEventType()) { 546 547 case XmlPullParser.START_TAG: 548 throw new JiBXException("Expected end tag, " + 549 "found start tag " + currentNameString() + 550 " " + buildPositionString()); 551 552 case XmlPullParser.END_TAG: 553 return m_parser.getName(); 554 555 case XmlPullParser.END_DOCUMENT: 556 throw new JiBXException("Expected end tag, " + 557 "found end of document " + buildPositionString()); 558 559 } 560 } 561 } catch (IOException ex) { 562 throw new JiBXException("Error accessing document", ex); 563 } catch (XmlPullParserException ex) { 564 throw new JiBXException 565 ("Error parsing document " + buildPositionString(), ex); 566 } 567 } 568 569 576 public int toTag() throws JiBXException { 577 try { 578 int type = m_parser.getEventType(); 579 while (type != XmlPullParser.START_TAG && 580 type != XmlPullParser.END_TAG) { 581 type = m_parser.next(); 582 } 583 return m_parser.getEventType(); 584 } catch (IOException ex) { 585 throw new JiBXException("Error accessing document", ex); 586 } catch (XmlPullParserException ex) { 587 throw new JiBXException 588 ("Error parsing document " + buildPositionString(), ex); 589 } 590 } 591 592 604 public boolean isAt(String ns, String name) throws JiBXException { 605 try { 606 int type = m_parser.getEventType(); 607 while (type != XmlPullParser.START_TAG && 608 type != XmlPullParser.END_TAG) { 609 type = m_parser.next(); 610 } 611 return m_parser.getEventType() == XmlPullParser.START_TAG && 612 m_parser.getName().equals(name) && verifyNamespace(ns); 613 } catch (IOException ex) { 614 throw new JiBXException("Error accessing document", ex); 615 } catch (XmlPullParserException ex) { 616 throw new JiBXException 617 ("Error parsing document " + buildPositionString(), ex); 618 } 619 } 620 621 632 public boolean hasAttribute(String ns, String name) throws JiBXException { 633 try { 634 if (m_parser.getEventType() == XmlPullParser.START_TAG) { 635 return getAttributeValue(ns, name) != null; 636 } else { 637 throw new JiBXException("Error parsing document " + 638 buildPositionString()); 639 } 640 } catch (XmlPullParserException ex) { 641 throw new JiBXException 642 ("Error parsing document " + buildPositionString(), ex); 643 } 644 } 645 646 657 public boolean hasAnyAttribute(String [] nss, String [] names) 658 throws JiBXException { 659 try { 660 if (m_parser.getEventType() == XmlPullParser.START_TAG) { 661 for (int i = 0; i < names.length; i++) { 662 if (getAttributeValue(nss[i], names[i]) != null) { 663 return true; 664 } 665 } 666 return false; 667 } else { 668 throw new JiBXException("Error parsing document " + 669 buildPositionString()); 670 } 671 } catch (XmlPullParserException ex) { 672 throw new JiBXException 673 ("Error parsing document " + buildPositionString(), ex); 674 } 675 } 676 677 688 public void checkAllowedAttributes(String [] nss, String [] names) 689 throws JiBXException { 690 try { 691 if (m_parser.getEventType() == XmlPullParser.START_TAG) { 692 int count = m_parser.getAttributeCount(); 693 loop: for (int i = 0; i < count; i++) { 694 String name = m_parser.getAttributeName(i); 695 String ns = m_parser.getAttributeNamespace(i); 696 int base = 0; 697 int limit = names.length - 1; 698 while (base <= limit) { 699 int cur = (base + limit) >> 1; 700 int diff = name.compareTo(names[cur]); 701 if (diff == 0) { 702 String comp = nss[cur]; 703 if (comp == null) { 704 diff = ns.compareTo(""); 705 } else { 706 diff = ns.compareTo(comp); 707 } 708 if (diff == 0) { 709 continue loop; 710 } 711 } 712 if (diff < 0) { 713 limit = cur - 1; 714 } else if (diff > 0) { 715 base = cur + 1; 716 } 717 } 718 throwStartTagException("Illegal attribute " + 719 buildNameString(ns, name)); 720 } 721 } else { 722 throw new JiBXException("Error parsing document " + 723 buildPositionString()); 724 } 725 } catch (XmlPullParserException ex) { 726 throw new JiBXException 727 ("Error parsing document " + buildPositionString(), ex); 728 } 729 } 730 731 743 public void parseToStartTag(String ns, String name) throws JiBXException { 744 if (toStart().equals(name) && verifyNamespace(ns)) { 745 return; 746 } else { 747 throwStartTagNameError(ns, name); 748 } 749 } 750 751 763 public void parsePastStartTag(String ns, String name) throws JiBXException { 764 if (toStart().equals(name) && verifyNamespace(ns)) { 765 advance(); 766 } else { 767 throwStartTagNameError(ns, name); 768 } 769 } 770 771 782 public boolean parseIfStartTag(String ns, String name) 783 throws JiBXException { 784 if (isAt(ns, name)) { 785 advance(); 786 return true; 787 } else { 788 return false; 789 } 790 } 791 792 804 public void parsePastEndTag(String ns, String name) throws JiBXException { 805 if (toEnd().equals(name) && verifyNamespace(ns)) { 806 advance(); 807 } else { 808 throwEndTagNameError(ns, name); 809 } 810 } 811 812 821 public boolean isEnd() throws JiBXException { 822 try { 823 int type = m_parser.getEventType(); 824 while (type != XmlPullParser.START_TAG && 825 type != XmlPullParser.END_TAG) { 826 type = m_parser.next(); 827 } 828 return m_parser.getEventType() == XmlPullParser.END_TAG; 829 } catch (IOException ex) { 830 throw new JiBXException("Error accessing document", ex); 831 } catch (XmlPullParserException ex) { 832 throw new JiBXException 833 ("Error parsing document " + buildPositionString(), ex); 834 } 835 } 836 837 845 public String accumulateText() throws JiBXException { 846 try { 847 String text = null; 848 StringBuffer buff = null; 849 loop: while (true) { 850 switch (m_parser.getEventType()) { 851 852 case XmlPullParser.ENTITY_REF: 853 if (m_parser.getText() == null) { 854 throw new JiBXException 855 ("Unexpanded entity reference in text at " + 856 buildPositionString()); 857 } 858 860 case XmlPullParser.CDSECT: 861 case XmlPullParser.TEXT: 862 if (text == null) { 863 text = m_parser.getText(); 864 } else { 865 if (buff == null) { 866 buff = new StringBuffer (text); 867 } 868 buff.append(m_parser.getText()); 869 } 870 break; 871 872 case XmlPullParser.END_TAG: 873 case XmlPullParser.START_TAG: 874 case XmlPullParser.END_DOCUMENT: 875 break loop; 876 877 default: 878 break; 879 880 } 881 m_parser.nextToken(); 882 } 883 if (buff == null) { 884 return (text == null) ? "" : text; 885 } else { 886 return buff.toString(); 887 } 888 } catch (IOException ex) { 889 throw new JiBXException("Error accessing document", ex); 890 } catch (XmlPullParserException ex) { 891 throw new JiBXException 892 ("Error parsing document " + buildPositionString(), ex); 893 } 894 } 895 896 903 public String parseContentText() throws JiBXException { 904 return accumulateText(); 905 } 906 907 919 public String parseContentText(String ns, String tag) 920 throws JiBXException { 921 try { 922 String text = accumulateText(); 923 switch (m_parser.getEventType()) { 924 925 case XmlPullParser.END_TAG: 926 if (m_parser.getName().equals(tag) && 927 verifyNamespace(ns)) { 928 m_parser.nextToken(); 929 return text; 930 } else { 931 throwEndTagNameError(ns, tag); 932 } 933 934 case XmlPullParser.START_TAG: 935 throw new JiBXException("Expected " + 936 buildNameString(ns, tag) + " end tag, " + 937 "found " + currentNameString() + " start tag " + 938 buildPositionString()); 939 940 case XmlPullParser.END_DOCUMENT: 941 throw new JiBXException("Expected " + 942 buildNameString(ns, tag) + " end tag, " + 943 "found end of document " + buildPositionString()); 944 945 } 946 return null; 947 } catch (IOException ex) { 948 throw new JiBXException("Error accessing document", ex); 949 } catch (XmlPullParserException ex) { 950 throw new JiBXException 951 ("Error parsing document " + buildPositionString(), ex); 952 } 953 } 954 955 966 public int parseContentInt(String ns, String tag) throws JiBXException { 967 String text = parseContentText(ns, tag); 968 try { 969 return Utility.parseInt(text); 970 } catch (JiBXException ex) { 971 throw new JiBXException(ex.getMessage() + ' ' + 972 buildPositionString(), ex.getRootCause()); 973 } 974 } 975 976 988 public String parseElementText(String ns, String tag) throws JiBXException { 989 parsePastStartTag(ns, tag); 990 return parseContentText(ns, tag); 991 } 992 993 1006 public String parseElementText(String ns, String tag, String dflt) 1007 throws JiBXException { 1008 if (parseIfStartTag(ns, tag)) { 1009 return parseContentText(ns, tag); 1010 } else { 1011 return dflt; 1012 } 1013 } 1014 1015 1026 public String attributeText(String ns, String name) throws JiBXException { 1027 String value = getAttributeValue(ns, name); 1028 if (value == null) { 1029 throw new JiBXException("Missing required attribute " + 1030 buildNameString(ns, name) + " " + buildPositionString()); 1031 } else { 1032 return value; 1033 } 1034 } 1035 1036 1047 public String attributeText(String ns, String name, String dflt) { 1048 String value = getAttributeValue(ns, name); 1049 if (value == null) { 1050 return dflt; 1051 } else { 1052 return value; 1053 } 1054 } 1055 1056 1066 public Object findID(String id, int index) throws JiBXException { 1067 HashMap map = m_idMaps[index]; 1068 if (map != null) { 1069 Object obj = map.get(id); 1070 if (obj == null || obj instanceof BackFillHolder) { 1071 return null; 1072 } else if (m_idClasses == null || 1073 m_idClasses[index].equals(obj.getClass().getName())) { 1074 return obj; 1075 } else { 1076 throwStartTagException 1077 ("IDREF element content mapped to wrong type"); 1078 } 1079 } 1080 return null; 1081 } 1082 1083 1092 public Object findDefinedID(String id, int index) throws JiBXException { 1093 Object obj = findID(id, index); 1094 if (obj == null) { 1095 throwStartTagException("ID " + id + " not defined"); 1096 } 1097 return obj; 1098 } 1099 1100 1114 public Object parseElementForwardIDREF(String ns, String tag, int index) 1115 throws JiBXException { 1116 parsePastStartTag(ns, tag); 1117 m_idref = parseContentText(ns, tag); 1118 return findID(m_idref, index); 1119 } 1120 1121 1134 public Object attributeForwardIDREF(String ns, String name, int index) 1135 throws JiBXException { 1136 m_idref = attributeText(ns, name); 1137 return findID(m_idref, index); 1138 } 1139 1140 1154 public Object parseElementExistingIDREF(String ns, String tag, int index) 1155 throws JiBXException { 1156 parsePastStartTag(ns, tag); 1157 m_idref = parseContentText(ns, tag); 1158 return findDefinedID(m_idref, index); 1159 } 1160 1161 1173 public Object attributeExistingIDREF(String ns, String name, int index) 1174 throws JiBXException { 1175 m_idref = attributeText(ns, name); 1176 return findDefinedID(m_idref, index); 1177 } 1178 1179 1191 public int attributeInt(String ns, String name) throws JiBXException { 1192 String text = attributeText(ns, name); 1193 try { 1194 return Utility.parseInt(text); 1195 } catch (JiBXException ex) { 1196 throw new JiBXException(ex.getMessage() + ' ' + 1197 buildPositionString(), ex.getRootCause()); 1198 } 1199 } 1200 1201 1213 public int attributeInt(String ns, String name, int dflt) 1214 throws JiBXException { 1215 String value = getAttributeValue(ns, name); 1216 if (value == null) { 1217 return dflt; 1218 } else { 1219 try { 1220 return Utility.parseInt(value); 1221 } catch (JiBXException ex) { 1222 throw new JiBXException(ex.getMessage() + ' ' + 1223 buildPositionString(), ex.getRootCause()); 1224 } 1225 } 1226 } 1227 1228 1240 public int parseElementInt(String ns, String tag) throws JiBXException { 1241 parsePastStartTag(ns, tag); 1242 return parseContentInt(ns, tag); 1243 } 1244 1245 1259 public int parseElementInt(String ns, String tag, int dflt) 1260 throws JiBXException { 1261 if (parseIfStartTag(ns, tag)) { 1262 return parseContentInt(ns, tag); 1263 } else { 1264 return dflt; 1265 } 1266 } 1267 1268 1279 public int convertEnum(String target, String [] enums, int[] vals) 1280 throws JiBXException { 1281 if (target == null) { 1282 throwStartTagException("Missing required enumeration value"); 1283 } 1284 try { 1285 return Utility.enumValue(target, enums, vals); 1286 } catch (JiBXException ex) { 1287 throw new JiBXException(ex.getMessage() + ' ' + 1288 buildPositionString()); 1289 } 1290 } 1291 1292 1305 public int convertEnum(String target, String [] enums, int[] vals, int dflt) 1306 throws JiBXException { 1307 if (target == null) { 1308 return dflt; 1309 } 1310 try { 1311 return Utility.enumValue(target, enums, vals); 1312 } catch (JiBXException ex) { 1313 throw new JiBXException(ex.getMessage() + ' ' + 1314 buildPositionString()); 1315 } 1316 } 1317 1318 1333 public int attributeEnumeration(String ns, String name, String [] enums, 1334 int[] vals) throws JiBXException { 1335 return convertEnum(getAttributeValue(ns, name), enums, vals); 1336 } 1337 1338 1354 public int attributeEnumeration(String ns, String name, String [] enums, 1355 int[] vals, int dflt) throws JiBXException { 1356 return convertEnum(getAttributeValue(ns, name), enums, vals, dflt); 1357 } 1358 1359 1374 public int parseContentEnumeration(String ns, String tag, String [] enums, 1375 int[] vals) throws JiBXException { 1376 return convertEnum(parseContentText(ns, tag), enums, vals); 1377 } 1378 1379 1395 public int parseElementEnumeration(String ns, String tag, String [] enums, 1396 int[] vals, int dflt) throws JiBXException { 1397 if (parseIfStartTag(ns, tag)) { 1398 String text = parseContentText(ns, tag); 1399 return convertEnum(text, enums, vals, dflt); 1400 } else { 1401 return dflt; 1402 } 1403 } 1404 1405 1414 public byte convertByte(String text) throws JiBXException { 1415 try { 1416 return Utility.parseByte(text); 1417 } catch (JiBXException ex) { 1418 throw new JiBXException(ex.getMessage() + ' ' + 1419 buildPositionString(), ex.getRootCause()); 1420 } 1421 } 1422 1423 1434 public byte attributeByte(String ns, String name) throws JiBXException { 1435 return convertByte(attributeText(ns, name)); 1436 } 1437 1438 1449 public byte attributeByte(String ns, String name, byte dflt) 1450 throws JiBXException { 1451 String text = getAttributeValue(ns, name); 1452 if (text == null) { 1453 return dflt; 1454 } else { 1455 return convertByte(text); 1456 } 1457 } 1458 1459 1471 public byte parseContentByte(String ns, String tag) throws JiBXException { 1472 return convertByte(parseContentText(ns, tag)); 1473 } 1474 1475 1487 public byte parseElementByte(String ns, String tag) throws JiBXException { 1488 parsePastStartTag(ns, tag); 1489 return parseContentByte(ns, tag); 1490 } 1491 1492 1505 public byte parseElementByte(String ns, String tag, byte dflt) 1506 throws JiBXException { 1507 if (parseIfStartTag(ns, tag)) { 1508 return convertByte(parseContentText(ns, tag)); 1509 } else { 1510 return dflt; 1511 } 1512 } 1513 1514 1523 public short convertShort(String text) throws JiBXException { 1524 try { 1525 return Utility.parseShort(text); 1526 } catch (JiBXException ex) { 1527 throw new JiBXException(ex.getMessage() + ' ' + 1528 buildPositionString(), ex.getRootCause()); 1529 } 1530 } 1531 1532 1543 public short attributeShort(String ns, String name) throws JiBXException { 1544 return convertShort(attributeText(ns, name)); 1545 } 1546 1547 1558 public short attributeShort(String ns, String name, short dflt) 1559 throws JiBXException { 1560 String text = getAttributeValue(ns, name); 1561 if (text == null) { 1562 return dflt; 1563 } else { 1564 return convertShort(text); 1565 } 1566 } 1567 1568 1580 public short parseContentShort(String ns, String tag) throws JiBXException { 1581 return convertShort(parseContentText(ns, tag)); 1582 } 1583 1584 1596 public short parseElementShort(String ns, String tag) throws JiBXException { 1597 parsePastStartTag(ns, tag); 1598 return parseContentShort(ns, tag); 1599 } 1600 1601 1614 public short parseElementShort(String ns, String tag, short dflt) 1615 throws JiBXException { 1616 if (parseIfStartTag(ns, tag)) { 1617 return convertShort(parseContentText(ns, tag)); 1618 } else { 1619 return dflt; 1620 } 1621 } 1622 1623 1632 public char convertChar(String text) throws JiBXException { 1633 try { 1634 return Utility.parseChar(text); 1635 } catch (JiBXException ex) { 1636 throw new JiBXException(ex.getMessage() + ' ' + 1637 buildPositionString(), ex.getRootCause()); 1638 } 1639 } 1640 1641 1652 public char attributeChar(String ns, String name) throws JiBXException { 1653 return convertChar(attributeText(ns, name)); 1654 } 1655 1656 1667 public char attributeChar(String ns, String name, char dflt) 1668 throws JiBXException { 1669 String text = getAttributeValue(ns, name); 1670 if (text == null) { 1671 return dflt; 1672 } else { 1673 return convertChar(text); 1674 } 1675 } 1676 1677 1689 public char parseContentChar(String ns, String tag) throws JiBXException { 1690 return convertChar(parseContentText(ns, tag)); 1691 } 1692 1693 1705 public char parseElementChar(String ns, String tag) throws JiBXException { 1706 parsePastStartTag(ns, tag); 1707 return parseContentChar(ns, tag); 1708 } 1709 1710 1723 public char parseElementChar(String ns, String tag, char dflt) 1724 throws JiBXException { 1725 if (parseIfStartTag(ns, tag)) { 1726 return convertChar(parseContentText(ns, tag)); 1727 } else { 1728 return dflt; 1729 } 1730 } 1731 1732 1741 public long convertLong(String text) throws JiBXException { 1742 try { 1743 return Utility.parseLong(text); 1744 } catch (JiBXException ex) { 1745 throw new JiBXException(ex.getMessage() + ' ' + 1746 buildPositionString(), ex.getRootCause()); 1747 } 1748 } 1749 1750 1761 public long attributeLong(String ns, String name) throws JiBXException { 1762 return convertLong(attributeText(ns, name)); 1763 } 1764 1765 1776 public long attributeLong(String ns, String name, long dflt) 1777 throws JiBXException { 1778 String text = getAttributeValue(ns, name); 1779 if (text == null) { 1780 return dflt; 1781 } else { 1782 return convertLong(text); 1783 } 1784 } 1785 1786 1798 public long parseElementLong(String ns, String tag) throws JiBXException { 1799 parsePastStartTag(ns, tag); 1800 return convertLong(parseContentText(ns, tag)); 1801 } 1802 1803 1816 public long parseElementLong(String ns, String tag, long dflt) 1817 throws JiBXException { 1818 if (parseIfStartTag(ns, tag)) { 1819 return convertLong(parseContentText(ns, tag)); 1820 } else { 1821 return dflt; 1822 } 1823 } 1824 1825 1834 public boolean convertBoolean(String text) throws JiBXException { 1835 if ("true".equals(text) || "1".equals(text)) { 1836 return true; 1837 } else if ("false".equals(text) || "0".equals(text)) { 1838 return false; 1839 } 1840 throw new JiBXException("Invalid boolean value " + 1841 buildPositionString()); 1842 } 1843 1844 1856 public boolean attributeBoolean(String ns, String name) 1857 throws JiBXException { 1858 return convertBoolean(attributeText(ns, name)); 1859 } 1860 1861 1872 public boolean attributeBoolean(String ns, String name, boolean dflt) 1873 throws JiBXException { 1874 String text = getAttributeValue(ns, name); 1875 if (text == null) { 1876 return dflt; 1877 } else { 1878 return convertBoolean(text); 1879 } 1880 } 1881 1882 1894 public boolean parseElementBoolean(String ns, String tag) 1895 throws JiBXException { 1896 parsePastStartTag(ns, tag); 1897 return convertBoolean(parseContentText(ns, tag)); 1898 } 1899 1900 1913 public boolean parseElementBoolean(String ns, String tag, boolean dflt) 1914 throws JiBXException { 1915 if (parseIfStartTag(ns, tag)) { 1916 return convertBoolean(parseContentText(ns, tag)); 1917 } else { 1918 return dflt; 1919 } 1920 } 1921 1922 1931 public float convertFloat(String text) throws JiBXException { 1932 try { 1933 return Utility.parseFloat(text); 1934 } catch (JiBXException ex) { 1935 throw new JiBXException(ex.getMessage() + ' ' + 1936 buildPositionString(), ex.getRootCause()); 1937 } 1938 } 1939 1940 1951 public float attributeFloat(String ns, String name) throws JiBXException { 1952 return convertFloat(attributeText(ns, name)); 1953 } 1954 1955 1966 public float attributeFloat(String ns, String name, float dflt) 1967 throws JiBXException { 1968 String text = getAttributeValue(ns, name); 1969 if (text == null) { 1970 return dflt; 1971 } else { 1972 return convertFloat(text); 1973 } 1974 } 1975 1976 1988 public float parseElementFloat(String ns, String tag) throws JiBXException { 1989 parsePastStartTag(ns, tag); 1990 return convertFloat(parseContentText(ns, tag)); 1991 } 1992 1993 2006 public float parseElementFloat(String ns, String tag, float dflt) 2007 throws JiBXException { 2008 if (parseIfStartTag(ns, tag)) { 2009 return convertFloat(parseContentText(ns, tag)); 2010 } else { 2011 return dflt; 2012 } 2013 } 2014 2015 2024 public double convertDouble(String text) throws JiBXException { 2025 try { 2026 return Utility.parseDouble(text); 2027 } catch (JiBXException ex) { 2028 throw new JiBXException(ex.getMessage() + ' ' + 2029 buildPositionString(), ex.getRootCause()); 2030 } 2031 } 2032 2033 2045 public double attributeDouble(String ns, String name) throws JiBXException { 2046 return convertDouble(attributeText(ns, name)); 2047 } 2048 2049 2060 public double attributeDouble(String ns, String name, double dflt) 2061 throws JiBXException { 2062 String text = getAttributeValue(ns, name); 2063 if (text == null) { 2064 return dflt; 2065 } else { 2066 return convertDouble(text); 2067 } 2068 } 2069 2070 2082 public double parseElementDouble(String ns, String tag) 2083 throws JiBXException { 2084 parsePastStartTag(ns, tag); 2085 return convertDouble(parseContentText(ns, tag)); 2086 } 2087 2088 2101 public double parseElementDouble(String ns, String tag, double dflt) 2102 throws JiBXException { 2103 if (parseIfStartTag(ns, tag)) { 2104 return convertDouble(parseContentText(ns, tag)); 2105 } else { 2106 return dflt; 2107 } 2108 } 2109 2110 2119 public Date convertDate(String text) throws JiBXException { 2120 try { 2121 return new Date(Utility.parseDateTime(text)); 2122 } catch (JiBXException ex) { 2123 throw new JiBXException(ex.getMessage() + ' ' + 2124 buildPositionString(), ex.getRootCause()); 2125 } 2126 } 2127 2128 2140 public Date attributeDate(String ns, String name) throws JiBXException { 2141 return convertDate(attributeText(ns, name)); 2142 } 2143 2144 2156 public Date attributeDate(String ns, String name, Date dflt) 2157 throws JiBXException { 2158 String text = getAttributeValue(ns, name); 2159 if (text == null) { 2160 return dflt; 2161 } else { 2162 return convertDate(text); 2163 } 2164 } 2165 2166 2178 public Date parseElementDate(String ns, String tag) throws JiBXException { 2179 parsePastStartTag(ns, tag); 2180 return convertDate(parseContentText(ns, tag)); 2181 } 2182 2183 2197 public Date parseElementDate(String ns, String tag, Date dflt) 2198 throws JiBXException { 2199 if (parseIfStartTag(ns, tag)) { 2200 return convertDate(parseContentText(ns, tag)); 2201 } else { 2202 return dflt; 2203 } 2204 } 2205 2206 2216 public void registerBackFill(String id, int index, BackFillReference fill) 2217 throws JiBXException { 2218 HashMap map = m_idMaps[index]; 2219 if (map == null) { 2220 m_idMaps[index] = map = new HashMap(); 2221 } 2222 Object obj = map.get(id); 2223 if (obj == null) { 2224 String xclass = (m_idClasses == null) ? null : m_idClasses[index]; 2225 BackFillHolder holder = new BackFillHolder(xclass); 2226 map.put(id, holder); 2227 holder.addBackFill(fill); 2228 } else if (obj instanceof BackFillHolder) { 2229 ((BackFillHolder)obj).addBackFill(fill); 2230 } else { 2231 throw new JiBXException 2232 ("Internal operation error (back fill error) " + 2233 buildPositionString()); 2234 } 2235 } 2236 2237 2247 public void registerBackFill(int index, BackFillReference fill) 2248 throws JiBXException { 2249 registerBackFill(m_idref, index, fill); 2250 } 2251 2252 2263 public void defineID(String id, int index, Object obj) 2264 throws JiBXException { 2265 HashMap map = m_idMaps[index]; 2266 if (map == null) { 2267 m_idMaps[index] = map = new HashMap(); 2268 } 2269 Object prior = map.put(id, obj); 2270 if (prior instanceof BackFillHolder) { 2271 BackFillHolder holder = (BackFillHolder)prior; 2272 String xclass = holder.getExpectedClass(); 2273 if (xclass == null || xclass.equals(obj.getClass().getName())) { 2274 holder.defineValue(obj); 2275 } else { 2276 throw new JiBXException("ID object has wrong type " + 2277 buildPositionString()); 2278 } 2279 } else if (prior != null) { 2280 throw new JiBXException("Duplicate ID definition " + 2281 buildPositionString()); 2282 } 2283 } 2284 2285 2291 protected void mapUnmarshalling(int index) { 2292 Object value = m_unmarshalMap.get(m_names[index]); 2293 if (value instanceof Integer ) { 2294 ArrayList list = new ArrayList(); 2295 list.add(value); 2296 list.add(m_indexes[index]); 2297 m_unmarshalMap.put(m_names[index], list); 2298 } else if (value instanceof ArrayList) { 2299 ArrayList list = (ArrayList)value; 2300 list.add(m_indexes[index]); 2301 } else { 2302 m_unmarshalMap.put(m_names[index], m_indexes[index]); 2303 } 2304 } 2305 2306 2318 public void addUnmarshalling(int index, String ns, String name, 2319 String cname) { 2320 m_namespaces[index] = ns; 2321 m_names[index] = name; 2322 m_unmarshallerClasses[index] = cname; 2323 if (m_unmarshalMap != null && name != null) { 2324 mapUnmarshalling(index); 2325 } 2326 } 2327 2328 2334 public void removeUnmarshalling(int index) { 2335 if (m_unmarshalMap != null && m_names[index] != null) { 2336 Object value = m_unmarshalMap.get(m_names[index]); 2337 if (value instanceof Integer ) { 2338 m_unmarshalMap.remove(m_names[index]); 2339 } else if (value instanceof ArrayList) { 2340 ArrayList list = (ArrayList)value; 2341 list.remove(list.indexOf(m_indexes[index])); 2342 } 2343 } 2344 m_namespaces[index] = null; 2345 m_names[index] = null; 2346 m_unmarshallers[index] = null; 2347 m_unmarshallerClasses[index] = null; 2348 } 2349 2350 2358 public IUnmarshaller getUnmarshaller(int index) throws JiBXException { 2359 if (m_unmarshallers[index] == null) { 2360 2361 Exception ex = null; 2363 try { 2364 2365 Class clas = null; 2367 String name = m_unmarshallerClasses[index]; 2368 ClassLoader loader = 2369 Thread.currentThread().getContextClassLoader(); 2370 if (loader != null) { 2371 try { 2372 clas = loader.loadClass(name); 2373 } catch (ClassNotFoundException e) { } 2374 } 2375 if (clas == null) { 2376 2377 clas = UnmarshallingContext.class.getClassLoader(). 2379 loadClass(name); 2380 } 2381 2382 IUnmarshaller um = (IUnmarshaller)clas.newInstance(); 2384 m_unmarshallers[index] = um; 2385 2386 } catch (ClassNotFoundException e) { 2387 ex = e; 2388 } catch (ClassCastException e) { 2389 ex = e; 2390 } catch (InstantiationException e) { 2391 ex = e; 2392 } catch (IllegalAccessException e) { 2393 ex = e; 2394 } finally { 2395 if (ex != null) { 2396 throw new JiBXException 2397 ("Unable to create unmarshaller of class " + 2398 m_unmarshallerClasses[index] + ": " + ex, ex); 2399 } 2400 } 2401 } 2402 return m_unmarshallers[index]; 2403 } 2404 2405 2416 public IUnmarshaller getUnmarshaller(String ns, String name) 2417 throws JiBXException { 2418 if (m_unmarshalMap == null) { 2419 m_unmarshalMap = new HashMap(); 2420 m_indexes = new Integer [m_names.length]; 2421 for (int i = 0; i < m_names.length; i++) { 2422 m_indexes[i] = new Integer (i); 2423 if (m_names[i] != null) { 2424 mapUnmarshalling(i); 2425 } 2426 } 2427 } 2428 Object value = m_unmarshalMap.get(name); 2429 if (value instanceof Integer ) { 2430 int index = ((Integer )value).intValue(); 2431 String mns = m_namespaces[index]; 2432 if (ns == mns || (ns == null && mns.length() == 0) || 2433 (mns == null && ns.length() == 0) || 2434 (ns != null && ns.equals(mns))) { 2435 return getUnmarshaller(index); 2436 } 2437 } else if (value instanceof ArrayList) { 2438 ArrayList list = (ArrayList)value; 2439 for (int i = 0; i < list.size(); i++) { 2440 int index = ((Integer )list.get(i)).intValue(); 2441 String mns = m_namespaces[index]; 2442 if (ns == mns || (ns == null && mns.length() == 0) || 2443 (mns == null && ns.length() == 0) || 2444 (ns != null && ns.equals(mns))) { 2445 return getUnmarshaller(index); 2446 } 2447 } 2448 } 2449 return null; 2450 } 2451 2452 2460 public Object unmarshalOptionalElement() throws JiBXException { 2461 int type = toTag(); 2462 if (type == XmlPullParser.START_TAG) { 2463 IUnmarshaller unmarshal = 2464 getUnmarshaller(m_parser.getNamespace(), m_parser.getName()); 2465 if (unmarshal != null) { 2466 return unmarshal.unmarshal(null, this); 2467 } 2468 } 2469 return null; 2470 } 2471 2472 2482 public Object unmarshalElement(Class clas) throws JiBXException { 2483 String name = toStart(); 2484 IUnmarshaller unmarshal = 2485 getUnmarshaller(m_parser.getNamespace(), name); 2486 if (unmarshal == null) { 2487 throw new JiBXException("No unmarshaller for element " + 2488 currentNameString() + " " + buildPositionString()); 2489 } else { 2490 Object obj = unmarshal.unmarshal(null, this); 2491 if (!clas.isInstance(obj)) { 2492 throw new JiBXException("Element " + name + 2493 " not compatible with expected type " + clas.getName() + 2494 " " + buildPositionString()); 2495 } 2496 return obj; 2497 } 2498 } 2499 2500 2507 public Object unmarshalElement() throws JiBXException { 2508 String name = toStart(); 2509 IUnmarshaller unmarshal = 2510 getUnmarshaller(m_parser.getNamespace(), name); 2511 if (unmarshal == null) { 2512 throw new JiBXException("No unmarshaller for element " + 2513 currentNameString() + " " + buildPositionString()); 2514 } else { 2515 return unmarshal.unmarshal(null, this); 2516 } 2517 } 2518 2519 2532 public void parsePastElement(String ns, String tag) throws JiBXException { 2533 parsePastStartTag(ns, tag); 2534 int depth = 0; 2535 try { 2536 while (true) { 2537 switch (m_parser.getEventType()) { 2538 2539 case XmlPullParser.END_TAG: 2540 if (depth == 0) { 2541 if (m_parser.getName().equals(tag) && 2542 verifyNamespace(ns)) { 2543 m_parser.nextToken(); 2544 return; 2545 } else { 2546 throwEndTagNameError(ns, tag); 2547 } 2548 } else { 2549 depth--; 2550 } 2551 break; 2552 2553 case XmlPullParser.START_TAG: 2554 depth++; 2555 break; 2556 2557 default: 2558 break; 2559 2560 } 2561 m_parser.nextToken(); 2562 } 2563 } catch (IOException ex) { 2564 throw new JiBXException("Error accessing document", ex); 2565 } catch (XmlPullParserException ex) { 2566 throw new JiBXException 2567 ("Error parsing document " + buildPositionString(), ex); 2568 } 2569 } 2570 2571 2578 public String getElementName() throws JiBXException { 2579 try { 2580 int type = m_parser.getEventType(); 2581 if (type == XmlPullParser.START_TAG || 2582 type == XmlPullParser.END_TAG) { 2583 return m_parser.getName(); 2584 } else { 2585 return null; 2586 } 2587 } catch (XmlPullParserException ex) { 2588 throw new JiBXException 2589 ("Error parsing document " + buildPositionString(), ex); 2590 } 2591 } 2592 2593 2600 public String getElementNamespace() throws JiBXException { 2601 try { 2602 int type = m_parser.getEventType(); 2603 if (type == XmlPullParser.START_TAG || 2604 type == XmlPullParser.END_TAG) { 2605 return m_parser.getNamespace(); 2606 } else { 2607 return null; 2608 } 2609 } catch (XmlPullParserException ex) { 2610 throw new JiBXException 2611 ("Error parsing document " + buildPositionString(), ex); 2612 } 2613 } 2614 2615 2621 public void throwStartTagException(String msg) throws JiBXException { 2622 throw new JiBXException(msg + " at tag " + currentNameString() + 2623 buildPositionString()); 2624 } 2625 2626 2634 public void throwStartTagException(String msg, Exception ex) 2635 throws JiBXException { 2636 throw new JiBXException(msg + " at tag " + currentNameString() + 2637 buildPositionString(), ex); 2638 } 2639 2640 2646 public void throwException(String msg) throws JiBXException { 2647 throw new JiBXException(msg + " " + buildPositionString()); 2648 } 2649 2650 2657 public void throwException(String msg, Exception ex) throws JiBXException { 2658 throw new JiBXException(msg + " " + buildPositionString(), ex); 2659 } 2660 2661 2672 public Object unmarshalDocument(InputStream ins, String enc) 2673 throws JiBXException { 2674 setDocument(ins, enc); 2675 return unmarshalElement(); 2676 } 2677 2678 2687 public Object unmarshalDocument(Reader rdr) throws JiBXException { 2688 setDocument(rdr); 2689 return unmarshalElement(); 2690 } 2691 2692 2704 public Object unmarshalDocument(InputStream ins, String name, String enc) 2705 throws JiBXException { 2706 setDocument(ins, name, enc); 2707 return unmarshalElement(); 2708 } 2709 2710 2720 public Object unmarshalDocument(Reader rdr, String name) 2721 throws JiBXException { 2722 setDocument(rdr, name); 2723 return unmarshalElement(); 2724 } 2725 2726 2731 public String getDocumentName() { 2732 return m_docName; 2733 } 2734 2735 2741 public String getInputEncoding() { 2742 return m_streamWrapper.getEncoding(); 2743 } 2744 2745 2754 public void pushObject(Object obj) { 2755 int depth = m_stackDepth; 2756 if (depth >= m_objectStack.length) { 2757 Object [] stack = new Object [depth*2]; 2758 System.arraycopy(m_objectStack, 0, stack, 0, depth); 2759 m_objectStack = stack; 2760 } 2761 m_objectStack[depth] = obj; 2762 m_stackDepth++; 2763 if (obj instanceof ITrackSourceImpl) { 2764 ((ITrackSourceImpl)obj).jibx_setSource(m_docName, 2765 m_parser.getLineNumber(), m_parser.getColumnNumber()); 2766 } 2767 } 2768 2769 2774 public void popObject() throws JiBXException { 2775 if (m_stackDepth > 0) { 2776 --m_stackDepth; 2777 } else { 2778 throw new JiBXException("No object on stack"); 2779 } 2780 } 2781 2782 2790 public int getStackDepth() { 2791 return m_stackDepth; 2792 } 2793 2794 2804 public Object getStackObject(int depth) { 2805 if (depth >= 0 && depth < m_stackDepth) { 2806 return m_objectStack[m_stackDepth-depth-1]; 2807 } else { 2808 throw new ArrayIndexOutOfBoundsException ("Depth " + depth + 2809 " is out of range"); 2810 } 2811 } 2812 2813 2819 public Object getStackTop() { 2820 if (m_stackDepth > 0) { 2821 return m_objectStack[m_stackDepth-1]; 2822 } else { 2823 return null; 2824 } 2825 } 2826 2827 2833 public int getActiveNamespaceCount() throws JiBXException { 2834 try { 2835 return m_parser.getNamespaceCount(m_parser.getDepth()); 2836 } catch (XmlPullParserException e) { 2837 throw new JiBXException 2838 ("Error parsing document " + buildPositionString(), e); 2839 } 2840 } 2841 2842 2849 public String getActiveNamespaceUri(int index) throws JiBXException { 2850 try { 2851 return m_parser.getNamespaceUri(index); 2852 } catch (XmlPullParserException e) { 2853 throw new JiBXException 2854 ("Error parsing document " + buildPositionString(), e); 2855 } 2856 } 2857 2858 2865 public String getActiveNamespacePrefix(int index) throws JiBXException { 2866 try { 2867 return m_parser.getNamespacePrefix(index); 2868 } catch (XmlPullParserException e) { 2869 throw new JiBXException 2870 ("Error parsing document " + buildPositionString(), e); 2871 } 2872 } 2873 2874 2879 public void skipElement() throws JiBXException { 2880 2881 if (!isEnd()) { 2883 2884 next(); 2886 2887 int depth = 1; 2889 while (depth > 0) { 2890 if (isEnd()) { 2891 depth--; 2892 } else { 2893 depth++; 2894 } 2895 next(); 2896 } 2897 2898 } 2899 } 2900 2901 2910 public int next() throws JiBXException { 2911 try { 2912 return m_parser.next(); 2913 } catch (IOException ex) { 2914 throw new JiBXException("Error accessing document", ex); 2915 } catch (XmlPullParserException ex) { 2916 throw new JiBXException 2917 ("Error parsing document " + buildPositionString(), ex); 2918 } 2919 } 2920 2921 2929 public int nextToken() throws JiBXException { 2930 try { 2931 return m_parser.nextToken(); 2932 } catch (IOException ex) { 2933 throw new JiBXException("Error accessing document", ex); 2934 } catch (XmlPullParserException ex) { 2935 throw new JiBXException 2936 ("Error parsing document " + buildPositionString(), ex); 2937 } 2938 } 2939 2940 2948 public int currentEvent() throws JiBXException { 2949 try { 2950 return m_parser.getEventType(); 2951 } catch (XmlPullParserException ex) { 2952 throw new JiBXException 2953 ("Error parsing document " + buildPositionString(), ex); 2954 } 2955 } 2956 2957 2964 public String getName() throws JiBXException { 2965 return m_parser.getName(); 2966 } 2967 2968 2975 public String getNamespace() throws JiBXException { 2976 return m_parser.getNamespace(); 2977 } 2978 2979 2986 public String getPrefix() throws JiBXException { 2987 return m_parser.getPrefix(); 2988 } 2989 2990 2997 public int getAttributeCount() throws JiBXException { 2998 return m_parser.getAttributeCount(); 2999 } 3000 3001 3009 public String getAttributeName(int index) throws JiBXException { 3010 return m_parser.getAttributeName(index); 3011 } 3012 3013 3021 public String getAttributeNamespace(int index) throws JiBXException { 3022 return m_parser.getAttributeNamespace(index); 3023 } 3024 3025 3034 public String getAttributePrefix(int index) throws JiBXException { 3035 return m_parser.getAttributePrefix(index); 3036 } 3037 3038 3046 public String getAttributeValue(int index) throws JiBXException { 3047 return m_parser.getAttributeValue(index); 3048 } 3049 3050 3058 public int getNamespaceCount() throws JiBXException { 3059 try { 3060 int level = m_parser.getDepth(); 3061 return m_parser.getNamespaceCount(level)- 3062 m_parser.getNamespaceCount(level-1); 3063 } catch (XmlPullParserException e) { 3064 throw new JiBXException 3065 ("Error parsing document " + buildPositionString(), e); 3066 } 3067 } 3068 3069 3078 public String getNamespaceUri(int index) throws JiBXException { 3079 try { 3080 int base = m_parser.getNamespaceCount(m_parser.getDepth()-1); 3081 return m_parser.getNamespaceUri(base + index); 3082 } catch (XmlPullParserException e) { 3083 throw new JiBXException 3084 ("Error parsing document " + buildPositionString(), e); 3085 } 3086 } 3087 3088 3097 public String getNamespacePrefix(int index) throws JiBXException { 3098 try { 3099 int base = m_parser.getNamespaceCount(m_parser.getDepth()-1); 3100 return m_parser.getNamespacePrefix(base + index); 3101 } catch (XmlPullParserException e) { 3102 throw new JiBXException 3103 ("Error parsing document " + buildPositionString(), e); 3104 } 3105 } 3106 3107 3113 public String getText() throws JiBXException { 3114 return m_parser.getText(); 3115 } 3116} | Popular Tags |