From c662362b4a5f5108f872d7ffeab69341faaaf1ff Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Fri, 26 Feb 2021 11:48:17 +0100 Subject: [PATCH] #171: Inconsistent owner document Signed-off-by: Lukas Jungmann --- .../messaging/saaj/soap/impl/AttrImpl.java | 48 ++++++++++++++++++- .../messaging/saaj/soap/impl/ElementImpl.java | 31 +++++------- .../saaj/soap/impl/SOAPCommentImpl.java | 8 +++- .../saaj/soap/impl/SOAPTextImpl.java | 8 +++- 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/AttrImpl.java b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/AttrImpl.java index 184cc46..a350414 100644 --- a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/AttrImpl.java +++ b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/AttrImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -33,178 +33,222 @@ public class AttrImpl implements Attr, jakarta.xml.soap.Node { this.delegate = attr; } + @Override public String getNodeName() { return delegate.getNodeName(); } + @Override public String getNodeValue() throws DOMException { return delegate.getNodeValue(); } + @Override public void setNodeValue(String nodeValue) throws DOMException { delegate.setNodeValue(nodeValue); } + @Override public short getNodeType() { - return delegate.getNodeType(); + return Node.ATTRIBUTE_NODE; } + @Override public Node getParentNode() { return delegate.getParentNode(); } + @Override public NodeList getChildNodes() { return delegate.getChildNodes(); } + @Override public String getName() { return delegate.getName(); } + @Override public Node getFirstChild() { return delegate.getFirstChild(); } + @Override public boolean getSpecified() { return delegate.getSpecified(); } + @Override public Node getLastChild() { return delegate.getLastChild(); } + @Override public Node getPreviousSibling() { return delegate.getPreviousSibling(); } + @Override public Node getNextSibling() { return delegate.getNextSibling(); } + @Override public String getValue() { return delegate.getValue(); } + @Override public NamedNodeMap getAttributes() { return delegate.getAttributes(); } + @Override public Document getOwnerDocument() { return soapElement.getOwnerDocument(); } + @Override public Node insertBefore(Node newChild, Node refChild) throws DOMException { return delegate.insertBefore(newChild, refChild); } + @Override public void setValue(String value) throws DOMException { delegate.setValue(value); } + @Override public Element getOwnerElement() { return soapElement; } + @Override public TypeInfo getSchemaTypeInfo() { return delegate.getSchemaTypeInfo(); } + @Override public boolean isId() { return delegate.isId(); } + @Override public Node replaceChild(Node newChild, Node oldChild) throws DOMException { return delegate.replaceChild(newChild, oldChild); } + @Override public Node removeChild(Node oldChild) throws DOMException { return delegate.removeChild(oldChild); } + @Override public Node appendChild(Node newChild) throws DOMException { return delegate.appendChild(newChild); } + @Override public boolean hasChildNodes() { return delegate.hasChildNodes(); } + @Override public Node cloneNode(boolean deep) { return delegate.cloneNode(deep); } + @Override public void normalize() { delegate.normalize(); } + @Override public boolean isSupported(String feature, String version) { return delegate.isSupported(feature, version); } + @Override public String getNamespaceURI() { return delegate.getNamespaceURI(); } + @Override public String getPrefix() { return delegate.getPrefix(); } + @Override public void setPrefix(String prefix) throws DOMException { delegate.setPrefix(prefix); } + @Override public String getLocalName() { return delegate.getLocalName(); } + @Override public boolean hasAttributes() { return delegate.hasAttributes(); } + @Override public String getBaseURI() { return delegate.getBaseURI(); } + @Override public short compareDocumentPosition(Node other) throws DOMException { return delegate.compareDocumentPosition(other); } + @Override public String getTextContent() throws DOMException { return delegate.getTextContent(); } + @Override public void setTextContent(String textContent) throws DOMException { delegate.setTextContent(textContent); } + @Override public boolean isSameNode(Node other) { return delegate.isSameNode(other); } + @Override public String lookupPrefix(String namespaceURI) { return delegate.lookupPrefix(namespaceURI); } + @Override public boolean isDefaultNamespace(String namespaceURI) { return delegate.isDefaultNamespace(namespaceURI); } + @Override public String lookupNamespaceURI(String prefix) { return delegate.lookupNamespaceURI(prefix); } + @Override public boolean isEqualNode(Node arg) { return delegate.isEqualNode(arg); } + @Override public Object getFeature(String feature, String version) { return delegate.getFeature(feature, version); } + @Override public Object setUserData(String key, Object data, UserDataHandler handler) { return delegate.setUserData(key, data, handler); } + @Override public Object getUserData(String key) { return delegate.getUserData(key); } diff --git a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/ElementImpl.java b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/ElementImpl.java index a133383..ec3270c 100644 --- a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/ElementImpl.java +++ b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/ElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -12,6 +12,7 @@ import com.sun.xml.messaging.saaj.SOAPExceptionImpl; import com.sun.xml.messaging.saaj.soap.SOAPDocument; +import com.sun.xml.messaging.saaj.soap.SOAPDocumentFragment; import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl; import com.sun.xml.messaging.saaj.soap.name.NameImpl; import com.sun.xml.messaging.saaj.util.LogDomainConstants; @@ -65,7 +66,8 @@ public String getTagName() { @Override public String getAttribute(String name) { - return element.getAttribute(name); + Attr n = getAttributeNode(name); + return n != null ? n.getValue() : ""; } @Override @@ -121,7 +123,8 @@ public NodeList getElementsByTagName(String name) { @Override public String getAttributeNS(String namespaceURI, String localName) throws DOMException { - return element.getAttributeNS(namespaceURI, localName); + Attr a = getAttributeNodeNS(namespaceURI, localName); + return a != null ? a.getValue() : ""; } protected static final Logger log = @@ -279,18 +282,7 @@ public String getTextContent() throws DOMException { @Override public void setTextContent(String textContent) throws DOMException { - element.setTextContent(textContent); - // The text node is always the first child (at least in xerces) - Node firstChild = element.getFirstChild(); - if (firstChild instanceof Text) { - // This constructor self-registers the node presence - new SOAPTextImpl(soapDocument, textContent) { - @Override - protected Text createN(SOAPDocumentImpl ownerDoc, String text) { - return (Text) firstChild; // Reuse the text node created by the DOM element - } - }; - } + new SOAPTextImpl(soapDocument, textContent); } @Override @@ -1641,13 +1633,16 @@ public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOM @Override public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { - return element.setAttributeNodeNS(newAttr); + return register(element.setAttributeNodeNS(newAttr)); } - private void register(Attr newAttr) { + private Attr register(Attr newAttr) { if (newAttr != null) { - newAttr.setUserData(SAAJ_NODE, new AttrImpl(this, newAttr), null); + Attr sn = new AttrImpl(this, newAttr); + newAttr.setUserData(SAAJ_NODE, sn, null); + return sn; } + return newAttr; } private Attr find(Attr attr) { diff --git a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPCommentImpl.java b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPCommentImpl.java index dc45116..e462d6f 100644 --- a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPCommentImpl.java +++ b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPCommentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -17,6 +17,7 @@ import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl; import static com.sun.xml.messaging.saaj.soap.impl.TextImpl.log; +import org.w3c.dom.Node; public class SOAPCommentImpl extends TextImpl implements Comment { @@ -48,6 +49,11 @@ public boolean isComment() { return true; } + @Override + public short getNodeType() { + return Node.COMMENT_NODE; + } + @Override public Text splitText(int offset) throws DOMException { log.severe("SAAJ0113.impl.cannot.split.text.from.comment"); diff --git a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPTextImpl.java b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPTextImpl.java index 142b4b8..785f443 100644 --- a/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPTextImpl.java +++ b/saaj-ri/src/main/java/com/sun/xml/messaging/saaj/soap/impl/SOAPTextImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -13,6 +13,7 @@ import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl; import org.w3c.dom.CharacterData; import org.w3c.dom.DOMException; +import org.w3c.dom.Node; import org.w3c.dom.Text; public class SOAPTextImpl extends TextImpl implements Text { @@ -25,6 +26,11 @@ public SOAPTextImpl(SOAPDocumentImpl ownerDoc, CharacterData data) { super(ownerDoc, data); } + @Override + public short getNodeType() { + return Node.TEXT_NODE; + } + @Override protected SOAPTextImpl doClone() { return new SOAPTextImpl(getSoapDocument(), this.getTextContent());