1 16 package org.jboss.axis.message; 17 18 20 import org.jboss.axis.AxisFault; 21 import org.jboss.axis.Constants; 22 import org.jboss.axis.MessageContext; 23 import org.jboss.axis.MessagePart; 24 import org.jboss.axis.encoding.DeserializationContext; 25 import org.jboss.axis.encoding.DeserializationContextImpl; 26 import org.jboss.axis.encoding.Deserializer; 27 import org.jboss.axis.encoding.SerializationContext; 28 import org.jboss.axis.encoding.SerializationContextImpl; 29 import org.jboss.axis.enums.Style; 30 import org.jboss.axis.soap.SOAPConstants; 31 import org.jboss.axis.utils.Mapping; 32 import org.jboss.axis.utils.Messages; 33 import org.jboss.axis.utils.XMLUtils; 34 import org.jboss.logging.Logger; 35 import org.w3c.dom.Attr ; 36 import org.w3c.dom.DOMException ; 37 import org.w3c.dom.Document ; 38 import org.w3c.dom.Element ; 39 import org.w3c.dom.NamedNodeMap ; 40 import org.w3c.dom.Node ; 41 import org.w3c.dom.NodeList ; 42 import org.w3c.dom.Text ; 43 import org.xml.sax.Attributes ; 44 import org.xml.sax.ContentHandler ; 45 import org.xml.sax.InputSource ; 46 import org.xml.sax.SAXException ; 47 import org.xml.sax.helpers.AttributesImpl ; 48 49 import javax.xml.namespace.QName ; 50 import javax.xml.rpc.JAXRPCException ; 51 import javax.xml.rpc.encoding.TypeMapping ; 52 import javax.xml.soap.Name ; 53 import javax.xml.soap.SOAPElement ; 54 import javax.xml.soap.SOAPException ; 55 import java.io.PrintWriter ; 56 import java.io.Reader ; 57 import java.io.StringReader ; 58 import java.io.StringWriter ; 59 import java.util.ArrayList ; 60 import java.util.Collections ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 import java.util.Vector ; 64 65 68 public class SOAPElementAxisImpl extends SOAPElementImpl implements SOAPElement , Cloneable 69 { 70 private static Logger log = Logger.getLogger(SOAPElementAxisImpl.class.getName()); 71 72 protected String name; 73 protected String prefix; 74 protected String namespaceURI; 75 protected transient Attributes attributes = NullAttributes.singleton; 76 protected String id; 77 protected String href; 78 protected boolean _isRoot = true; 79 protected SOAPEnvelopeAxisImpl message; 80 81 protected transient DeserializationContext context; 82 83 protected transient QName typeQName; 84 85 protected Vector qNameAttrs; 86 87 protected transient SAX2EventRecorder recorder; 89 protected int startEventIndex; 90 protected int startContentsIndex; 91 protected int endEventIndex = -1; 92 93 protected Element elementRep; 95 96 private SOAPElementAxisImpl parent; 97 98 public ArrayList namespaces; 99 100 103 protected String encodingStyle; 104 105 108 protected Object objectValue; 109 110 private ChildElementList children = new ChildElementList(); 112 113 protected MessagePart soapPart; 114 115 private boolean immutable; 119 120 123 public SOAPElementAxisImpl() 124 { 125 super("unqualified-element"); 126 } 127 128 public SOAPElementAxisImpl(String localPart) 129 { 130 super(localPart); 131 namespaceURI = ""; 132 name = localPart; 133 } 134 135 public SOAPElementAxisImpl(String namespace, String localPart) 136 { 137 super(localPart, null, namespace); 138 namespaceURI = namespace; 139 name = localPart; 140 } 141 142 public SOAPElementAxisImpl(String localPart, String prefix, String namespace) 143 { 144 super(localPart, prefix, namespace); 145 this.namespaceURI = namespace; 146 this.name = localPart; 147 this.prefix = prefix; 148 if (prefix != null && prefix.length() > 0) 149 addMapping(new Mapping(namespace, prefix)); 150 } 151 152 public SOAPElementAxisImpl(Name eltName) 153 { 154 super(eltName); 155 this.namespaceURI = eltName.getURI(); 156 this.name = eltName.getLocalName(); 157 this.prefix = eltName.getPrefix(); 158 if (prefix != null && prefix.length() > 0) 159 addMapping(new Mapping(namespaceURI, prefix)); 160 } 161 162 public SOAPElementAxisImpl(String namespace, String localPart, Object value) 163 { 164 super(localPart, "", namespace); 165 this.namespaceURI = namespace; 166 this.name = localPart; 167 objectValue = value; 168 } 169 170 public SOAPElementAxisImpl(QName name, Object value) 171 { 172 super(name.getLocalPart(), name.getPrefix(), name.getNamespaceURI()); 173 this.namespaceURI = name.getNamespaceURI(); 174 this.prefix = name.getPrefix(); 175 this.name = name.getLocalPart(); 176 objectValue = value; 177 } 178 179 public SOAPElementAxisImpl(Element elem) 180 { 181 super(elem); 182 namespaceURI = elem.getNamespaceURI(); 183 prefix = elem.getPrefix(); 184 name = elem.getLocalName(); 185 elementRep = elem; 186 } 187 188 public SOAPElementAxisImpl(String namespace, String localPart, String prefix, Attributes attributes, DeserializationContext context) 189 throws AxisFault 190 { 191 192 super(localPart, prefix, namespace); 193 this.namespaceURI = namespace; 194 this.name = localPart; 195 this.prefix = prefix; 196 197 if (log.isDebugEnabled()) 198 { 199 log.debug(Messages.getMessage("newElem00", super.toString(), 200 "{" + prefix + "}" + localPart)); 201 for (int i = 0; attributes != null && i < attributes.getLength(); i++) 202 { 203 log.debug(" " + attributes.getQName(i) + " = '" + attributes.getValue(i) + "'"); 204 } 205 } 206 207 this.context = context; 208 this.startEventIndex = context.getStartOfMappingsPos(); 209 210 setNSMappings(context.getCurrentNSMappings()); 211 212 this.recorder = context.getRecorder(); 213 214 if (attributes != null && attributes.getLength() > 0) 215 { 216 this.attributes = attributes; 217 218 typeQName = context.getTypeFromAttributes(namespace, 219 localPart, 220 attributes); 221 222 String rootVal = attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, Constants.ATTR_ROOT); 223 if (rootVal != null) 224 _isRoot = rootVal.equals("1"); 225 226 id = attributes.getValue(Constants.ATTR_ID); 227 if (id != null) 229 { 230 context.registerElementByID(id, this); 231 if (recorder == null) 232 { 233 recorder = new SAX2EventRecorder(); 234 context.setRecorder(recorder); 235 } 236 } 237 238 MessageContext mc = context.getMessageContext(); 241 SOAPConstants sc = (mc != null) ? 242 mc.getSOAPConstants() : 243 SOAPConstants.SOAP11_CONSTANTS; 244 245 href = attributes.getValue(sc.getAttrHref()); 246 247 if (attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, Constants.ATTR_ARRAY_TYPE) != null) 249 typeQName = Constants.SOAP_ARRAY; 250 251 252 encodingStyle = 253 attributes.getValue(sc.getEncodingURI(), 254 Constants.ATTR_ENCODING_STYLE); 255 256 if (Constants.URI_SOAP12_NOENC.equals(encodingStyle)) 258 encodingStyle = null; 259 260 if (encodingStyle != null && 267 sc.equals(SOAPConstants.SOAP12_CONSTANTS) && 268 (mc.getOperationStyle() != Style.MESSAGE)) 269 { 270 TypeMapping tm = mc.getTypeMappingRegistry(). 271 getTypeMapping(encodingStyle); 272 if (tm == null || 273 (tm.equals(mc.getTypeMappingRegistry(). 274 getDefaultTypeMapping()))) 275 { 276 AxisFault badEncodingFault = new AxisFault(Constants.FAULT_SOAP12_DATAENCODINGUNKNOWN, 277 "bad encoding style", null, null); 278 throw badEncodingFault; 279 } 280 } 281 282 } 283 } 284 285 288 Deserializer fixupDeserializer; 289 290 public void setFixupDeserializer(Deserializer dser) 291 { 292 fixupDeserializer = dser; 294 } 295 296 public Deserializer getFixupDeserializer() 297 { 298 return fixupDeserializer; 299 } 300 301 public void setEndIndex(int endIndex) 302 { 303 endEventIndex = endIndex; 304 } 306 307 312 private boolean isDirty; 313 314 public boolean isDirty() 315 { 316 return isDirty; 317 } 319 320 public void setDirty(boolean dirty) 321 { 322 isDirty = dirty; 323 } 324 325 public boolean isRoot() 326 { 327 return _isRoot; 328 } 329 330 public String getID() 331 { 332 return id; 333 } 334 335 public String getHref() 336 { 337 return href; 338 } 339 340 public Attributes getAttributesEx() 341 { 342 return attributes; 343 } 344 345 public Node getFirstChild() 346 { 347 if (children != null && !children.isEmpty()) 348 { 349 return (Node )children.get(0); 350 } 351 else 352 { 353 return null; 354 } 355 } 356 357 public Node getLastChild() 358 { 359 List children = getChildren(); 360 if (children != null) 361 return (Node )children.get(children.size() - 1); 362 else 363 return null; 364 } 365 366 public Node getNextSibling() 367 { 368 SOAPElement parent = getParentElement(); 369 if (parent == null) 370 { 371 return null; 372 } 373 Iterator iter = parent.getChildElements(); 374 Node nextSibling = null; 375 while (iter.hasNext()) 376 { 377 if (iter.next().equals(this)) 378 { 379 if (iter.hasNext()) 380 { 381 return (Node )iter.next(); 382 } 383 else 384 { 385 return null; 386 } 387 } 388 } 389 return nextSibling; } 391 392 public Node getParentNode() 393 { 394 return parent; 395 } 396 397 public Node getPreviousSibling() 398 { 399 SOAPElement parent = getParentElement(); 400 Iterator iter = parent.getChildElements(); 401 Node previousSibling = null; 402 while (iter.hasNext()) 403 { 404 if (iter.next().equals(this)) 405 { 406 return previousSibling; 407 } 408 } 409 return previousSibling; } 411 412 public Node cloneNode(boolean deep) 413 { 414 try 415 { 416 SOAPElementAxisImpl clonedSelf = (SOAPElementAxisImpl)this.clonning(); 417 418 if (deep == true) 419 { 420 if (children != null) 421 { 422 for (int i = 0; i < children.size(); i++) 423 { 424 SOAPElementAxisImpl child = (SOAPElementAxisImpl)children.get(i); 425 if (child != null) 426 { SOAPElementAxisImpl clonedChild = (SOAPElementAxisImpl)child.cloneNode(deep); clonedChild.setParent(clonedSelf); 429 clonedChild.setOwnerDocument(soapPart); 430 } 431 } 432 } 433 } 434 return clonedSelf; 435 } 436 catch (Exception e) 437 { 438 return null; 439 } 440 } 441 442 472 protected Object clonning() throws CloneNotSupportedException 473 { 474 try 475 { 476 SOAPElementAxisImpl clonedME = null; 477 clonedME = (SOAPElementAxisImpl)this.clone(); 478 479 clonedME.setName(name); 480 clonedME.setNamespaceURI(namespaceURI); 481 clonedME.setPrefix(prefix); 482 483 clonedME.setAllAttributes(new AttributesImpl (attributes)); 485 487 clonedME.namespaces = new ArrayList (); 488 if (namespaces != null) 489 { 490 for (int i = 0; i < namespaces.size(); i++) 491 { 492 Mapping namespace = (Mapping)namespaces.get(i); 494 clonedME.addNamespaceDeclaration(namespace.getPrefix(), namespace.getNamespaceURI()); } 496 } 497 clonedME.detachAllChildren(); 499 500 clonedME.setParent(null); 502 clonedME.setDirty(isDirty()); 504 if (encodingStyle != null) 505 { 506 clonedME.setEncodingStyle(new String (encodingStyle)); 507 } 508 clonedME.setRecorder(recorder); 509 return clonedME; 510 } 511 catch (Exception ex) 512 { 513 return null; 514 } 515 } 516 517 public void setAllAttributes(Attributes attrs) 519 { 520 attributes = attrs; 521 } 522 523 public void detachAllChildren() 524 { 525 children.clear(); 526 } 527 528 public NodeList getChildNodes() 529 { 530 NodeListImpl nodeList = new NodeListImpl(); 531 for (int i = 0; i < children.size(); i++) 532 { 533 Node node = (Node )children.get(i); 534 nodeList.addNode(node); 535 } 536 return nodeList; 537 } 538 539 public boolean isSupported(String feature, String version) 540 { 541 return false; } 543 544 public Node appendChild(Node newChild) throws DOMException 545 { 546 super.appendChild(newChild); 547 children.add(newChild); 548 return newChild; 549 } 550 551 555 public void addChild(SOAPElementAxisImpl el) throws SOAPException 556 { 557 558 assertImmutable(); 559 560 el.parent = this; 561 children.add(el); 562 } 563 564 568 private void assertImmutable() 569 { 570 SOAPEnvelopeAxisImpl env = getSOAPEnvelope(); 571 if (env != null && env.isProcessingRPCInvocation() && immutable) 572 throw new JAXRPCException ("Cannot modify an immutable element"); 573 } 574 575 public Node removeChild(Node oldChild) throws DOMException 576 { 577 578 int position = children.indexOf(oldChild); 579 if (position < 0) 580 throw new DOMException (DOMException.NOT_FOUND_ERR, "MessageElement Not found"); 581 582 Iterator it = children.iterator(); 584 while (it.hasNext()) 585 { 586 Node node = (Node )it.next(); 587 if (node.equals(oldChild)) 588 { 589 log.debug("Remove child node: " + node.getNodeName()); 590 it.remove(); 591 } 592 } 593 594 setDirty(true); 595 return oldChild; 596 } 597 598 public Node insertBefore(Node newChild, Node refChild) throws DOMException 599 { 600 int position = children.indexOf(refChild); 601 if (position < 0) position = 0; 602 children.add(position, newChild); 603 setDirty(true); 604 return newChild; 605 } 606 607 public Node replaceChild(Node newChild, Node oldChild) throws DOMException 608 { 609 int position = children.indexOf(oldChild); 610 if (position < 0) 611 throw new DOMException (DOMException.NOT_FOUND_ERR, "MessageElement Not found"); 612 613 children.remove(position); 614 children.add(position, newChild); 615 setDirty(true); 616 return oldChild; 617 } 618 619 625 public Attributes getCompleteAttributes() 626 { 627 if (namespaces == null) 628 return attributes; 629 630 AttributesImpl attrs = null; 631 if (attributes == NullAttributes.singleton) 632 attrs = new AttributesImpl (); 633 else 634 attrs = new AttributesImpl (attributes); 635 636 for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) 637 { 638 Mapping mapping = (Mapping)iterator.next(); 639 String prefix = mapping.getPrefix(); 640 String nsURI = mapping.getNamespaceURI(); 641 attrs.addAttribute(Constants.NS_URI_XMLNS, prefix, 642 "xmlns:" + prefix, nsURI, "CDATA"); 643 } 644 return attrs; 645 } 646 647 public String getName() 648 { 649 return (name); 650 } 651 652 public void setName(String name) 653 { 654 this.name = name; 655 } 656 657 public QName getQName() 658 { 659 return new QName (namespaceURI, name); 660 } 661 662 public void setQName(QName qName) 663 { 664 this.name = qName.getLocalPart(); 665 this.namespaceURI = qName.getNamespaceURI(); 666 } 667 668 public String getPrefix() 669 { 670 return (prefix); 671 } 672 673 public void setPrefix(String prefix) 674 { 675 this.prefix = prefix; 676 } 677 678 public Document getOwnerDocument() 679 { 680 return soapPart; 681 } 682 683 public NamedNodeMap getAttributes() 684 { 685 makeAttributesEditable(); 687 return convertAttrSAXtoDOM(); 688 } 689 690 698 699 private NamedNodeMap convertAttrSAXtoDOM() 700 { 701 try 702 { 703 org.w3c.dom.Document doc = org.jboss.axis.utils.XMLUtils.newDocument(); 704 705 AttributesImpl saxAttrs = (AttributesImpl )attributes; 706 NamedNodeMap domAttributes = new NamedNodeMapImpl(); 707 for (int i = 0; i < saxAttrs.getLength(); i++) 708 { 709 String uri = saxAttrs.getURI(i); 710 String qname = saxAttrs.getQName(i); 711 String value = saxAttrs.getValue(i); 712 713 if (uri != null && uri.trim().length() > 0) 714 { 715 if (uri.equals("intentionalNullURI")) 718 { 719 uri = null; 720 } 721 722 if (uri.equals(Constants.NS_URI_XMLNS) && qname.startsWith("xmlns:") == false) 723 qname = "xmlns:" + qname; 724 725 if (uri.equals(Constants.URI_DEFAULT_SCHEMA_XSI) && qname.startsWith("xsi:") == false) 726 qname = "xsi:" + qname; 727 728 Attr attr = doc.createAttributeNS(uri, qname); 729 attr.setValue(value); 730 domAttributes.setNamedItemNS(attr); 731 } 732 else 733 { 734 735 Attr attr = doc.createAttribute(qname); 736 attr.setValue(value); 737 domAttributes.setNamedItem(attr); 738 } 739 } 740 return domAttributes; 741 742 } 743 catch (Exception ex) 744 { 745 log.error("Cannot convert SAX to DOM attributes", ex); 746 return null; 747 } 748 749 } 750 751 public short getNodeType() 752 { 753 if (false) 754 { 755 return DOCUMENT_FRAGMENT_NODE; 756 } 757 else if (false) 758 { 759 return Node.ELEMENT_NODE; 760 } 761 else 762 { return Node.ELEMENT_NODE; 764 } 765 } 766 767 public void normalize() 768 { 769 } 771 772 public boolean hasAttributes() 773 { 774 return attributes.getLength() > 0; 775 } 776 777 public boolean hasChildNodes() 778 { 779 return children.size() > 0; 780 } 781 782 public String getLocalName() 783 { 784 return name; 785 } 786 787 public String getNamespaceURI() 788 { 789 return (namespaceURI); 790 } 791 792 public String getNodeValue() throws DOMException 793 { 794 throw new DOMException (DOMException.NO_DATA_ALLOWED_ERR, 795 "Cannot use TextNode.get in " + this); 796 } 797 798 public void setNamespaceURI(String nsURI) 799 { 800 namespaceURI = nsURI; 801 } 802 803 public QName getType() 804 { 805 if (typeQName == null && href != null && context != null) 807 { 808 SOAPElementAxisImpl referent = context.getElementByID(href); 809 if (referent != null) 810 { 811 typeQName = referent.getType(); 812 } 813 } 814 return typeQName; 815 } 816 817 public void setType(QName qname) 818 { 819 typeQName = qname; 820 } 821 822 public SAX2EventRecorder getRecorder() 823 { 824 return recorder; 825 } 826 827 public void setRecorder(SAX2EventRecorder rec) 828 { 829 recorder = rec; 830 } 831 832 838 public String getEncodingStyle() 839 { 840 if (encodingStyle == null) 841 { 842 if (parent == null) 843 return ""; 844 return parent.getEncodingStyle(); 845 } 846 return encodingStyle; 847 } 848 849 public void removeContents() 850 { 851 if (children != null) 853 { 854 for (int i = 0; i < children.size(); i++) 855 { 856 try 857 { 858 ((SOAPElementAxisImpl)children.get(i)).setParent(null); 859 } 860 catch (Exception e) 861 { 862 } 863 } 864 children.clear(); 866 } 867 } 868 869 public Iterator getVisibleNamespacePrefixes() 870 { 871 Vector prefixes = new Vector (); 872 873 if (parent != null) 875 { 876 Iterator parentsPrefixes = parent.getVisibleNamespacePrefixes(); 877 if (parentsPrefixes != null) 878 { 879 while (parentsPrefixes.hasNext()) 880 { 881 prefixes.add(parentsPrefixes.next()); 882 } 883 } 884 } 885 Iterator mine = getNamespacePrefixes(); 886 if (mine != null) 887 { 888 while (mine.hasNext()) 889 { 890 prefixes.add(mine.next()); 891 } 892 } 893 return prefixes.iterator(); 894 } 895 896 909 public void setEncodingStyle(String encodingStyle) throws SOAPException 910 { 911 if (encodingStyle == null) 912 { 913 encodingStyle = ""; 914 } 915 916 this.encodingStyle = encodingStyle; 917 918 if (encodingStyle.equals("") == false) 922 { 923 SOAPConstants soapConstants = SOAPConstants.SOAP11_CONSTANTS; 924 addAttribute(getPrefix(soapConstants.getEnvelopeURI()), soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encodingStyle); 925 } 926 } 927 928 private SOAPElementAxisImpl getParent() 929 { 930 return parent; 931 } 932 933 private void setParent(SOAPElementAxisImpl parent) throws SOAPException 934 { 935 this.parent = parent; 936 if (parent != null && !parent.children.contains(this)) 937 { 938 parent.addChild(this); 939 } 940 } 941 942 945 void removeChildren() 946 { 947 while (children.isEmpty() == false) 948 { 949 removeChild((SOAPElementAxisImpl)children.get(0)); 950 } 951 } 952 953 public void setContentsIndex(int index) 954 { 955 startContentsIndex = index; 956 } 957 958 public void setNSMappings(ArrayList namespaces) 959 { 960 this.namespaces = namespaces; 961 } 962 963 public String getPrefix(String namespaceURI) 964 { 965 if ((namespaceURI == null) || (namespaceURI.equals(""))) 966 return null; 967 968 if (href != null && getRealElement() != null) 969 { 970 return getRealElement().getPrefix(namespaceURI); 971 } 972 973 for (int i = 0; namespaces != null && i < namespaces.size(); i++) 974 { 975 Mapping map = (Mapping)namespaces.get(i); 976 if (map.getNamespaceURI().equals(namespaceURI)) 977 return map.getPrefix(); 978 } 979 980 if (parent != null) 981 return parent.getPrefix(namespaceURI); 982 983 return null; 984 } 985 986 public String getNamespaceURI(String prefix) 987 { 988 if (prefix == null) 989 prefix = ""; 990 991 if (href != null && getRealElement() != null) 992 { 993 return getRealElement().getNamespaceURI(prefix); 994 } 995 996 for (int i = 0; namespaces != null && i < namespaces.size(); i++) 997 { 998 Mapping map = (Mapping)namespaces.get(i); 999 if (map.getPrefix().equals(prefix)) 1000 { 1001 return map.getNamespaceURI(); 1002 } 1003 } 1004 1005 if (parent != null) 1006 return parent.getNamespaceURI(prefix); 1007 1008 if (log.isDebugEnabled()) 1009 { 1010 log.debug(Messages.getMessage("noPrefix00", "" + this, prefix)); 1011 } 1012 1013 return null; 1014 } 1015 1016 1021 public Object getObjectValue() 1022 { 1023 Object obj = null; 1024 try 1025 { 1026 obj = getObjectValue(null); 1027 } 1028 catch (Exception e) 1029 { 1030 log.debug("getValue()", e); 1031 } 1032 return obj; 1033 } 1034 1035 1041 public Object getObjectValue(Class cls) throws Exception 1042 { 1043 if (objectValue == null) 1044 { 1045 objectValue = getValueAsType(getType(), cls); 1046 } 1047 return objectValue; 1048 } 1049 1050 1061 public void setObjectValue(Object newValue) throws SOAPException 1062 { 1063 if (children != null && !children.isEmpty()) 1064 { 1065 SOAPException exc = new SOAPException (Messages.getMessage("childPresent")); 1066 log.error(Messages.getMessage("childPresent"), exc); 1067 throw exc; 1068 } 1069 if (elementRep != null) 1070 { 1071 SOAPException exc = new SOAPException (Messages.getMessage("xmlPresent")); 1072 log.error(Messages.getMessage("xmlPresent"), exc); 1073 throw exc; 1074 } 1075 this.objectValue = newValue; 1076 } 1077 1078 public Object getValueAsType(QName type) throws Exception 1079 { 1080 return getValueAsType(type, null); 1081 } 1082 1083 public Object getValueAsType(QName type, Class cls) throws Exception 1084 { 1085 if (context == null) 1086 throw new Exception (Messages.getMessage("noContext00")); 1087 1088 Deserializer dser = null; 1089 if (cls == null) 1090 { 1091 dser = context.getDeserializerForType(type); 1092 } 1093 else 1094 { 1095 dser = context.getDeserializerForClass(cls); 1098 } 1099 if (dser == null) 1100 throw new Exception (Messages.getMessage("noDeser00", "" + type)); 1101 1102 boolean oldVal = context.isDoneParsing(); 1103 ((DeserializationContextImpl)context).deserializing(true); 1104 context.pushElementHandler(new EnvelopeHandler((SOAPHandler)dser)); 1105 1106 publishToHandler((org.xml.sax.ContentHandler )context); 1107 1108 ((DeserializationContextImpl)context).deserializing(oldVal); 1109 1110 return dser.getValue(); 1111 } 1112 1113 protected static class QNameAttr 1114 { 1115 QName name; 1116 QName value; 1117 } 1118 1119 public void addAttribute(String namespace, String localName, 1120 QName value) 1121 { 1122 if (qNameAttrs == null) 1123 qNameAttrs = new Vector (); 1124 1125 QNameAttr attr = new QNameAttr(); 1126 attr.name = new QName (namespace, localName); 1127 attr.value = value; 1128 1129 qNameAttrs.addElement(attr); 1130 } 1132 1133 protected AttributesImpl makeAttributesEditable() 1134 { 1135 if (attributes == null || attributes instanceof NullAttributes) 1136 { 1137 attributes = new AttributesImpl (); 1138 } 1139 else if (!(attributes instanceof AttributesImpl )) 1140 { 1141 attributes = new AttributesImpl (attributes); 1142 } 1143 1144 return (AttributesImpl )attributes; 1145 } 1146 1147 public void addAttribute(String namespace, String localName, String value) 1148 { 1149 AttributesImpl attrs = makeAttributesEditable(); 1150 attrs.addAttribute(namespace, localName, localName, "CDATA", value); 1151 } 1152 1153 public void addAttribute(String prefix, String namespace, String localName, String value) 1154 { 1155 AttributesImpl attrs = makeAttributesEditable(); 1156 String attrName = localName; 1157 if (prefix != null && prefix.length() > 0) 1158 { 1159 attrName = prefix + ":" + localName; 1160 } 1161 attrs.addAttribute(namespace, localName, attrName, "CDATA", value); 1162 } 1163 1164 1169 public void setAttribute(String namespace, String localName, String value) 1170 { 1171 AttributesImpl attrs = makeAttributesEditable(); 1172 int idx = attrs.getIndex(namespace, localName); 1173 if (idx > -1) 1174 { 1175 if (value != null) 1177 { 1178 attrs.setValue(idx, value); 1179 } 1180 else 1181 { 1182 attrs.removeAttribute(idx); 1183 } 1184 return; 1185 } 1186 1187 addAttribute(namespace, localName, value); 1188 } 1189 1190 public String getAttributeValue(String localName) 1191 { 1192 if (attributes == null) 1193 { 1194 return null; 1195 } 1196 return attributes.getValue(localName); 1197 } 1198 1199 public void setEnvelope(SOAPEnvelopeAxisImpl env) 1200 { 1201 env.setDirty(true); 1202 message = env; 1203 } 1204 1205 public SOAPEnvelopeAxisImpl getEnvelope() 1206 { 1207 return message; 1208 } 1209 1210 public SOAPElementAxisImpl getRealElement() 1211 { 1212 if (href == null) 1213 return this; 1214 1215 Object obj = context.getObjectByRef(href); 1216 if (obj == null) 1217 return null; 1218 1219 if (!(obj instanceof SOAPElementAxisImpl)) 1220 return null; 1221 1222 return (SOAPElementAxisImpl)obj; 1223 } 1224 1225 public Element getAsDOM() 1226 { 1227 try 1228 { 1229 return getAsDocument().getDocumentElement(); 1230 } 1231 catch (Exception e) 1232 { 1233 log.error("Cannot get element as DOM: " + getElementName(), e); 1234 return null; 1235 } 1236 } 1237 1238 public Document getAsDocument() 1239 { 1240 1241 Document doc = null; 1242 try 1243 { 1244 String elementString = getAsString(); 1245 Reader reader = new StringReader (elementString); 1246 doc = XMLUtils.newDocument(new InputSource (reader)); 1247 } 1248 catch (Exception e) 1249 { 1250 log.error("Cannot serialize element", e); 1251 throw new IllegalStateException (e.toString()); 1252 } 1253 1254 return doc; 1255 } 1256 1257 public String getAsString() 1258 { 1259 SerializationContext serializeContext = null; 1260 StringWriter writer = new StringWriter (); 1261 1262 try 1263 { 1264 MessageContext msgContext; 1265 if (context != null) 1266 { 1267 msgContext = context.getMessageContext(); 1268 } 1269 else 1270 { 1271 msgContext = MessageContext.getCurrentContext(); 1272 } 1273 serializeContext = new SerializationContextImpl(writer, msgContext); 1274 serializeContext.setSendDecl(false); 1275 output(serializeContext); 1276 writer.close(); 1277 } 1278 catch (Exception e) 1279 { 1280 log.error("Cannot serialize element", e); 1281 throw new IllegalStateException (e.toString()); 1282 } 1283 1284 return writer.getBuffer().toString(); 1285 } 1286 1287 1291 public String getAsStringFromInternal() 1292 { 1293 try 1294 { 1295 StringWriter sw = new StringWriter (1024); 1296 printFromInternal(new PrintWriter (sw), this); 1297 return sw.toString(); 1298 } 1299 catch (Exception e) 1300 { 1301 log.error("Cannot parser internal element representation", e); 1302 return null; 1303 } 1304 } 1305 1306 1310 public static void printFromInternal(PrintWriter out, NodeImpl node) throws Exception 1311 { 1312 if (node instanceof Text ) 1313 { 1314 out.print(node.getNodeValue()); 1315 return; 1316 } 1317 1318 SOAPElementAxisImpl el = (SOAPElementAxisImpl)node; 1319 if (el.getChildren().size() == 0) 1320 { 1321 printStartElement(out, el); 1322 printEndElement(out, el); 1323 return; 1324 } 1325 else if (el.getChildren().size() == 1 && el.getFirstChild() instanceof Text ) 1326 { 1327 printStartElement(out, el); 1328 out.print(el.getValue()); 1329 printEndElement(out, el); 1330 return; 1331 } 1332 else 1333 { 1334 printStartElement(out, el); 1335 1336 Iterator it = el.getChildren().iterator(); 1337 while (it.hasNext()) 1338 { 1339 NodeImpl child = (NodeImpl)it.next(); 1340 printFromInternal(out, child); 1341 } 1342 printEndElement(out, el); 1343 } 1344 } 1345 1346 private static void printStartElement(PrintWriter out, SOAPElementAxisImpl el) 1347 { 1348 if (el.prefix != null && el.prefix.length() > 0) 1349 out.print("<" + el.prefix + ":" + el.name); 1350 else 1351 out.print("<" + el.name); 1352 1353 for (int i = 0; i < el.attributes.getLength(); i++) 1354 { 1355 out.print(" " + el.attributes.getQName(i) + "='" + el.attributes.getValue(i) + "'"); 1356 } 1357 1358 if (el.namespaces != null) 1359 { 1360 for (Iterator i = el.namespaces.iterator(); i.hasNext();) 1361 { 1362 Mapping mapping = (Mapping)i.next(); 1363 out.print(" xmlns:" + mapping.getPrefix() + "='" + mapping.getNamespaceURI() + "'"); 1364 } 1365 } 1366 1367 if (el.getChildren().size() > 0) 1368 out.print(">"); 1369 else 1370 out.print("/>"); 1371 } 1372 1373 private static void printEndElement(PrintWriter out, SOAPElementAxisImpl el) 1374 { 1375 if (el.getChildren().size() > 0) 1376 { 1377 if (el.prefix != null && el.prefix.length() > 0) 1378 out.print("</" + el.prefix + ":" + el.name + ">"); 1379 else 1380 out.print("</" + el.name + ">"); 1381 } 1382 } 1383 1384 public void publishToHandler(ContentHandler handler) throws SAXException 1385 { 1386 if (recorder == null) 1387 throw new SAXException (Messages.getMessage("noRecorder00")); 1388 1389 recorder.replay(startEventIndex, endEventIndex, handler); 1390 } 1391 1392 public void publishContents(ContentHandler handler) throws SAXException 1393 { 1394 if (recorder == null) 1395 throw new SAXException (Messages.getMessage("noRecorder00")); 1396 1397 recorder.replay(startContentsIndex, endEventIndex - 1, handler); 1398 } 1399 1400 1408 public final void output(SerializationContext context) throws Exception 1409 { 1410 1411 if ((recorder != null) && (isDirty() == false)) 1412 { 1413 recorder.replay(startEventIndex, endEventIndex, new SAXOutputter(context)); 1414 return; 1415 } 1416 1417 if (qNameAttrs != null) 1419 { 1420 for (int i = 0; i < qNameAttrs.size(); i++) 1421 { 1422 QNameAttr attr = (QNameAttr)qNameAttrs.get(i); 1423 QName attrName = attr.name; 1424 setAttribute(attrName.getNamespaceURI(), attrName.getLocalPart(), context.qName2String(attr.value)); 1425 } 1426 } 1427 1428 1432 if (encodingStyle != null) 1433 { 1434 MessageContext mc = context.getMessageContext(); 1435 SOAPConstants soapConstants = (mc != null) ? 1436 mc.getSOAPConstants() : 1437 SOAPConstants.SOAP11_CONSTANTS; 1438 if (parent == null) 1439 { 1440 if (!encodingStyle.equals("")) 1442 { 1443 setAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encodingStyle); 1444 } 1445 } 1446 else if (!encodingStyle.equals(parent.getEncodingStyle())) 1447 { 1448 setAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encodingStyle); 1449 } 1450 } 1451 1452 outputImpl(context); 1453 } 1454 1455 1458 protected void outputImpl(SerializationContext context) throws Exception 1459 { 1460 if (elementRep != null) 1461 { 1462 boolean oldPretty = context.getPretty(); 1463 context.setPretty(false); 1464 context.writeDOMElement(elementRep); 1465 context.setPretty(oldPretty); 1466 return; 1467 } 1468 1469 if (prefix != null && prefix.length() > 0) 1470 context.registerPrefixForURI(prefix, namespaceURI); 1471 1472 if (namespaces != null) 1473 { 1474 for (Iterator i = namespaces.iterator(); i.hasNext();) 1475 { 1476 Mapping mapping = (Mapping)i.next(); 1477 context.registerPrefixForURI(mapping.getPrefix(), mapping.getNamespaceURI()); 1478 } 1479 } 1480 1481 if (objectValue != null) 1482 { 1483 context.serialize(new QName (namespaceURI, name), 1484 attributes, 1485 objectValue, null, false, null); 1486 return; 1487 } 1488 1489 context.startElement(new QName (namespaceURI, name), attributes); 1490 for (Iterator it = children.iterator(); it.hasNext();) 1491 { 1492 Node childNode = (Node )it.next(); 1493 if (childNode instanceof SOAPElementAxisImpl) 1494 ((SOAPElementAxisImpl)childNode).output(context); 1495 else if (childNode instanceof TextImpl) 1496 context.writeString(childNode.getNodeValue()); 1497 } 1498 1499 context.endElement(); 1500 } 1501 1502 public void addMapping(Mapping map) 1503 { 1504 if (namespaces == null) 1505 namespaces = new ArrayList (); 1506 namespaces.add(map); 1507 } 1508 1509 1511 public void setParentElement(SOAPElement parent) throws SOAPException 1512 { 1513 if (parent == null) 1514 throw new IllegalArgumentException (Messages.getMessage("nullParent00")); 1515 try 1516 { 1517 setParent((SOAPElementAxisImpl)parent); 1518 } 1519 catch (Throwable t) 1520 { 1521 throw new SOAPException (t); 1522 } 1523 } 1524 1525 public SOAPElement getParentElement() 1526 { 1527 return getParent(); 1528 } 1529 1530 1533 public void detachNode() 1534 { 1535 1536 assertImmutable(); 1537 1538 super.detachNode(); 1539 if (parent != null) 1540 { 1541 parent.removeChild(this); 1542 parent = null; 1543 } 1544 } 1545 1546 public boolean isImmutable() 1547 { 1548 return immutable; 1549 } 1550 1551 public void setImmutable(boolean immutable) 1552 { 1553 this.immutable = immutable; 1554 } 1555 1556 public void setAllImmutable(boolean immutable) 1557 { 1558 this.immutable = immutable; 1559 1560 Iterator it = children.iterator(); 1561 while (it.hasNext()) 1562 { 1563 Node node = (Node )it.next(); 1564 if (node instanceof SOAPElementAxisImpl) 1565 ((SOAPElementAxisImpl)node).setAllImmutable(true); 1566 } 1567 } 1568 1569 1571 public SOAPElement addChildElement(Name name) throws SOAPException 1572 { 1573 SOAPElementAxisImpl child = new SOAPElementAxisImpl(name.getLocalName(), 1574 name.getPrefix(), 1575 name.getURI()); 1576 addChild(child); 1577 return child; 1578 } 1579 1580 public SOAPElement addChildElement(String localName) throws SOAPException 1581 { 1582 SOAPElementAxisImpl child = new SOAPElementAxisImpl(getNamespaceURI(), 1584 localName); 1585 addChild(child); 1586 return child; 1587 } 1588 1589 public SOAPElement addChildElement(String localName, 1590 String prefix) throws SOAPException 1591 { 1592 SOAPElementAxisImpl child = new SOAPElementAxisImpl(getNamespaceURI(prefix), 1593 localName); 1594 child.setPrefix(prefix); 1595 addChild(child); 1596 return child; 1597 } 1598 1599 public SOAPElement addChildElement(String localName, 1600 String prefix, 1601 String uri) throws SOAPException 1602 { 1603 SOAPElementAxisImpl child = new SOAPElementAxisImpl(uri, localName); 1604 child.setPrefix(prefix); 1605 child.addNamespaceDeclaration(prefix, uri); 1606 addChild(child); 1607 return child; 1608 } 1609 1610 1615 public SOAPElement addChildElement(SOAPElement element) 1616 throws SOAPException 1617 { 1618 try 1619 { 1620 addChild((SOAPElementAxisImpl)element); 1621 return element; 1622 } 1623 catch (ClassCastException e) 1624 { 1625 throw new SOAPException (e); 1626 } 1627 } 1628 1629 1632 public SOAPElement addTextNode(String value) throws SOAPException 1633 { 1634 org.w3c.dom.Text domText = domNode.getOwnerDocument().createTextNode(value); 1635 javax.xml.soap.Text soapText = new TextImpl(domText); 1636 appendChild(soapText); 1637 return this; 1638 } 1639 1640 public SOAPElement addAttribute(Name name, String value) 1641 throws SOAPException 1642 { 1643 try 1644 { 1645 addAttribute(name.getPrefix(), name.getURI(), name.getLocalName(), value); 1646 } 1647 catch (RuntimeException t) 1648 { 1649 throw new SOAPException (t); 1650 } 1651 return this; 1652 } 1653 1654 public SOAPElement addNamespaceDeclaration(String prefix, String uri) 1655 throws SOAPException 1656 { 1657 try 1658 { 1659 Mapping map = new Mapping(uri, prefix); 1660 addMapping(map); 1661 } 1662 catch (RuntimeException t) 1663 { 1664 throw new SOAPException (t); 1665 } 1666 return this; 1667 } 1668 1669 public String getAttributeValue(Name name) 1670 { 1671 return attributes.getValue(name.getURI(), name.getLocalName()); 1672 } 1673 1674 public Iterator getAllAttributes() 1675 { 1676 int num = attributes.getLength(); 1677 Vector attrs = new Vector (num); 1678 for (int i = 0; i < num; i++) 1679 { 1680 String q = attributes.getQName(i); 1681 String prefix = ""; 1682 if (q != null) 1683 { 1684 int idx = q.indexOf(":"); 1685 if (idx > 0) 1686 { 1687 prefix = q.substring(0, idx); 1688 } 1689 else 1690 { 1691 prefix = ""; 1692 } 1693 } 1694 1695 attrs.add(new NameImpl(attributes.getLocalName(i), prefix, attributes.getURI(i))); 1696 } 1697 return attrs.iterator(); 1698 } 1699 1700 1702 public Iterator getNamespacePrefixes() 1703 { 1704 Vector prefixes = new Vector (); 1705 for (int i = 0; namespaces != null && i < namespaces.size(); i++) 1706 { 1707 prefixes.add(((Mapping)namespaces.get(i)).getPrefix()); 1708 } 1709 return prefixes.iterator(); 1710 } 1711 1712 public Name getElementName() 1713 { 1714 return new NameImpl(getName(), getPrefix(), getNamespaceURI()); 1715 } 1716 1717 public boolean removeAttribute(Name name) 1718 { 1719 AttributesImpl attrs = makeAttributesEditable(); 1720 boolean removed = false; 1721 1722 for (int i = 0; i < attrs.getLength() && !removed; i++) 1723 { 1724 if (attrs.getURI(i).equals(name.getURI()) && 1725 attrs.getLocalName(i).equals(name.getLocalName())) 1726 { 1727 attrs.removeAttribute(i); 1728 removed = true; 1729 } 1730 } 1731 return removed; 1732 } 1733 1734 public boolean removeNamespaceDeclaration(String prefix) 1735 { 1736 makeAttributesEditable(); 1737 boolean removed = false; 1738 1739 for (int i = 0; namespaces != null && i < namespaces.size() && !removed; i++) 1740 { 1741 if (((Mapping)namespaces.get(i)).getPrefix().equals(prefix)) 1742 { 1743 namespaces.remove(i); 1744 removed = true; 1745 } 1746 } 1747 return removed; 1748 } 1749 1750 public Iterator getChildElements() 1751 { 1752 return children.iterator(); 1753 } 1754 1755 public Iterator getChildElements(Name name) 1756 { 1757 ArrayList list = new ArrayList (); 1758 Iterator it = getChildElements(); 1759 while (it.hasNext()) 1760 { 1761 Node node = (Node )it.next(); 1762 if (name.getURI().equals(node.getNamespaceURI()) && name.getLocalName().equals(node.getLocalName())) 1763 list.add(node); 1764 } 1765 return list.iterator(); 1766 } 1767 1768 public String getTagName() 1769 { 1770 return prefix == null ? name : prefix + ":" + name; 1771 } 1772 1773 public void removeAttribute(String name) throws DOMException 1774 { 1775 AttributesImpl impl = (AttributesImpl )attributes; 1776 int index = impl.getIndex(name); 1777 if (index >= 0) 1778 { 1779 AttributesImpl newAttrs = new AttributesImpl (); 1780 for (int i = 0; i < impl.getLength(); i++) 1782 { if (i != index) 1784 { 1785 String uri = impl.getURI(i); 1786 String local = impl.getLocalName(i); 1787 String qname = impl.getQName(i); 1788 String type = impl.getType(i); 1789 String value = impl.getValue(i); 1790 newAttrs.addAttribute(uri, local, qname, type, value); 1791 } 1792 } 1793 attributes = newAttrs; 1795 } 1796 } 1797 1798 public boolean hasAttribute(String name) 1799 { 1800 if (name == null) name = ""; 1802 1803 for (int i = 0; i < attributes.getLength(); i++) 1804 { 1805 if (name.equals(attributes.getQName(i))) 1806 return true; 1807 } 1808 return false; 1809 } 1810 1811 public String getAttribute(String name) 1812 { 1813 return attributes.getValue(name); 1814 } 1815 1816 public void removeAttributeNS(String namespaceURI, String localName) throws DOMException 1817 { 1818 makeAttributesEditable(); 1819 Name name = new NameImpl(localName, null, namespaceURI); 1820 removeAttribute(name); 1821 } 1822 1823 public void setAttribute(String name, String value) throws DOMException 1824 { 1825 if (value == null) 1826 throw new IllegalArgumentException ("Cannot set null attribute"); 1827 1828 AttributesImpl attrs = makeAttributesEditable(); 1829 int index = attrs.getIndex(name); 1830 if (index < 0) 1831 { String uri = ""; 1833 String localname = name; 1834 String qname = name; 1835 String type = "CDDATA"; 1836 attrs.addAttribute(uri, localname, qname, type, value); 1837 } 1838 else 1839 { attrs.setLocalName(index, value); 1841 } 1842 } 1843 1844 public boolean hasAttributeNS(String namespaceURI, String localName) 1845 { 1846 if (namespaceURI == null) 1847 namespaceURI = ""; 1848 if (localName == null) localName = ""; 1850 1851 for (int i = 0; i < attributes.getLength(); i++) 1852 { 1853 if (namespaceURI.equals(attributes.getURI(i)) 1854 && localName.equals(attributes.getLocalName(i))) 1855 return true; 1856 } 1857 return false; 1858 } 1859 1860 public Attr getAttributeNode(String name) 1861 { 1862 return null; } 1864 1865 public Attr removeAttributeNode(Attr oldAttr) throws DOMException 1866 { 1867 makeAttributesEditable(); 1868 Name name = new NameImpl(oldAttr.getLocalName(), oldAttr.getPrefix(), oldAttr.getNamespaceURI()); 1869 removeAttribute(name); 1870 return oldAttr; 1871 } 1872 1873 public Attr setAttributeNode(Attr newAttr) throws DOMException 1874 { 1875 return newAttr; 1876 } 1877 1878 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException 1879 { 1880 AttributesImpl attrs = makeAttributesEditable(); 1882 attrs.addAttribute(newAttr.getNamespaceURI(), 1884 newAttr.getLocalName(), 1885 newAttr.getLocalName(), 1886 "CDATA", 1887 newAttr.getValue()); 1888 return null; 1889 } 1890 1891 public NodeList getElementsByTagName(String name) 1892 { 1893 NodeListImpl nodelist = new NodeListImpl(); 1895 if (children != null) 1896 { 1897 for (int i = 0; i < children.size(); i++) 1899 { 1900 Node child = children.get(i); 1901 if ("*".equals(name) || child.getNodeName().equals(name)) 1902 nodelist.addNode(child); 1903 } 1904 for (int i = 0; i < children.size(); i++) 1906 { 1907 if (children.get(i).getNodeType() == Node.ELEMENT_NODE) 1908 { 1909 Element child = (Element )children.get(i); 1910 NodeList grandsons = child.getElementsByTagName(name); 1911 for (int j = 0; j < grandsons.getLength(); j++) 1912 { 1913 nodelist.addNode(grandsons.item(j)); 1914 } 1915 } 1916 } 1917 } 1918 return nodelist; 1919 } 1920 1921 public String getAttributeNS(String namespaceURI, String localName) 1922 { 1923 for (int i = 0; i < attributes.getLength(); i++) 1924 { 1925 if (attributes.getURI(i).equals(namespaceURI) && attributes.getLocalName(i).equals(localName)) 1926 { 1927 return attributes.getValue(i); 1928 } 1929 } 1930 return null; 1931 } 1932 1933 public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException 1934 { 1935 AttributesImpl attrs = makeAttributesEditable(); 1936 String localName = qualifiedName.substring(qualifiedName.indexOf(":") + 1, qualifiedName.length()); 1937 1938 if (namespaceURI == null) 1939 { 1940 namespaceURI = "intentionalNullURI"; 1941 } 1942 attrs.addAttribute(namespaceURI, localName, qualifiedName, "CDATA", value); 1943 } 1944 1945 public Attr getAttributeNodeNS(String namespaceURI, String localName) 1946 { 1947 return null; } 1949 1950 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) 1951 { 1952 return getElementsNS(this, namespaceURI, localName); 1953 } 1954 1955 1958 protected NodeList getElementsNS(org.w3c.dom.Element parent, 1959 String namespaceURI, String localName) 1960 { 1961 NodeList children = parent.getChildNodes(); 1962 NodeListImpl matches = new NodeListImpl(); 1963 for (int i = 0; i < children.getLength(); i++) 1965 { 1966 1967 Node c = (Node )children.item(i); 1968 if (c instanceof Element ) 1969 { 1970 Element child = (Element )c; 1971 if (namespaceURI.equals(child.getNamespaceURI()) && 1972 localName.equals(child.getLocalName())) 1973 { 1974 matches.addNode(child); 1975 } 1976 matches.addNodeList(child.getElementsByTagNameNS(namespaceURI, localName)); 1978 } 1979 } 1980 return matches; 1981 } 1982 1983 public void setOwnerDocument(org.jboss.axis.MessagePart sp) 1984 { 1985 soapPart = sp; 1986 } 1987 1988 1991 private void setElementAsModified() 1992 { 1993 SOAPEnvelopeAxisImpl env = getSOAPEnvelope(); 1994 if (env != null) env.setModified(true); 1995 } 1996 1997 2000 private SOAPEnvelopeAxisImpl getSOAPEnvelope() 2001 { 2002 SOAPEnvelopeAxisImpl env = null; 2003 SOAPElementAxisImpl el = this; 2004 while (env == null && el != null) 2005 { 2006 if (el instanceof SOAPEnvelopeAxisImpl) 2007 { 2008 env = (SOAPEnvelopeAxisImpl)el; 2009 } 2010 el = el.getParent(); 2011 } 2012 return env; 2013 } 2014 2015 public List getChildren() 2016 { 2017 return children.getUnmodifieableList(); 2018 } 2019 2020 2025 class ChildElementList 2026 { 2027 private ArrayList children = new ArrayList (); 2028 2029 2031 public void clear() 2032 { 2033 log.debug("Clear the child list"); 2034 children.clear(); 2035 setElementAsModified(); 2036 } 2037 2038 public void add(Node child) 2039 { 2040 log.debug("Adding child: " + getDebugStr(child)); 2041 children.add(child); 2042 setElementAsModified(); 2043 } 2044 2045 public void add(int pos, Node child) 2046 { 2047 log.debug("Adding child at position: " + pos + "," + getDebugStr(child)); 2048 children.add(pos, child); 2049 setElementAsModified(); 2050 } 2051 2052 public void remove(int pos) 2053 { 2054 log.debug("Remove child at position: " + pos); 2055 children.remove(pos); 2056 setElementAsModified(); 2057 } 2058 2059 2061 public List getUnmodifieableList() 2062 { 2063 return Collections.unmodifiableList(children); 2064 } 2065 2066 public boolean contains(Node child) 2067 { 2068 return children.contains(child); 2069 } 2070 2071 public boolean isEmpty() 2072 { 2073 return children.isEmpty(); 2074 } 2075 2076 public Node get(int pos) 2077 { 2078 return (NodeImpl)children.get(pos); 2079 } 2080 2081 public int size() 2082 { 2083 return children.size(); 2084 } 2085 2086 public int indexOf(Node child) 2087 { 2088 return children.indexOf(child); 2089 } 2090 2091 public Iterator iterator() 2092 { 2093 return children.iterator(); 2094 } 2095 2096 private String getDebugStr(Node child) 2097 { 2098 String nodeStr = child.getNodeName(); 2099 if (child.getNodeType() == Node.TEXT_NODE) 2100 nodeStr += " [" + child.getNodeValue() + "]"; 2101 return nodeStr; 2102 } 2103 } 2104} 2105 | Popular Tags |