1 55 package org.jboss.axis.encoding; 56 57 import org.jboss.axis.AxisFault; 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.Message; 60 import org.jboss.axis.MessageContext; 61 import org.jboss.axis.attachments.Attachments; 62 import org.jboss.axis.description.TypeDesc; 63 import org.jboss.axis.message.EnvelopeBuilder; 64 import org.jboss.axis.message.EnvelopeHandler; 65 import org.jboss.axis.message.IDResolver; 66 import org.jboss.axis.message.NullAttributes; 67 import org.jboss.axis.message.SAX2EventRecorder; 68 import org.jboss.axis.message.SOAPElementAxisImpl; 69 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 70 import org.jboss.axis.message.SOAPHandler; 71 import org.jboss.axis.schema.SchemaVersion; 72 import org.jboss.axis.soap.SOAPConstants; 73 import org.jboss.axis.utils.JavaUtils; 74 import org.jboss.axis.utils.Messages; 75 import org.jboss.axis.utils.NSStack; 76 import org.jboss.axis.utils.XMLUtils; 77 import org.jboss.logging.Logger; 78 import org.xml.sax.Attributes ; 79 import org.xml.sax.InputSource ; 80 import org.xml.sax.Locator ; 81 import org.xml.sax.SAXException ; 82 import org.xml.sax.ext.LexicalHandler ; 83 import org.xml.sax.helpers.AttributesImpl ; 84 import org.xml.sax.helpers.DefaultHandler ; 85 86 import javax.xml.namespace.QName ; 87 import javax.xml.parsers.SAXParser ; 88 import javax.xml.rpc.JAXRPCException ; 89 import javax.xml.rpc.holders.Holder ; 90 import javax.xml.soap.SOAPException ; 91 import java.io.IOException ; 92 import java.lang.reflect.Method ; 93 import java.util.ArrayList ; 94 import java.util.HashMap ; 95 96 101 102 public class DeserializationContextImpl extends DefaultHandler implements LexicalHandler , DeserializationContext 103 { 104 private static Logger log = Logger.getLogger(DeserializationContextImpl.class.getName()); 105 106 static final SchemaVersion schemaVersions[] = new SchemaVersion[]{ 107 SchemaVersion.SCHEMA_1999, 108 SchemaVersion.SCHEMA_2000, 109 SchemaVersion.SCHEMA_2001, 110 }; 111 112 private NSStack namespaces = new NSStack(); 113 114 private Locator locator; 115 116 private SOAPHandler topHandler = null; 119 private ArrayList pushedDownHandlers = new ArrayList (); 120 121 private SAX2EventRecorder recorder = null; 123 private SOAPEnvelopeAxisImpl envelope; 124 125 126 private HashMap idMap; 127 private LocalIDResolver localIDs; 128 129 private HashMap fixups; 130 131 static final SOAPHandler nullHandler = new SOAPHandler(); 132 133 protected MessageContext msgContext; 134 135 private boolean doneParsing; 136 protected InputSource inputSource; 137 138 private SOAPElementAxisImpl curElement; 139 private StringBuffer curElementContent; 140 141 protected int startOfMappingsPos = -1; 142 143 protected boolean haveSeenSchemaNS = false; 147 148 private static final Class [] DESERIALIZER_CLASSES = 149 new Class []{String .class, Class .class, QName .class}; 150 private static final String DESERIALIZER_METHOD = "getDeserializer"; 151 152 public void deserializing(boolean isDeserializing) 153 { 154 doneParsing = isDeserializing; 155 } 156 157 163 public DeserializationContextImpl(MessageContext ctx, 164 SOAPHandler initialHandler) 165 { 166 msgContext = ctx; 167 168 if (ctx == null || ctx.isHighFidelity()) 170 recorder = new SAX2EventRecorder(); 171 172 if (initialHandler instanceof EnvelopeBuilder) 173 { 174 envelope = ((EnvelopeBuilder)initialHandler).getEnvelope(); 175 envelope.setRecorder(recorder); 176 } 177 178 pushElementHandler(new EnvelopeHandler(initialHandler)); 179 } 180 181 188 public DeserializationContextImpl(InputSource is, 189 MessageContext ctx, 190 String messageType) 191 { 192 msgContext = ctx; 193 EnvelopeBuilder builder = new EnvelopeBuilder(messageType, getSOAPConstants()); 194 if (ctx == null || ctx.isHighFidelity()) 196 recorder = new SAX2EventRecorder(); 197 198 envelope = builder.getEnvelope(); 199 envelope.setRecorder(recorder); 200 201 pushElementHandler(new EnvelopeHandler(builder)); 202 203 inputSource = is; 204 } 205 206 209 private SOAPConstants getSOAPConstants() 210 { 211 SOAPConstants constants = Constants.DEFAULT_SOAP_VERSION; 212 if (msgContext != null) 213 constants = msgContext.getSOAPConstants(); 214 return constants; 215 } 216 217 225 public DeserializationContextImpl(InputSource is, 226 MessageContext ctx, 227 String messageType, 228 SOAPEnvelopeAxisImpl env) 229 { 230 EnvelopeBuilder builder = new EnvelopeBuilder(env, messageType); 231 232 msgContext = ctx; 233 234 if (ctx == null || ctx.isHighFidelity()) 236 recorder = new SAX2EventRecorder(); 237 238 envelope = builder.getEnvelope(); 239 envelope.setRecorder(recorder); 240 241 pushElementHandler(new EnvelopeHandler(builder)); 242 243 inputSource = is; 244 } 245 246 249 public void parse() throws SAXException 250 { 251 if (inputSource != null) 252 { 253 SAXParser parser = XMLUtils.getSAXParser(); 254 try 255 { 256 parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); 257 parser.parse(inputSource, this); 258 259 try 260 { 261 parser.setProperty("http://xml.org/sax/properties/lexical-handler", nullLexicalHandler); 263 } 264 catch (SAXException se) 265 { 266 } 268 } 269 catch (IOException e) 270 { 271 throw new SAXException (e); 272 } 273 inputSource = null; 274 } 275 } 276 277 280 public SOAPElementAxisImpl getCurElement() 281 { 282 return curElement; 283 } 284 285 288 public void setCurElement(SOAPElementAxisImpl el) 289 { 290 curElement = el; 291 if (curElement != null && curElement.getRecorder() != recorder) 292 { 293 recorder = curElement.getRecorder(); 294 } 295 } 296 297 298 301 public MessageContext getMessageContext() 302 { 303 return msgContext; 304 } 305 306 309 public SOAPEnvelopeAxisImpl getEnvelope() 310 { 311 return envelope; 312 } 313 314 317 public SAX2EventRecorder getRecorder() 318 { 319 return recorder; 320 } 321 322 325 public void setRecorder(SAX2EventRecorder recorder) 326 { 327 this.recorder = recorder; 328 } 329 330 333 public ArrayList getCurrentNSMappings() 334 { 335 return namespaces.cloneFrame(); 336 } 337 338 341 public String getNamespaceURI(String prefix) 342 { 343 String result = namespaces.getNamespaceURI(prefix); 344 if (result != null) 345 return result; 346 347 if (curElement != null) 348 return curElement.getNamespaceURI(prefix); 349 350 return null; 351 } 352 353 359 public QName getQNameFromString(String qNameStr) 360 { 361 if (qNameStr == null) 362 return null; 363 364 int i = qNameStr.indexOf(':'); 366 String nsURI; 367 if (i == -1) 368 { 369 nsURI = getNamespaceURI(""); 370 } 371 else 372 { 373 nsURI = getNamespaceURI(qNameStr.substring(0, i)); 374 } 375 376 return new QName (nsURI, qNameStr.substring(i + 1)); 377 } 378 379 387 public QName getTypeFromXSITypeAttr(String namespace, String localName, 388 Attributes attrs) 389 { 390 String type = Constants.getValue(attrs, Constants.URIS_SCHEMA_XSI, 392 "type"); 393 if (type != null) 394 { 395 return getQNameFromString(type); 397 } 398 return null; 399 } 400 401 409 public QName getTypeFromAttributes(String namespace, String localName, 410 Attributes attrs) 411 { 412 QName typeQName = getTypeFromXSITypeAttr(namespace, localName, attrs); 413 if ((typeQName == null) && Constants.isSOAP_ENC(namespace)) 414 { 415 416 if (namespace.equals(Constants.URI_SOAP12_ENC)) 422 { 423 typeQName = new QName (namespace, localName); 424 } 425 else if (localName.equals(Constants.SOAP_ARRAY.getLocalPart())) 426 { 427 typeQName = Constants.SOAP_ARRAY; 428 } 429 else if (localName.equals(Constants.SOAP_STRING.getLocalPart())) 430 { 431 typeQName = Constants.SOAP_STRING; 432 } 433 else if (localName.equals(Constants.SOAP_BOOLEAN.getLocalPart())) 434 { 435 typeQName = Constants.SOAP_BOOLEAN; 436 } 437 else if (localName.equals(Constants.SOAP_DOUBLE.getLocalPart())) 438 { 439 typeQName = Constants.SOAP_DOUBLE; 440 } 441 else if (localName.equals(Constants.SOAP_FLOAT.getLocalPart())) 442 { 443 typeQName = Constants.SOAP_FLOAT; 444 } 445 else if (localName.equals(Constants.SOAP_INT.getLocalPart())) 446 { 447 typeQName = Constants.SOAP_INT; 448 } 449 else if (localName.equals(Constants.SOAP_LONG.getLocalPart())) 450 { 451 typeQName = Constants.SOAP_LONG; 452 } 453 else if (localName.equals(Constants.SOAP_SHORT.getLocalPart())) 454 { 455 typeQName = Constants.SOAP_SHORT; 456 } 457 else if (localName.equals(Constants.SOAP_BYTE.getLocalPart())) 458 { 459 typeQName = Constants.SOAP_BYTE; 460 } 461 } 462 463 467 if (typeQName == null && attrs != null) 468 { 469 String encURI = getSOAPConstants().getEncodingURI(); 470 String itemType = getSOAPConstants().getAttrItemType(); 471 for (int i = 0; i < attrs.getLength(); i++) 472 { 473 if (encURI.equals(attrs.getURI(i)) && 474 itemType.equals(attrs.getLocalName(i))) 475 { 476 return new QName (encURI, "Array"); 477 } 478 } 479 } 480 481 return typeQName; 482 } 483 484 491 public Deserializer getDeserializerForClass(Class cls) 492 { 493 if (cls == null) 497 { 498 return null; 499 } 500 if (cls.isArray()) 501 { 502 cls = cls.getComponentType(); 503 } 504 if (Holder .class.isAssignableFrom(cls)) 505 { 506 try 507 { 508 cls = cls.getField("value").getType(); 509 } 510 catch (Exception e) 511 { 512 } 513 } 514 Deserializer dser = null; 515 try 516 { 517 Method method = cls.getMethod(DESERIALIZER_METHOD, DESERIALIZER_CLASSES); 518 if (method != null) 519 { 520 TypeDesc typedesc = TypeDesc.getTypeDescForClass(cls); 521 if (typedesc != null) 522 { 523 dser = (Deserializer)method.invoke(null, 524 new Object []{msgContext.getEncodingStyle(), cls, typedesc.getXmlType()}); 525 } 526 } 527 } 528 catch (Exception e) 529 { 530 log.error(Messages.getMessage("noDeser00", cls.getName())); 531 } 532 return dser; 533 } 534 535 542 public boolean isNil(Attributes attrs) 543 { 544 return JavaUtils.isTrueExplicitly(Constants.getValue(attrs, Constants.QNAMES_NIL), 545 false); 546 } 547 548 552 public final Deserializer getDeserializer(Class cls, QName xmlType) 553 { 554 if (xmlType == null) 555 return null; 556 557 log.debug("Enter:getDeserializer: [class=" + cls + ",xmlType=" + xmlType + "]"); 558 559 DeserializerFactory dserF = null; 560 Deserializer dser = null; 561 try 562 { 563 dserF = (DeserializerFactory)getTypeMapping(). 564 getDeserializer(cls, xmlType); 565 } 566 catch (JAXRPCException e) 567 { 568 log.error(Messages.getMessage("noFactory00", xmlType.toString())); 569 } 570 if (dserF != null) 571 { 572 try 573 { 574 dser = (Deserializer)dserF.getDeserializerAs(Constants.AXIS_SAX); 575 } 576 catch (JAXRPCException e) 577 { 578 log.error(Messages.getMessage("noDeser00", xmlType.toString())); 579 } 580 } 581 582 log.debug("Exit:getDeserializer: " + dser); 583 return dser; 584 } 585 586 593 public final Deserializer getDeserializerForType(QName xmlType) 594 { 595 return getDeserializer(null, xmlType); 596 } 597 598 601 public TypeMapping getTypeMapping() 602 { 603 TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry(); 604 return (TypeMapping)tmr.getTypeMapping(msgContext.getEncodingStyle()); 605 } 606 607 612 public TypeMappingRegistry getTypeMappingRegistry() 613 { 614 return msgContext.getTypeMappingRegistry(); 615 } 616 617 626 public SOAPElementAxisImpl getElementByID(String id) 627 { 628 if ((idMap != null)) 629 { 630 IDResolver resolver = (IDResolver)idMap.get(id); 631 if (resolver != null) 632 { 633 Object ret = resolver.getReferencedObject(id); 634 if (ret instanceof SOAPElementAxisImpl) 635 return (SOAPElementAxisImpl)ret; 636 } 637 } 638 639 return null; 640 } 641 642 652 public Object getObjectByRef(String href) 653 { 654 Object ret = null; 655 if (href != null) 656 { 657 if ((idMap != null)) 658 { 659 IDResolver resolver = (IDResolver)idMap.get(href); 660 if (resolver != null) 661 ret = resolver.getReferencedObject(href); 662 } 663 if (null == ret && !href.startsWith("#")) 664 { 665 Message msg = null; 667 if (null != (msg = msgContext.getCurrentMessage())) 668 { 669 Attachments attch = null; 670 if (null != (attch = msg.getAttachmentsImpl())) 671 { 672 try 673 { 674 ret = attch.getAttachmentByReference(href); 675 } 676 catch (AxisFault e) 677 { 678 throw new RuntimeException (e.toString() + JavaUtils.stackToString(e)); 679 } 680 } 681 } 682 } 683 } 684 685 return ret; 686 } 687 688 697 public void addObjectById(String id, Object obj) 698 { 699 String idStr = '#' + id; 701 if ((idMap == null) || (id == null)) 702 return; 703 704 IDResolver resolver = (IDResolver)idMap.get(idStr); 705 if (resolver == null) 706 return; 707 708 resolver.addReferencedObject(idStr, obj); 709 return; 710 } 711 712 724 public void registerFixup(String href, Deserializer dser) 725 { 726 if (fixups == null) 727 fixups = new HashMap (); 728 729 Deserializer prev = (Deserializer)fixups.put(href, dser); 730 731 if (prev != null && prev != dser) 736 { 737 dser.moveValueTargets(prev); 738 if (dser.getDefaultType() == null) 739 { 740 dser.setDefaultType(prev.getDefaultType()); 741 } 742 } 743 } 744 745 756 public void registerElementByID(String id, SOAPElementAxisImpl elem) 757 { 758 if (localIDs == null) 759 localIDs = new LocalIDResolver(); 760 761 String absID = '#' + id; 762 763 localIDs.addReferencedObject(absID, elem); 764 765 registerResolverForID(absID, localIDs); 766 767 if (fixups != null) 768 { 769 Deserializer dser = (Deserializer)fixups.get(absID); 770 if (dser != null) 771 { 772 elem.setFixupDeserializer(dser); 773 } 774 } 775 } 776 777 781 public void registerResolverForID(String id, IDResolver resolver) 782 { 783 if ((id == null) || (resolver == null)) 784 { 785 return; 787 } 788 789 if (idMap == null) 790 idMap = new HashMap (); 791 792 idMap.put(id, resolver); 793 } 794 795 798 public int getCurrentRecordPos() 799 { 800 if (recorder == null) return -1; 801 return recorder.getLength() - 1; 802 } 803 804 807 public int getStartOfMappingsPos() 808 { 809 if (startOfMappingsPos == -1) 810 { 811 return getCurrentRecordPos() + 1; 812 } 813 814 return startOfMappingsPos; 815 } 816 817 820 public void pushNewElement(SOAPElementAxisImpl elem) 821 { 822 if (log.isDebugEnabled()) 823 { 824 log.debug("Pushing element " + elem.getName()); 825 } 826 827 if (!doneParsing && (recorder != null)) 828 { 829 recorder.newElement(elem); 830 } 831 832 try 833 { 834 if (curElement != null) 835 elem.setParentElement(curElement); 836 } 837 catch (Exception e) 838 { 839 844 log.fatal(Messages.getMessage("exception00"), e); 845 } 846 curElement = elem; 847 848 if (elem.getRecorder() != recorder) 849 recorder = elem.getRecorder(); 850 } 851 852 856 857 public void pushElementHandler(SOAPHandler handler) 858 { 859 if (log.isDebugEnabled()) 860 { 861 log.debug(Messages.getMessage("pushHandler00", "" + handler)); 862 } 863 864 if (topHandler != null) pushedDownHandlers.add(topHandler); 865 topHandler = handler; 866 } 867 868 875 public void replaceElementHandler(SOAPHandler handler) 876 { 877 topHandler = handler; 878 } 879 880 public SOAPHandler popElementHandler() 881 { 882 SOAPHandler result = topHandler; 883 884 int size = pushedDownHandlers.size(); 885 if (size > 0) 886 { 887 topHandler = (SOAPHandler)pushedDownHandlers.remove(size - 1); 888 } 889 else 890 { 891 topHandler = null; 892 } 893 894 if (log.isDebugEnabled()) 895 { 896 if (result == null) 897 { 898 log.debug(Messages.getMessage("popHandler00", "(null)")); 899 } 900 else 901 { 902 log.debug(Messages.getMessage("popHandler00", "" + result)); 903 } 904 } 905 906 return result; 907 } 908 909 boolean processingRef = false; 910 911 public void setProcessingRef(boolean ref) 912 { 913 processingRef = ref; 914 } 915 916 public boolean isProcessingRef() 917 { 918 return processingRef; 919 } 920 921 925 public void startDocument() throws SAXException 926 { 927 if (!doneParsing && (recorder != null)) 929 recorder.startDocument(); 930 } 931 932 935 public void endDocument() throws SAXException 936 { 937 if (log.isDebugEnabled()) 938 { 939 log.debug("Enter: DeserializationContextImpl::endDocument()"); 940 } 941 if (!doneParsing && (recorder != null)) 942 recorder.endDocument(); 943 944 doneParsing = true; 945 946 if (log.isDebugEnabled()) 947 { 948 log.debug("Exit: DeserializationContextImpl::endDocument()"); 949 } 950 } 951 952 955 public boolean isDoneParsing() 956 { 957 return doneParsing; 958 } 959 960 969 public void startPrefixMapping(String prefix, String uri) 970 throws SAXException 971 { 972 if (log.isDebugEnabled()) 973 log.debug("Enter: DeserializationContextImpl::startPrefixMapping(" + prefix + ", " + uri + ")"); 974 975 if ("".equals(uri)) 977 { 978 log.warn("Ignoring invalid namespace mapping: [prefix=" + prefix + ",uri=" + uri + "]"); 979 return; 980 } 981 982 if (!doneParsing && (recorder != null)) 983 { 984 recorder.startPrefixMapping(prefix, uri); 985 } 986 987 if (startOfMappingsPos == -1) 988 { 989 namespaces.push(); 990 startOfMappingsPos = getCurrentRecordPos(); 991 } 992 993 if (prefix != null) 994 { 995 namespaces.add(uri, prefix); 996 } 997 else 998 { 999 namespaces.add(uri, ""); 1000 } 1001 1002 if (!haveSeenSchemaNS && msgContext != null) 1003 { 1004 for (int i = 0; !haveSeenSchemaNS && i < schemaVersions.length; 1009 i++) 1010 { 1011 SchemaVersion schemaVersion = schemaVersions[i]; 1012 if (uri.equals(schemaVersion.getXsdURI()) || 1013 uri.equals(schemaVersion.getXsiURI())) 1014 { 1015 msgContext.setSchemaVersion(schemaVersion); 1016 haveSeenSchemaNS = true; 1017 } 1018 } 1019 } 1020 1021 if (topHandler != null) 1022 { 1023 topHandler.startPrefixMapping(prefix, uri); 1024 } 1025 1026 if (log.isDebugEnabled()) 1027 log.debug("Exit: DeserializationContextImpl::startPrefixMapping()"); 1028 } 1029 1030 public void endPrefixMapping(String prefix) 1031 throws SAXException 1032 { 1033 if (log.isDebugEnabled()) 1034 { 1035 log.debug("Enter: DeserializationContextImpl::endPrefixMapping(" + prefix + ")"); 1036 } 1037 1038 if (!doneParsing && (recorder != null)) 1039 { 1040 recorder.endPrefixMapping(prefix); 1041 } 1042 1043 if (topHandler != null) 1044 { 1045 topHandler.endPrefixMapping(prefix); 1046 } 1047 1048 if (log.isDebugEnabled()) 1049 { 1050 log.debug("Exit: DeserializationContextImpl::endPrefixMapping()"); 1051 } 1052 } 1053 1054 public void setDocumentLocator(Locator locator) 1055 { 1056 if (!doneParsing && (recorder != null)) 1057 { 1058 recorder.setDocumentLocator(locator); 1059 } 1060 this.locator = locator; 1061 } 1062 1063 public Locator getDocumentLocator() 1064 { 1065 return locator; 1066 } 1067 1068 public void characters(char[] p1, int p2, int p3) throws SAXException 1069 { 1070 if (!doneParsing && (recorder != null)) 1071 { 1072 recorder.characters(p1, p2, p3); 1073 1074 if (curElement != null) 1075 { 1076 if (curElementContent == null) 1077 curElementContent = new StringBuffer (); 1078 1079 String text = new String (p1, p2, p3); 1080 curElementContent.append(text); 1081 } 1082 } 1083 if (topHandler != null) 1084 { 1085 topHandler.characters(p1, p2, p3); 1086 } 1087 } 1088 1089 public void ignorableWhitespace(char[] p1, int p2, int p3) throws SAXException 1090 { 1091 if (!doneParsing && (recorder != null)) 1092 { 1093 recorder.ignorableWhitespace(p1, p2, p3); 1094 } 1095 if (topHandler != null) 1096 { 1097 topHandler.ignorableWhitespace(p1, p2, p3); 1098 } 1099 } 1100 1101 public void processingInstruction(String p1, String p2) throws SAXException 1102 { 1103 throw new SAXException (Messages.getMessage("noInstructions00")); 1106 } 1107 1108 public void skippedEntity(String p1) throws SAXException 1109 { 1110 if (!doneParsing && (recorder != null)) 1111 { 1112 recorder.skippedEntity(p1); 1113 } 1114 topHandler.skippedEntity(p1); 1115 } 1116 1117 1123 public void startElement(String namespace, String localName, 1124 String qName, Attributes attributes) 1125 throws SAXException 1126 { 1127 if (log.isDebugEnabled()) 1128 { 1129 log.debug("Enter: DeserializationContextImpl::startElement(" + namespace + ", " + localName + ")"); 1130 } 1131 1132 if (attributes == null || attributes.getLength() == 0) 1133 { 1134 attributes = NullAttributes.singleton; 1135 } 1136 else 1137 { 1138 attributes = new AttributesImpl (attributes); 1139 1140 SOAPConstants soapConstants = getSOAPConstants(); 1141 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) 1142 { 1143 if (attributes.getValue(soapConstants.getAttrHref()) != null && 1144 attributes.getValue(Constants.ATTR_ID) != null) 1145 { 1146 1147 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, 1148 null, Messages.getMessage("noIDandHREFonSameElement"), null, null, null); 1149 1150 throw new SAXException (fault); 1151 1152 } 1153 } 1154 1155 } 1156 1157 SOAPHandler nextHandler = null; 1158 1159 String prefix = ""; 1160 int idx = qName.indexOf(':'); 1161 if (idx > 0) 1162 { 1163 prefix = qName.substring(0, idx); 1164 } 1165 1166 if (topHandler != null) 1167 { 1168 nextHandler = topHandler.onStartChild(namespace, 1169 localName, 1170 prefix, 1171 attributes, 1172 this); 1173 } 1174 1175 if (nextHandler == null) 1176 { 1177 nextHandler = new SOAPHandler(); 1178 } 1179 1180 pushElementHandler(nextHandler); 1181 1182 nextHandler.startElement(namespace, localName, prefix, 1183 attributes, this); 1184 1185 if (!doneParsing && (recorder != null)) 1186 { 1187 recorder.startElement(namespace, localName, qName, 1188 attributes); 1189 if (!doneParsing) 1190 { 1191 curElement.setContentsIndex(recorder.getLength()); 1192 } 1193 } 1194 1195 if (startOfMappingsPos != -1) 1196 { 1197 startOfMappingsPos = -1; 1198 } 1199 else 1200 { 1201 namespaces.push(); 1203 } 1204 1205 if (log.isDebugEnabled()) 1206 { 1207 log.debug("Exit: DeserializationContextImpl::startElement()"); 1208 } 1209 } 1210 1211 1214 public void endElement(String namespace, String localName, String qName) 1215 throws SAXException 1216 { 1217 if (log.isDebugEnabled()) 1218 { 1219 log.debug("Enter: DeserializationContextImpl::endElement(" + namespace + ", " + localName + ")"); 1220 } 1221 1222 if (!doneParsing && (recorder != null)) 1223 { 1224 String text = null; 1225 try 1226 { 1227 if (curElementContent != null) 1228 { 1229 text = curElementContent.toString().trim(); 1230 if (text.length() > 0) 1231 { 1232 log.debug("addTextNode: '" + text + "'"); 1233 curElement.addTextNode(text); 1234 } 1235 curElementContent = null; 1236 } 1237 } 1238 catch (SOAPException e) 1239 { 1240 throw new SAXException ("Cannot add Text child: " + text); 1241 } 1242 1243 recorder.endElement(namespace, localName, qName); 1244 } 1245 1246 try 1247 { 1248 SOAPHandler handler = popElementHandler(); 1249 handler.endElement(namespace, localName, this); 1250 1251 if (topHandler != null) 1252 { 1253 topHandler.onEndChild(namespace, localName, this); 1254 } 1255 else 1256 { 1257 } 1259 1260 } 1261 finally 1262 { 1263 if (curElement != null) 1264 { 1265 curElement = (SOAPElementAxisImpl)curElement.getParentElement(); 1266 } 1267 1268 namespaces.pop(); 1269 1270 if (log.isDebugEnabled()) 1271 { 1272 String name = curElement != null ? 1273 curElement.getClass().getName() + ":" + 1274 curElement.getName() : null; 1275 log.debug("Popped element stack to " + name); 1276 log.debug("Exit: DeserializationContextImpl::endElement()"); 1277 } 1278 } 1279 } 1280 1281 1284 private static class LocalIDResolver implements IDResolver 1285 { 1286 HashMap idMap = null; 1287 1288 1291 public void addReferencedObject(String id, Object referent) 1292 { 1293 if (idMap == null) 1294 { 1295 idMap = new HashMap (); 1296 } 1297 1298 idMap.put(id, referent); 1299 } 1300 1301 1304 public Object getReferencedObject(String href) 1305 { 1306 if ((idMap == null) || (href == null)) 1307 { 1308 return null; 1309 } 1310 return idMap.get(href); 1311 } 1312 } 1313 1314 public void startDTD(java.lang.String name, 1315 java.lang.String publicId, 1316 java.lang.String systemId) 1317 throws SAXException 1318 { 1319 1332 throw new SAXException (Messages.getMessage("noInstructions00")); 1333 1336 } 1337 1338 public void endDTD() 1339 throws SAXException 1340 { 1341 if (recorder != null) 1342 recorder.endDTD(); 1343 } 1344 1345 public void startEntity(java.lang.String name) 1346 throws SAXException 1347 { 1348 if (recorder != null) 1349 recorder.startEntity(name); 1350 } 1351 1352 public void endEntity(java.lang.String name) 1353 throws SAXException 1354 { 1355 if (recorder != null) 1356 recorder.endEntity(name); 1357 } 1358 1359 public void startCDATA() 1360 throws SAXException 1361 { 1362 if (recorder != null) 1363 recorder.startCDATA(); 1364 } 1365 1366 public void endCDATA() 1367 throws SAXException 1368 { 1369 if (recorder != null) 1370 recorder.endCDATA(); 1371 } 1372 1373 public void comment(char[] ch, 1374 int start, 1375 int length) 1376 throws SAXException 1377 { 1378 if (recorder != null) 1379 recorder.comment(ch, start, length); 1380 } 1381 1382 public InputSource resolveEntity(String publicId, String systemId) 1383 { 1384 return XMLUtils.getEmptyInputSource(); 1385 } 1386 1387 1388 private static final NullLexicalHandler nullLexicalHandler = new NullLexicalHandler(); 1389 1390 1396 private static class NullLexicalHandler implements LexicalHandler 1397 { 1398 public void startDTD(String arg0, String arg1, String arg2) throws SAXException {} 1399 public void endDTD() throws SAXException {} 1400 public void startEntity(String arg0) throws SAXException {} 1401 public void endEntity(String arg0) throws SAXException {} 1402 public void startCDATA() throws SAXException {} 1403 public void endCDATA() throws SAXException {} 1404 public void comment(char[] arg0, int arg1, int arg2) throws SAXException {} 1405 } 1406} 1407 1408 | Popular Tags |