aoqi@0: /* aefimov@1341: * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.messaging.saaj.soap.impl; aoqi@0: aoqi@0: import java.net.URI; aoqi@0: import java.net.URISyntaxException; aoqi@0: import java.util.*; aoqi@0: import java.util.logging.Level; aoqi@0: import java.util.logging.Logger; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.soap.*; aoqi@0: aoqi@0: import org.w3c.dom.*; aoqi@0: import org.w3c.dom.Node; aoqi@0: aoqi@0: import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.util.*; aoqi@0: aoqi@0: public class ElementImpl aoqi@0: extends com.sun.org.apache.xerces.internal.dom.ElementNSImpl aoqi@0: implements SOAPElement, SOAPBodyElement { aoqi@0: aoqi@0: public static final String DSIG_NS = "http://www.w3.org/2000/09/xmldsig#".intern(); aoqi@0: public static final String XENC_NS = "http://www.w3.org/2001/04/xmlenc#".intern(); aoqi@0: public static final String WSU_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd".intern(); aoqi@0: aoqi@0: private AttributeManager encodingStyleAttribute = new AttributeManager(); aoqi@0: aoqi@0: protected QName elementQName; aoqi@0: aoqi@0: protected static final Logger log = aoqi@0: Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN, aoqi@0: "com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings"); aoqi@0: aoqi@0: /** aoqi@0: * XML Information Set REC aoqi@0: * all namespace attributes (including those named xmlns, aoqi@0: * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/ aoqi@0: */ aoqi@0: public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern(); aoqi@0: aoqi@0: /** aoqi@0: * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is aoqi@0: * the Namespace URI that is automatically mapped to the "xml" prefix. aoqi@0: */ aoqi@0: public final static String XML_URI = "http://www.w3.org/XML/1998/namespace".intern(); aoqi@0: aoqi@0: public ElementImpl(SOAPDocumentImpl ownerDoc, Name name) { aoqi@0: super( aoqi@0: ownerDoc, aoqi@0: name.getURI(), aoqi@0: name.getQualifiedName(), aoqi@0: name.getLocalName()); aoqi@0: elementQName = NameImpl.convertToQName(name); aoqi@0: } aoqi@0: aoqi@0: public ElementImpl(SOAPDocumentImpl ownerDoc, QName name) { aoqi@0: super( aoqi@0: ownerDoc, aoqi@0: name.getNamespaceURI(), aoqi@0: getQualifiedName(name), aoqi@0: name.getLocalPart()); aoqi@0: elementQName = name; aoqi@0: } aoqi@0: aoqi@0: public ElementImpl( aoqi@0: SOAPDocumentImpl ownerDoc, aoqi@0: String uri, aoqi@0: String qualifiedName) { aoqi@0: aoqi@0: super(ownerDoc, uri, qualifiedName); aoqi@0: elementQName = aoqi@0: new QName(uri, getLocalPart(qualifiedName), getPrefix(qualifiedName)); aoqi@0: } aoqi@0: aoqi@0: public void ensureNamespaceIsDeclared(String prefix, String uri) { aoqi@0: String alreadyDeclaredUri = getNamespaceURI(prefix); aoqi@0: if (alreadyDeclaredUri == null || !alreadyDeclaredUri.equals(uri)) { aoqi@0: try { aoqi@0: addNamespaceDeclaration(prefix, uri); aoqi@0: } catch (SOAPException e) { /*ignore*/ aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public Document getOwnerDocument() { aoqi@0: Document doc = super.getOwnerDocument(); aoqi@0: if (doc instanceof SOAPDocument) aoqi@0: return ((SOAPDocument) doc).getDocument(); aoqi@0: else aoqi@0: return doc; aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addChildElement(Name name) throws SOAPException { aoqi@0: return addElement(name); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addChildElement(QName qname) throws SOAPException { aoqi@0: return addElement(qname); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addChildElement(String localName) throws SOAPException { aefimov@1341: String nsUri = getNamespaceURI(""); aefimov@1341: Name name = (nsUri == null || nsUri.isEmpty()) aefimov@1341: ? NameImpl.createFromUnqualifiedName(localName) aefimov@1341: : NameImpl.createFromQualifiedName(localName, nsUri); aefimov@1341: return addChildElement(name); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addChildElement(String localName, String prefix) aoqi@0: throws SOAPException { aoqi@0: String uri = getNamespaceURI(prefix); aoqi@0: if (uri == null) { aoqi@0: log.log( aoqi@0: Level.SEVERE, aoqi@0: "SAAJ0101.impl.parent.of.body.elem.mustbe.body", aoqi@0: new String[] { prefix }); aoqi@0: throw new SOAPExceptionImpl( aoqi@0: "Unable to locate namespace for prefix " + prefix); aoqi@0: } aoqi@0: return addChildElement(localName, prefix, uri); aoqi@0: } aoqi@0: aoqi@0: public String getNamespaceURI(String prefix) { aoqi@0: aoqi@0: if ("xmlns".equals(prefix)) { aoqi@0: return XMLNS_URI; aoqi@0: } aoqi@0: aoqi@0: if("xml".equals(prefix)) { aoqi@0: return XML_URI; aoqi@0: } aoqi@0: aoqi@0: if ("".equals(prefix)) { aoqi@0: aoqi@0: org.w3c.dom.Node currentAncestor = this; aoqi@0: while (currentAncestor != null && aoqi@0: !(currentAncestor instanceof Document)) { aoqi@0: aoqi@0: if (currentAncestor instanceof ElementImpl) { aoqi@0: QName name = ((ElementImpl) currentAncestor).getElementQName(); aoqi@0: /* aoqi@0: if (prefix.equals(name.getPrefix())) { aoqi@0: String uri = name.getNamespaceURI(); aoqi@0: if ("".equals(uri)) { aoqi@0: return null; aoqi@0: } aoqi@0: else { aoqi@0: return uri; aoqi@0: } aoqi@0: }*/ aoqi@0: if (((Element) currentAncestor).hasAttributeNS( aoqi@0: XMLNS_URI, "xmlns")) { aoqi@0: aoqi@0: String uri = aoqi@0: ((Element) currentAncestor).getAttributeNS( aoqi@0: XMLNS_URI, "xmlns"); aoqi@0: if ("".equals(uri)) aoqi@0: return null; aoqi@0: else { aoqi@0: return uri; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: currentAncestor = currentAncestor.getParentNode(); aoqi@0: } aoqi@0: aoqi@0: } else if (prefix != null) { aoqi@0: // Find if there's an ancester whose name contains this prefix aoqi@0: org.w3c.dom.Node currentAncestor = this; aoqi@0: aoqi@0: // String uri = currentAncestor.lookupNamespaceURI(prefix); aoqi@0: // return uri; aoqi@0: while (currentAncestor != null && aoqi@0: !(currentAncestor instanceof Document)) { aoqi@0: aoqi@0: /* if (prefix.equals(currentAncestor.getPrefix())) { aoqi@0: String uri = currentAncestor.getNamespaceURI(); aoqi@0: // this is because the javadoc says getNamespaceURI() is not a computed value aoqi@0: // and URI for a non-empty prefix cannot be null aoqi@0: if (uri != null) aoqi@0: return uri; aoqi@0: }*/ aoqi@0: //String uri = currentAncestor.lookupNamespaceURI(prefix); aoqi@0: //if (uri != null) { aoqi@0: // return uri; aoqi@0: //} aoqi@0: aoqi@0: if (((Element) currentAncestor).hasAttributeNS( aoqi@0: XMLNS_URI, prefix)) { aoqi@0: return ((Element) currentAncestor).getAttributeNS( aoqi@0: XMLNS_URI, prefix); aoqi@0: } aoqi@0: aoqi@0: currentAncestor = currentAncestor.getParentNode(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public SOAPElement setElementQName(QName newName) throws SOAPException { aoqi@0: ElementImpl copy = aoqi@0: new ElementImpl((SOAPDocumentImpl) getOwnerDocument(), newName); aoqi@0: return replaceElementWithSOAPElement(this,copy); aoqi@0: } aoqi@0: aoqi@0: public QName createQName(String localName, String prefix) aoqi@0: throws SOAPException { aoqi@0: String uri = getNamespaceURI(prefix); aoqi@0: if (uri == null) { aoqi@0: log.log(Level.SEVERE, "SAAJ0102.impl.cannot.locate.ns", aoqi@0: new Object[] {prefix}); aoqi@0: throw new SOAPException("Unable to locate namespace for prefix " aoqi@0: + prefix); aoqi@0: } aoqi@0: return new QName(uri, localName, prefix); aoqi@0: } aoqi@0: aoqi@0: public String getNamespacePrefix(String uri) { aoqi@0: aoqi@0: NamespaceContextIterator eachNamespace = getNamespaceContextNodes(); aoqi@0: while (eachNamespace.hasNext()) { aoqi@0: org.w3c.dom.Attr namespaceDecl = eachNamespace.nextNamespaceAttr(); aoqi@0: if (namespaceDecl.getNodeValue().equals(uri)) { aoqi@0: String candidatePrefix = namespaceDecl.getLocalName(); aoqi@0: if ("xmlns".equals(candidatePrefix)) aoqi@0: return ""; aoqi@0: else aoqi@0: return candidatePrefix; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Find if any of the ancestors' name has this uri aoqi@0: org.w3c.dom.Node currentAncestor = this; aoqi@0: while (currentAncestor != null && aoqi@0: !(currentAncestor instanceof Document)) { aoqi@0: aoqi@0: if (uri.equals(currentAncestor.getNamespaceURI())) aoqi@0: return currentAncestor.getPrefix(); aoqi@0: currentAncestor = currentAncestor.getParentNode(); aoqi@0: } aoqi@0: aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: protected org.w3c.dom.Attr getNamespaceAttr(String prefix) { aoqi@0: NamespaceContextIterator eachNamespace = getNamespaceContextNodes(); aoqi@0: if (!"".equals(prefix)) aoqi@0: prefix = ":"+prefix; aoqi@0: while (eachNamespace.hasNext()) { aoqi@0: org.w3c.dom.Attr namespaceDecl = eachNamespace.nextNamespaceAttr(); aoqi@0: if (!"".equals(prefix)) { aoqi@0: if (namespaceDecl.getNodeName().endsWith(prefix)) aoqi@0: return namespaceDecl; aoqi@0: } else { aoqi@0: if (namespaceDecl.getNodeName().equals("xmlns")) aoqi@0: return namespaceDecl; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public NamespaceContextIterator getNamespaceContextNodes() { aoqi@0: return getNamespaceContextNodes(true); aoqi@0: } aoqi@0: aoqi@0: public NamespaceContextIterator getNamespaceContextNodes(boolean traverseStack) { aoqi@0: return new NamespaceContextIterator(this, traverseStack); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addChildElement( aoqi@0: String localName, aoqi@0: String prefix, aoqi@0: String uri) aoqi@0: throws SOAPException { aoqi@0: aoqi@0: SOAPElement newElement = createElement(NameImpl.create(localName, prefix, uri)); aoqi@0: addNode(newElement); aoqi@0: return convertToSoapElement(newElement); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addChildElement(SOAPElement element) aoqi@0: throws SOAPException { aoqi@0: aoqi@0: // check if Element falls in SOAP 1.1 or 1.2 namespace. aoqi@0: String elementURI = element.getElementName().getURI(); aoqi@0: String localName = element.getLocalName(); aoqi@0: aoqi@0: if ((SOAPConstants.URI_NS_SOAP_ENVELOPE).equals(elementURI) aoqi@0: || (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE).equals(elementURI)) { aoqi@0: aoqi@0: aoqi@0: if ("Envelope".equalsIgnoreCase(localName) || aoqi@0: "Header".equalsIgnoreCase(localName) || "Body".equalsIgnoreCase(localName)) { aoqi@0: log.severe("SAAJ0103.impl.cannot.add.fragements"); aoqi@0: throw new SOAPExceptionImpl( aoqi@0: "Cannot add fragments which contain elements " aoqi@0: + "which are in the SOAP namespace"); aoqi@0: } aoqi@0: aoqi@0: if ("Fault".equalsIgnoreCase(localName) && !"Body".equalsIgnoreCase(this.getLocalName())) { aoqi@0: log.severe("SAAJ0154.impl.adding.fault.to.nonbody"); aoqi@0: throw new SOAPExceptionImpl("Cannot add a SOAPFault as a child of " + this.getLocalName()); aoqi@0: } aoqi@0: aoqi@0: if ("Detail".equalsIgnoreCase(localName) && !"Fault".equalsIgnoreCase(this.getLocalName())) { aoqi@0: log.severe("SAAJ0155.impl.adding.detail.nonfault"); aoqi@0: throw new SOAPExceptionImpl("Cannot add a Detail as a child of " + this.getLocalName()); aoqi@0: } aoqi@0: aoqi@0: if ("Fault".equalsIgnoreCase(localName)) { aoqi@0: // if body is not empty throw an exception aoqi@0: if (!elementURI.equals(this.getElementName().getURI())) { aoqi@0: log.severe("SAAJ0158.impl.version.mismatch.fault"); aoqi@0: throw new SOAPExceptionImpl("SOAP Version mismatch encountered when trying to add SOAPFault to SOAPBody"); aoqi@0: } aoqi@0: Iterator it = this.getChildElements(); aoqi@0: if (it.hasNext()) { aoqi@0: log.severe("SAAJ0156.impl.adding.fault.error"); aoqi@0: throw new SOAPExceptionImpl("Cannot add SOAPFault as a child of a non-Empty SOAPBody"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // preserve the encodingStyle attr as it may get lost in the import aoqi@0: String encodingStyle = element.getEncodingStyle(); aoqi@0: aoqi@0: ElementImpl importedElement = (ElementImpl) importElement(element); aoqi@0: addNode(importedElement); aoqi@0: aoqi@0: if (encodingStyle != null) aoqi@0: importedElement.setEncodingStyle(encodingStyle); aoqi@0: aoqi@0: return convertToSoapElement(importedElement); aoqi@0: } aoqi@0: aoqi@0: protected Element importElement(Element element) { aoqi@0: Document document = getOwnerDocument(); aoqi@0: Document oldDocument = element.getOwnerDocument(); aoqi@0: if (!oldDocument.equals(document)) { aoqi@0: return (Element) document.importNode(element, true); aoqi@0: } else { aoqi@0: return element; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement addElement(Name name) throws SOAPException { aoqi@0: SOAPElement newElement = createElement(name); aoqi@0: addNode(newElement); aefimov@1341: return newElement; aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement addElement(QName name) throws SOAPException { aoqi@0: SOAPElement newElement = createElement(name); aoqi@0: addNode(newElement); aefimov@1341: return newElement; aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement createElement(Name name) { aoqi@0: aoqi@0: if (isNamespaceQualified(name)) { aoqi@0: return (SOAPElement) aoqi@0: getOwnerDocument().createElementNS( aoqi@0: name.getURI(), aoqi@0: name.getQualifiedName()); aoqi@0: } else { aoqi@0: return (SOAPElement) aoqi@0: getOwnerDocument().createElement(name.getQualifiedName()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement createElement(QName name) { aoqi@0: aoqi@0: if (isNamespaceQualified(name)) { aoqi@0: return (SOAPElement) aoqi@0: getOwnerDocument().createElementNS( aoqi@0: name.getNamespaceURI(), aoqi@0: getQualifiedName(name)); aoqi@0: } else { aoqi@0: return (SOAPElement) aoqi@0: getOwnerDocument().createElement(getQualifiedName(name)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected void addNode(org.w3c.dom.Node newElement) throws SOAPException { aoqi@0: insertBefore(newElement, null); aoqi@0: aoqi@0: if (getOwnerDocument() instanceof DocumentFragment) aoqi@0: return; aoqi@0: aoqi@0: if (newElement instanceof ElementImpl) { aoqi@0: ElementImpl element = (ElementImpl) newElement; aoqi@0: QName elementName = element.getElementQName(); aoqi@0: if (!"".equals(elementName.getNamespaceURI())) { aoqi@0: element.ensureNamespaceIsDeclared( aoqi@0: elementName.getPrefix(), elementName.getNamespaceURI()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement findChild(NameImpl name) { aoqi@0: Iterator eachChild = getChildElementNodes(); aoqi@0: while (eachChild.hasNext()) { aoqi@0: SOAPElement child = (SOAPElement) eachChild.next(); aoqi@0: if (child.getElementName().equals(name)) { aoqi@0: return child; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addTextNode(String text) throws SOAPException { aoqi@0: if (text.startsWith(CDATAImpl.cdataUC) aoqi@0: || text.startsWith(CDATAImpl.cdataLC)) aoqi@0: return addCDATA( aoqi@0: text.substring(CDATAImpl.cdataUC.length(), text.length() - 3)); aoqi@0: return addText(text); aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement addCDATA(String text) throws SOAPException { aoqi@0: org.w3c.dom.Text cdata = aoqi@0: (org.w3c.dom.Text) getOwnerDocument().createCDATASection(text); aoqi@0: addNode(cdata); aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement addText(String text) throws SOAPException { aoqi@0: org.w3c.dom.Text textNode = aoqi@0: (org.w3c.dom.Text) getOwnerDocument().createTextNode(text); aoqi@0: addNode(textNode); aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addAttribute(Name name, String value) aoqi@0: throws SOAPException { aoqi@0: addAttributeBare(name, value); aoqi@0: if (!"".equals(name.getURI())) { aoqi@0: ensureNamespaceIsDeclared(name.getPrefix(), name.getURI()); aoqi@0: } aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addAttribute(QName qname, String value) aoqi@0: throws SOAPException { aoqi@0: addAttributeBare(qname, value); aoqi@0: if (!"".equals(qname.getNamespaceURI())) { aoqi@0: ensureNamespaceIsDeclared(qname.getPrefix(), qname.getNamespaceURI()); aoqi@0: } aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: private void addAttributeBare(Name name, String value) { aoqi@0: addAttributeBare( aoqi@0: name.getURI(), aoqi@0: name.getPrefix(), aoqi@0: name.getQualifiedName(), aoqi@0: value); aoqi@0: } aoqi@0: private void addAttributeBare(QName name, String value) { aoqi@0: addAttributeBare( aoqi@0: name.getNamespaceURI(), aoqi@0: name.getPrefix(), aoqi@0: getQualifiedName(name), aoqi@0: value); aoqi@0: } aoqi@0: aoqi@0: private void addAttributeBare( aoqi@0: String uri, aoqi@0: String prefix, aoqi@0: String qualifiedName, aoqi@0: String value) { aoqi@0: aoqi@0: uri = uri.length() == 0 ? null : uri; aoqi@0: if (qualifiedName.equals("xmlns")) { aoqi@0: uri = XMLNS_URI; aoqi@0: } aoqi@0: aoqi@0: if (uri == null) { aoqi@0: setAttribute(qualifiedName, value); aoqi@0: } else { aoqi@0: setAttributeNS(uri, qualifiedName, value); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addNamespaceDeclaration(String prefix, String uri) aoqi@0: throws SOAPException { aoqi@0: if (prefix.length() > 0) { aoqi@0: setAttributeNS(XMLNS_URI, "xmlns:" + prefix, uri); aoqi@0: } else { aoqi@0: setAttributeNS(XMLNS_URI, "xmlns", uri); aoqi@0: } aoqi@0: //Fix for CR:6474641 aoqi@0: //tryToFindEncodingStyleAttributeName(); aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public String getAttributeValue(Name name) { aoqi@0: return getAttributeValueFrom(this, name); aoqi@0: } aoqi@0: aoqi@0: public String getAttributeValue(QName qname) { aoqi@0: return getAttributeValueFrom( aoqi@0: this, aoqi@0: qname.getNamespaceURI(), aoqi@0: qname.getLocalPart(), aoqi@0: qname.getPrefix(), aoqi@0: getQualifiedName(qname)); aoqi@0: } aoqi@0: aoqi@0: public Iterator getAllAttributes() { aoqi@0: Iterator i = getAllAttributesFrom(this); aoqi@0: ArrayList list = new ArrayList(); aoqi@0: while (i.hasNext()) { aoqi@0: Name name = (Name) i.next(); aoqi@0: if (!"xmlns".equalsIgnoreCase(name.getPrefix())) aoqi@0: list.add(name); aoqi@0: } aoqi@0: return list.iterator(); aoqi@0: } aoqi@0: aoqi@0: public Iterator getAllAttributesAsQNames() { aoqi@0: Iterator i = getAllAttributesFrom(this); aoqi@0: ArrayList list = new ArrayList(); aoqi@0: while (i.hasNext()) { aoqi@0: Name name = (Name) i.next(); aoqi@0: if (!"xmlns".equalsIgnoreCase(name.getPrefix())) { aoqi@0: list.add(NameImpl.convertToQName(name)); aoqi@0: } aoqi@0: } aoqi@0: return list.iterator(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: public Iterator getNamespacePrefixes() { aoqi@0: return doGetNamespacePrefixes(false); aoqi@0: } aoqi@0: aoqi@0: public Iterator getVisibleNamespacePrefixes() { aoqi@0: return doGetNamespacePrefixes(true); aoqi@0: } aoqi@0: aoqi@0: protected Iterator doGetNamespacePrefixes(final boolean deep) { aoqi@0: return new Iterator() { aoqi@0: String next = null; aoqi@0: String last = null; aoqi@0: NamespaceContextIterator eachNamespace = aoqi@0: getNamespaceContextNodes(deep); aoqi@0: aoqi@0: void findNext() { aoqi@0: while (next == null && eachNamespace.hasNext()) { aoqi@0: String attributeKey = aoqi@0: eachNamespace.nextNamespaceAttr().getNodeName(); aoqi@0: if (attributeKey.startsWith("xmlns:")) { aoqi@0: next = attributeKey.substring("xmlns:".length()); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: findNext(); aoqi@0: return next != null; aoqi@0: } aoqi@0: aoqi@0: public Object next() { aoqi@0: findNext(); aoqi@0: if (next == null) { aoqi@0: throw new NoSuchElementException(); aoqi@0: } aoqi@0: aoqi@0: last = next; aoqi@0: next = null; aoqi@0: return last; aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: if (last == null) { aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: eachNamespace.remove(); aoqi@0: next = null; aoqi@0: last = null; aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: public Name getElementName() { aoqi@0: return NameImpl.convertToName(elementQName); aoqi@0: } aoqi@0: aoqi@0: public QName getElementQName() { aoqi@0: return elementQName; aoqi@0: } aoqi@0: aoqi@0: public boolean removeAttribute(Name name) { aoqi@0: return removeAttribute(name.getURI(), name.getLocalName()); aoqi@0: } aoqi@0: aoqi@0: public boolean removeAttribute(QName name) { aoqi@0: return removeAttribute(name.getNamespaceURI(), name.getLocalPart()); aoqi@0: } aoqi@0: aoqi@0: private boolean removeAttribute(String uri, String localName) { aoqi@0: String nonzeroLengthUri = aoqi@0: (uri == null || uri.length() == 0) ? null : uri; aoqi@0: org.w3c.dom.Attr attribute = aoqi@0: getAttributeNodeNS(nonzeroLengthUri, localName); aoqi@0: if (attribute == null) { aoqi@0: return false; aoqi@0: } aoqi@0: removeAttributeNode(attribute); aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: public boolean removeNamespaceDeclaration(String prefix) { aoqi@0: org.w3c.dom.Attr declaration = getNamespaceAttr(prefix); aoqi@0: if (declaration == null) { aoqi@0: return false; aoqi@0: } aoqi@0: try { aoqi@0: removeAttributeNode(declaration); aoqi@0: } catch (DOMException de) { aoqi@0: // ignore aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: public Iterator getChildElements() { aoqi@0: return getChildElementsFrom(this); aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement convertToSoapElement(Element element) { aoqi@0: if (element instanceof SOAPElement) { aoqi@0: return (SOAPElement) element; aoqi@0: } else { aoqi@0: return replaceElementWithSOAPElement( aoqi@0: element, aoqi@0: (ElementImpl) createElement(NameImpl.copyElementName(element))); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected static SOAPElement replaceElementWithSOAPElement( aoqi@0: Element element, aoqi@0: ElementImpl copy) { aoqi@0: aoqi@0: Iterator eachAttribute = getAllAttributesFrom(element); aoqi@0: while (eachAttribute.hasNext()) { aoqi@0: Name name = (Name) eachAttribute.next(); aoqi@0: copy.addAttributeBare(name, getAttributeValueFrom(element, name)); aoqi@0: } aoqi@0: aoqi@0: Iterator eachChild = getChildElementsFrom(element); aoqi@0: while (eachChild.hasNext()) { aoqi@0: Node nextChild = (Node) eachChild.next(); aoqi@0: copy.insertBefore(nextChild, null); aoqi@0: } aoqi@0: aoqi@0: Node parent = element.getParentNode(); aoqi@0: if (parent != null) { aoqi@0: parent.replaceChild(copy, element); aoqi@0: } // XXX else throw an exception? aoqi@0: aoqi@0: return copy; aoqi@0: } aoqi@0: aoqi@0: protected Iterator getChildElementNodes() { aoqi@0: return new Iterator() { aoqi@0: Iterator eachNode = getChildElements(); aoqi@0: Node next = null; aoqi@0: Node last = null; aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: if (next == null) { aoqi@0: while (eachNode.hasNext()) { aoqi@0: Node node = (Node) eachNode.next(); aoqi@0: if (node instanceof SOAPElement) { aoqi@0: next = node; aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return next != null; aoqi@0: } aoqi@0: aoqi@0: public Object next() { aoqi@0: if (hasNext()) { aoqi@0: last = next; aoqi@0: next = null; aoqi@0: return last; aoqi@0: } aoqi@0: throw new NoSuchElementException(); aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: if (last == null) { aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: Node target = last; aoqi@0: last = null; aoqi@0: removeChild(target); aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: public Iterator getChildElements(final Name name) { aoqi@0: return getChildElements(name.getURI(), name.getLocalName()); aoqi@0: } aoqi@0: aoqi@0: public Iterator getChildElements(final QName qname) { aoqi@0: return getChildElements(qname.getNamespaceURI(), qname.getLocalPart()); aoqi@0: } aoqi@0: aoqi@0: private Iterator getChildElements(final String nameUri, final String nameLocal) { aoqi@0: return new Iterator() { aoqi@0: Iterator eachElement = getChildElementNodes(); aoqi@0: Node next = null; aoqi@0: Node last = null; aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: if (next == null) { aoqi@0: while (eachElement.hasNext()) { aoqi@0: Node element = (Node) eachElement.next(); aoqi@0: String elementUri = element.getNamespaceURI(); aoqi@0: elementUri = elementUri == null ? "" : elementUri; aoqi@0: String elementName = element.getLocalName(); aoqi@0: if (elementUri.equals(nameUri) aoqi@0: && elementName.equals(nameLocal)) { aoqi@0: next = element; aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return next != null; aoqi@0: } aoqi@0: aoqi@0: public Object next() { aoqi@0: if (!hasNext()) { aoqi@0: throw new NoSuchElementException(); aoqi@0: } aoqi@0: last = next; aoqi@0: next = null; aoqi@0: return last; aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: if (last == null) { aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: Node target = last; aoqi@0: last = null; aoqi@0: removeChild(target); aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: public void removeContents() { aoqi@0: Node currentChild = getFirstChild(); aoqi@0: aoqi@0: while (currentChild != null) { aoqi@0: Node temp = currentChild.getNextSibling(); aoqi@0: if (currentChild instanceof javax.xml.soap.Node) { aoqi@0: ((javax.xml.soap.Node) currentChild).detachNode(); aoqi@0: } else { aoqi@0: Node parent = currentChild.getParentNode(); aoqi@0: if (parent != null) { aoqi@0: parent.removeChild(currentChild); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: currentChild = temp; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void setEncodingStyle(String encodingStyle) throws SOAPException { aoqi@0: if (!"".equals(encodingStyle)) { aoqi@0: try { aoqi@0: new URI(encodingStyle); aoqi@0: } catch (URISyntaxException m) { aoqi@0: log.log( aoqi@0: Level.SEVERE, aoqi@0: "SAAJ0105.impl.encoding.style.mustbe.valid.URI", aoqi@0: new String[] { encodingStyle }); aoqi@0: throw new IllegalArgumentException( aoqi@0: "Encoding style (" + encodingStyle + ") should be a valid URI"); aoqi@0: } aoqi@0: } aoqi@0: encodingStyleAttribute.setValue(encodingStyle); aoqi@0: tryToFindEncodingStyleAttributeName(); aoqi@0: } aoqi@0: aoqi@0: public String getEncodingStyle() { aoqi@0: String encodingStyle = encodingStyleAttribute.getValue(); aoqi@0: if (encodingStyle != null) aoqi@0: return encodingStyle; aoqi@0: String soapNamespace = getSOAPNamespace(); aoqi@0: if (soapNamespace != null) { aoqi@0: Attr attr = getAttributeNodeNS(soapNamespace, "encodingStyle"); aoqi@0: if (attr != null) { aoqi@0: encodingStyle = attr.getValue(); aoqi@0: try { aoqi@0: setEncodingStyle(encodingStyle); aoqi@0: } catch (SOAPException se) { aoqi@0: // has to be ignored aoqi@0: } aoqi@0: return encodingStyle; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: // Node methods aoqi@0: public String getValue() { aoqi@0: javax.xml.soap.Node valueNode = getValueNode(); aoqi@0: return valueNode == null ? null : valueNode.getValue(); aoqi@0: } aoqi@0: aoqi@0: public void setValue(String value) { aoqi@0: Node valueNode = getValueNodeStrict(); aoqi@0: if (valueNode != null) { aoqi@0: valueNode.setNodeValue(value); aoqi@0: } else { aoqi@0: try { aoqi@0: addTextNode(value); aoqi@0: } catch (SOAPException e) { aoqi@0: throw new RuntimeException(e.getMessage()); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected Node getValueNodeStrict() { aoqi@0: Node node = getFirstChild(); aoqi@0: if (node != null) { aoqi@0: if (node.getNextSibling() == null aoqi@0: && node.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { aoqi@0: return node; aoqi@0: } else { aoqi@0: log.severe("SAAJ0107.impl.elem.child.not.single.text"); aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: protected javax.xml.soap.Node getValueNode() { aoqi@0: Iterator i = getChildElements(); aoqi@0: while (i.hasNext()) { aoqi@0: javax.xml.soap.Node n = (javax.xml.soap.Node) i.next(); aoqi@0: if (n.getNodeType() == org.w3c.dom.Node.TEXT_NODE || aoqi@0: n.getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE) { aoqi@0: // TODO: Hack to fix text node split into multiple lines. aoqi@0: normalize(); aoqi@0: // Should remove the normalization step when this gets fixed in aoqi@0: // DOM/Xerces. aoqi@0: return (javax.xml.soap.Node) n; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public void setParentElement(SOAPElement element) throws SOAPException { aoqi@0: if (element == null) { aoqi@0: log.severe("SAAJ0106.impl.no.null.to.parent.elem"); aoqi@0: throw new SOAPException("Cannot pass NULL to setParentElement"); aoqi@0: } aoqi@0: element.addChildElement(this); aoqi@0: findEncodingStyleAttributeName(); aoqi@0: } aoqi@0: aoqi@0: protected void findEncodingStyleAttributeName() throws SOAPException { aoqi@0: String soapNamespace = getSOAPNamespace(); aoqi@0: if (soapNamespace != null) { aoqi@0: String soapNamespacePrefix = getNamespacePrefix(soapNamespace); aoqi@0: if (soapNamespacePrefix != null) { aoqi@0: setEncodingStyleNamespace(soapNamespace, soapNamespacePrefix); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected void setEncodingStyleNamespace( aoqi@0: String soapNamespace, aoqi@0: String soapNamespacePrefix) aoqi@0: throws SOAPException { aoqi@0: Name encodingStyleAttributeName = aoqi@0: NameImpl.create( aoqi@0: "encodingStyle", aoqi@0: soapNamespacePrefix, aoqi@0: soapNamespace); aoqi@0: encodingStyleAttribute.setName(encodingStyleAttributeName); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement getParentElement() { aoqi@0: Node parentNode = getParentNode(); aoqi@0: if (parentNode instanceof SOAPDocument) { aoqi@0: return null; aoqi@0: } aoqi@0: return (SOAPElement) parentNode; aoqi@0: } aoqi@0: aoqi@0: protected String getSOAPNamespace() { aoqi@0: String soapNamespace = null; aoqi@0: aoqi@0: SOAPElement antecedent = this; aoqi@0: while (antecedent != null) { aoqi@0: Name antecedentName = antecedent.getElementName(); aoqi@0: String antecedentNamespace = antecedentName.getURI(); aoqi@0: aoqi@0: if (NameImpl.SOAP11_NAMESPACE.equals(antecedentNamespace) aoqi@0: || NameImpl.SOAP12_NAMESPACE.equals(antecedentNamespace)) { aoqi@0: aoqi@0: soapNamespace = antecedentNamespace; aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: antecedent = antecedent.getParentElement(); aoqi@0: } aoqi@0: aoqi@0: return soapNamespace; aoqi@0: } aoqi@0: aoqi@0: public void detachNode() { aoqi@0: Node parent = getParentNode(); aoqi@0: if (parent != null) { aoqi@0: parent.removeChild(this); aoqi@0: } aoqi@0: encodingStyleAttribute.clearNameAndValue(); aoqi@0: // Fix for CR: 6474641 aoqi@0: //tryToFindEncodingStyleAttributeName(); aoqi@0: } aoqi@0: aoqi@0: public void tryToFindEncodingStyleAttributeName() { aoqi@0: try { aoqi@0: findEncodingStyleAttributeName(); aoqi@0: } catch (SOAPException e) { /*okay to fail*/ aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void recycleNode() { aoqi@0: detachNode(); aoqi@0: // TBD aoqi@0: // - add this to the factory so subsequent aoqi@0: // creations can reuse this object. aoqi@0: } aoqi@0: aoqi@0: class AttributeManager { aoqi@0: Name attributeName = null; aoqi@0: String attributeValue = null; aoqi@0: aoqi@0: public void setName(Name newName) throws SOAPException { aoqi@0: clearAttribute(); aoqi@0: attributeName = newName; aoqi@0: reconcileAttribute(); aoqi@0: } aoqi@0: public void clearName() { aoqi@0: clearAttribute(); aoqi@0: attributeName = null; aoqi@0: } aoqi@0: public void setValue(String value) throws SOAPException { aoqi@0: attributeValue = value; aoqi@0: reconcileAttribute(); aoqi@0: } aoqi@0: public Name getName() { aoqi@0: return attributeName; aoqi@0: } aoqi@0: public String getValue() { aoqi@0: return attributeValue; aoqi@0: } aoqi@0: aoqi@0: /** Note: to be used only in detachNode method */ aoqi@0: public void clearNameAndValue() { aoqi@0: attributeName = null; aoqi@0: attributeValue = null; aoqi@0: } aoqi@0: aoqi@0: private void reconcileAttribute() throws SOAPException { aoqi@0: if (attributeName != null) { aoqi@0: removeAttribute(attributeName); aoqi@0: if (attributeValue != null) { aoqi@0: addAttribute(attributeName, attributeValue); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: private void clearAttribute() { aoqi@0: if (attributeName != null) { aoqi@0: removeAttribute(attributeName); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected static org.w3c.dom.Attr getNamespaceAttrFrom( aoqi@0: Element element, aoqi@0: String prefix) { aoqi@0: NamespaceContextIterator eachNamespace = aoqi@0: new NamespaceContextIterator(element); aoqi@0: while (eachNamespace.hasNext()) { aoqi@0: org.w3c.dom.Attr namespaceDecl = eachNamespace.nextNamespaceAttr(); aoqi@0: String declaredPrefix = aoqi@0: NameImpl.getLocalNameFromTagName(namespaceDecl.getNodeName()); aoqi@0: if (declaredPrefix.equals(prefix)) { aoqi@0: return namespaceDecl; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: protected static Iterator getAllAttributesFrom(final Element element) { aoqi@0: final NamedNodeMap attributes = element.getAttributes(); aoqi@0: aoqi@0: return new Iterator() { aoqi@0: int attributesLength = attributes.getLength(); aoqi@0: int attributeIndex = 0; aoqi@0: String currentName; aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: return attributeIndex < attributesLength; aoqi@0: } aoqi@0: aoqi@0: public Object next() { aoqi@0: if (!hasNext()) { aoqi@0: throw new NoSuchElementException(); aoqi@0: } aoqi@0: Node current = attributes.item(attributeIndex++); aoqi@0: currentName = current.getNodeName(); aoqi@0: aoqi@0: String prefix = NameImpl.getPrefixFromTagName(currentName); aoqi@0: if (prefix.length() == 0) { aoqi@0: return NameImpl.createFromUnqualifiedName(currentName); aoqi@0: } else { aoqi@0: Name attributeName = aoqi@0: NameImpl.createFromQualifiedName( aoqi@0: currentName, aoqi@0: current.getNamespaceURI()); aoqi@0: return attributeName; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: if (currentName == null) { aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: attributes.removeNamedItem(currentName); aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: protected static String getAttributeValueFrom(Element element, Name name) { aoqi@0: return getAttributeValueFrom( aoqi@0: element, aoqi@0: name.getURI(), aoqi@0: name.getLocalName(), aoqi@0: name.getPrefix(), aoqi@0: name.getQualifiedName()); aoqi@0: } aoqi@0: aoqi@0: private static String getAttributeValueFrom( aoqi@0: Element element, aoqi@0: String uri, aoqi@0: String localName, aoqi@0: String prefix, aoqi@0: String qualifiedName) { aoqi@0: aoqi@0: String nonzeroLengthUri = aoqi@0: (uri == null || uri.length() == 0) ? null : uri; aoqi@0: aoqi@0: boolean mustUseGetAttributeNodeNS = (nonzeroLengthUri != null); aoqi@0: aoqi@0: if (mustUseGetAttributeNodeNS) { aoqi@0: aoqi@0: if (!element.hasAttributeNS(uri, localName)) { aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: String attrValue = aoqi@0: element.getAttributeNS(nonzeroLengthUri, localName); aoqi@0: aoqi@0: return attrValue; aoqi@0: } aoqi@0: aoqi@0: Attr attribute = null; aoqi@0: attribute = element.getAttributeNode(qualifiedName); aoqi@0: aoqi@0: return attribute == null ? null : attribute.getValue(); aoqi@0: } aoqi@0: aoqi@0: protected static Iterator getChildElementsFrom(final Element element) { aoqi@0: return new Iterator() { aoqi@0: Node next = element.getFirstChild(); aoqi@0: Node nextNext = null; aoqi@0: Node last = null; aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: if (next != null) { aoqi@0: return true; aoqi@0: } aoqi@0: if (next == null && nextNext != null) { aoqi@0: next = nextNext; aoqi@0: } aoqi@0: aoqi@0: return next != null; aoqi@0: } aoqi@0: aoqi@0: public Object next() { aoqi@0: if (hasNext()) { aoqi@0: last = next; aoqi@0: next = null; aoqi@0: aoqi@0: if ((element instanceof ElementImpl) aoqi@0: && (last instanceof Element)) { aoqi@0: last = aoqi@0: ((ElementImpl) element).convertToSoapElement( aoqi@0: (Element) last); aoqi@0: } aoqi@0: aoqi@0: nextNext = last.getNextSibling(); aoqi@0: return last; aoqi@0: } aoqi@0: throw new NoSuchElementException(); aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: if (last == null) { aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: Node target = last; aoqi@0: last = null; aoqi@0: element.removeChild(target); aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: public static String getQualifiedName(QName name) { aoqi@0: String prefix = name.getPrefix(); aoqi@0: String localName = name.getLocalPart(); aoqi@0: String qualifiedName = null; aoqi@0: aoqi@0: if (prefix != null && prefix.length() > 0) { aoqi@0: qualifiedName = prefix + ":" + localName; aoqi@0: } else { aoqi@0: qualifiedName = localName; aoqi@0: } aoqi@0: return qualifiedName; aoqi@0: } aoqi@0: aoqi@0: public static String getLocalPart(String qualifiedName) { aoqi@0: if (qualifiedName == null) { aoqi@0: // Log aoqi@0: throw new IllegalArgumentException("Cannot get local name for a \"null\" qualified name"); aoqi@0: } aoqi@0: aoqi@0: int index = qualifiedName.indexOf(':'); aoqi@0: if (index < 0) aoqi@0: return qualifiedName; aoqi@0: else aoqi@0: return qualifiedName.substring(index + 1); aoqi@0: } aoqi@0: aoqi@0: public static String getPrefix(String qualifiedName) { aoqi@0: if (qualifiedName == null) { aoqi@0: // Log aoqi@0: throw new IllegalArgumentException("Cannot get prefix for a \"null\" qualified name"); aoqi@0: } aoqi@0: aoqi@0: int index = qualifiedName.indexOf(':'); aoqi@0: if (index < 0) aoqi@0: return ""; aoqi@0: else aoqi@0: return qualifiedName.substring(0, index); aoqi@0: } aoqi@0: aoqi@0: protected boolean isNamespaceQualified(Name name) { aoqi@0: return !"".equals(name.getURI()); aoqi@0: } aoqi@0: aoqi@0: protected boolean isNamespaceQualified(QName name) { aoqi@0: return !"".equals(name.getNamespaceURI()); aoqi@0: } aoqi@0: aoqi@0: //TODO: This is a temporary SAAJ workaround for optimizing XWS aoqi@0: // should be removed once the corresponding JAXP bug is fixed aoqi@0: // It appears the bug will be fixed in JAXP 1.4 (not by Appserver 9 timeframe) aoqi@0: public void setAttributeNS( aoqi@0: String namespaceURI,String qualifiedName, String value) { aoqi@0: int index = qualifiedName.indexOf(':'); aoqi@0: String localName; aoqi@0: if (index < 0) aoqi@0: localName = qualifiedName; aoqi@0: else aoqi@0: localName = qualifiedName.substring(index + 1); aoqi@0: aoqi@0: // Workaround for bug 6467808 - This needs to be fixed in JAXP aoqi@0: aoqi@0: // Rolling back this fix, this is a wrong fix, infact its causing other regressions in JAXWS tck and aoqi@0: // other tests, because of this change the namespace declarations on soapenv:Fault element are never aoqi@0: // picked up. The fix for bug 6467808 should be in JAXP. aoqi@0: // if(elementQName.getLocalPart().equals("Fault") && aoqi@0: // (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(value) || aoqi@0: // SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(value))) aoqi@0: // return; aoqi@0: aoqi@0: super.setAttributeNS(namespaceURI,qualifiedName,value); aoqi@0: //String tmpLocalName = this.getLocalName(); aoqi@0: String tmpURI = this.getNamespaceURI(); aoqi@0: boolean isIDNS = false; aoqi@0: if( tmpURI != null && (tmpURI.equals(DSIG_NS) || tmpURI.equals(XENC_NS))){ aoqi@0: isIDNS = true; aoqi@0: } aoqi@0: //No need to check for Signature/encryption element aoqi@0: //just check for namespace. aoqi@0: if(localName.equals("Id")){ aoqi@0: if(namespaceURI == null || namespaceURI.equals("")){ aoqi@0: setIdAttribute(localName,true); aoqi@0: }else if(isIDNS || WSU_NS.equals(namespaceURI)){ aoqi@0: setIdAttributeNS(namespaceURI,localName,true); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: }