Skip to content

Commit

Permalink
eclipse-ee4j#171: Inconsistent owner document
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Mar 1, 2021
1 parent 5cee792 commit c662362
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Comment> implements Comment {

Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Text> implements Text {
Expand All @@ -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());
Expand Down

0 comments on commit c662362

Please sign in to comment.