[jbossws-commits] JBossWS SVN: r2293 - trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Wed Feb 7 05:21:06 EST 2007
Author: alex.guizar at jboss.com
Date: 2007-02-07 05:21:06 -0500 (Wed, 07 Feb 2007)
New Revision: 2293
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
Log:
JBCTS-440
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-02-07 10:20:03 UTC (rev 2292)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-02-07 10:21:06 UTC (rev 2293)
@@ -39,6 +39,7 @@
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
+import javax.xml.soap.Text;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
@@ -232,20 +233,17 @@
{
log.trace("appendChild: " + newChild.getNodeName());
expandToDOM();
- Node retNode;
- if (!(newChild instanceof SOAPBodyElement || newChild instanceof DocumentFragment))
- {
+ if (needsConversionToBodyElement(newChild))
newChild = convertToBodyElement(newChild);
- }
- retNode = super.appendChild(newChild);
- return retNode;
+
+ return super.appendChild(newChild);
}
public Node insertBefore(Node newChild, Node refChild) throws DOMException
{
log.trace("insertBefore: " + newChild.getNodeName());
expandToDOM();
- if (!(newChild instanceof SOAPBodyElement || newChild instanceof DocumentFragment))
+ if (needsConversionToBodyElement(newChild))
newChild = convertToBodyElement(newChild);
return super.insertBefore(newChild, refChild);
@@ -255,10 +253,8 @@
{
log.trace("replaceChild: " + newChild.getNodeName());
expandToDOM();
- if (!(newChild instanceof SOAPBodyElement || newChild instanceof DocumentFragment))
- {
+ if (needsConversionToBodyElement(newChild))
newChild = convertToBodyElement(newChild);
- }
return super.replaceChild(newChild, oldChild);
}
@@ -304,8 +300,16 @@
expandToDOM();
return super.hasChildNodes();
}
+
+ private static boolean needsConversionToBodyElement(Node node)
+ {
+ // JBCTS-440 #addTextNodeTest1 appends a Text node to a SOAPBody
+ return !(node instanceof SOAPBodyElement
+ || node instanceof DocumentFragment
+ || node instanceof Text);
+ }
- private SOAPBodyElementDoc convertToBodyElement(Node node)
+ private static SOAPBodyElementDoc convertToBodyElement(Node node)
{
if (!(node instanceof SOAPElementImpl))
throw new IllegalArgumentException("SOAPElement expected");
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-02-07 10:20:03 UTC (rev 2292)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-02-07 10:21:06 UTC (rev 2293)
@@ -68,13 +68,15 @@
private Element element;
// The element name
private Name elementName;
- // The element's encoding style
- private String encodingStyle = Constants.URI_LITERAL_ENC;
+ /* The element's encoding style
+ * JBCTS-440 #getEncodingStyleTest1 expects the initial value of the
+ * encodingStyle property to be null
+ */
+ private String encodingStyle = null;
/** Called by SOAPFactory */
public SOAPElementImpl(String localPart)
{
-
super(DOMUtils.createElement(localPart, null, null));
this.element = (Element)domNode;
log.trace("new SOAPElementImpl: " + getElementName());
@@ -123,33 +125,59 @@
public QName getElementQName()
{
- String nsURI = getNamespaceURI();
- String localPart = getLocalName();
- String prefix = getPrefix();
+ return ((NameImpl)getElementName()).toQName();
+ }
- QName qname;
- if (nsURI != null && prefix != null)
+ /**
+ * Changes the name of this Element to newName if possible. SOAP Defined elements such as SOAPEnvelope, SOAPHeader, SOAPBody etc. cannot
+ * have their names changed using this method. Any attempt to do so will result in a SOAPException being thrown.
+ *
+ * Callers should not rely on the element instance being renamed as is.
+ * Implementations could end up copying the content of the SOAPElement to a renamed instance.
+ * @param qname the new name for the Element.
+ * @return The renamed Node
+ * @throws SOAPException if changing the name of this Element is not allowed.
+ */
+ public SOAPElement setElementQName(QName qname) throws SOAPException
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()) || Constants.NS_SOAP12_ENV.equals(getNamespaceURI()))
+ throw new SOAPException("Changing the name of this SOAP Element is not allowed: " + getLocalName());
+
+ // Since DOM Elements do not support renaming, we must copy the content
+ Element copy = DOMUtils.createElement(qname.getLocalPart(), qname.getPrefix(), qname.getNamespaceURI());
+
+ // copy attributes (and namespaces by the way)
+ NamedNodeMap attributes = element.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++)
{
- qname = new QName(nsURI, localPart, prefix);
+ org.w3c.dom.Node attribute = attributes.item(i);
+
+ // DOM disallows moving an attribute, it must explicitly be cloned
+ copy.setAttributeNode((Attr)attribute.cloneNode(true));
}
- else if (nsURI != null)
+
+ // move child nodes
+ for (org.w3c.dom.Node child = element.getFirstChild(), next; child != null; child = next)
{
- qname = new QName(nsURI, localPart);
+ next = child.getNextSibling();
+
+ // DOM removes a node from the tree before adding it to a different element
+ copy.appendChild(child);
}
- else
- {
- qname = new QName(localPart);
- }
- return qname;
+ // replace element with copy
+ org.w3c.dom.Node parent = element.getParentNode();
+ if (parent != null)
+ parent.replaceChild(copy, element);
+
+ // update fields
+ domNode = copy;
+ element = copy;
+ elementName = null; // getElementName() regenerates this field
+
+ return this;
}
- public SOAPElement setElementQName(QName qname) throws SOAPException
- {
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
- }
-
/**
* Adds an attribute with the specified name and value to this SOAPElement object.
*
@@ -316,6 +344,7 @@
* @param value a String object with the textual content to be added
* @return the SOAPElement object into which the new Text object was inserted
* @throws javax.xml.soap.SOAPException if there is an error in creating the new Text object
+ * or if it is not legal to attach it as a child to this SOAPElement
*/
public SOAPElement addTextNode(String value) throws SOAPException
{
@@ -656,18 +685,23 @@
* Sets the encoding style for this SOAPElement object to one specified.
*
* @param encodingStyle a String giving the encoding style
- * @throws javax.xml.soap.SOAPException if there was a problem in the encoding style being set.
+ * @throws IllegalArgumentException if there was a problem in the encoding style being set.
+ * @throws javax.xml.soap.SOAPException if setting the encodingStyle is invalid for this SOAPElement.
*/
public void setEncodingStyle(String encodingStyle) throws SOAPException
{
- if (!Constants.URI_LITERAL_ENC.equals(encodingStyle) && !Constants.URI_SOAP11_ENC.equals(encodingStyle))
+ if (Constants.NS_SOAP12_ENV.equals(getNamespaceURI()))
+ throw new SOAPException("Setting the encodingStyle is invalid for this SOAP 1.2 Element: " + getLocalName());
+
+ /* JBCTS-440 #getEncodingStyleTest1 expects the initial value of the
+ * encodingStyle property to be null, hence null is a legal argument
+ */
+ if (!Constants.URI_LITERAL_ENC.equals(encodingStyle) && !Constants.URI_SOAP11_ENC.equals(encodingStyle) && encodingStyle != null)
throw new IllegalArgumentException("Unsupported encodingStyle: " + encodingStyle);
this.encodingStyle = encodingStyle;
}
- // org.w3c.Element ***********************************************************************************************
-
public String getTagName()
{
return element.getTagName();
@@ -776,9 +810,11 @@
throw new NotImplementedException("setIdAttributeNS");
}
- public void accept(SAAJVisitor visitor) {
- visitor.visitSOAPElement(this);
+ public void accept(SAAJVisitor visitor)
+ {
+ visitor.visitSOAPElement(this);
}
+
/**
* The default implementation uses a DOMWriter.
* SOAPContentElements overwrite this to optimize DOM callbacks.
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-02-07 10:20:03 UTC (rev 2292)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-02-07 10:21:06 UTC (rev 2293)
@@ -30,8 +30,10 @@
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.Text;
import org.jboss.util.NotImplementedException;
+import org.jboss.ws.Constants;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
@@ -49,8 +51,16 @@
{
super("Header", prefix, namespace);
}
+
+ private static boolean needsConversionToHeaderElement(Node newChild)
+ {
+ // JBCTS-440 #addTextNodeTest2 appends a Text node to a SOAPHeader
+ return !(newChild instanceof SOAPHeaderElementImpl
+ || newChild instanceof DocumentFragment
+ || newChild instanceof Text);
+ }
- private SOAPHeaderElementImpl convertToHeaderElement(Node node)
+ private static SOAPHeaderElementImpl convertToHeaderElement(Node node)
{
if (!(node instanceof SOAPElementImpl))
throw new IllegalArgumentException("SOAPElement expected");
@@ -61,8 +71,8 @@
element.detachNode();
return new SOAPHeaderElementImpl(element);
}
-
- /*** Add a SOAPHeaderElement as a child of this SOAPHeader instance.
+
+ /** Add a SOAPHeaderElement as a child of this SOAPHeader instance.
*/
public SOAPElement addChildElement(SOAPElement child) throws SOAPException
{
@@ -73,6 +83,18 @@
return super.addChildElement(child);
}
+ /** Attaching a Text node is not legal.
+ */
+ @Override
+ public SOAPElement addTextNode(String value) throws SOAPException
+ {
+ // JBCTS-440 #addTextNodeTest2 adds a text node to a SOAPHeader and expects a SOAPException
+ if (Constants.NS_SOAP12_ENV.equals(getNamespaceURI()))
+ throw new SOAPException("Attaching a Text node to this SOAP 1.2 Element is not legal: " + getLocalName());
+
+ return super.addTextNode(value);
+ }
+
/** Creates a new SOAPHeaderElement object initialized with the specified name and adds it to this SOAPHeader object.
*/
public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException
@@ -89,7 +111,7 @@
{
return addHeaderElement(new NameImpl(qname));
}
-
+
/** Returns an Iterator over all the SOAPHeaderElement objects in this SOAPHeader object.
*/
public Iterator examineAllHeaderElements()
@@ -180,7 +202,7 @@
public Node appendChild(Node newChild) throws DOMException
{
- if (!(newChild instanceof SOAPHeaderElementImpl || newChild instanceof DocumentFragment))
+ if (needsConversionToHeaderElement(newChild))
newChild = convertToHeaderElement(newChild);
return super.appendChild(newChild);
@@ -188,7 +210,7 @@
public Node insertBefore(Node newChild, Node refChild) throws DOMException
{
- if (!(newChild instanceof SOAPHeaderElementImpl || newChild instanceof DocumentFragment))
+ if (needsConversionToHeaderElement(newChild))
newChild = convertToHeaderElement(newChild);
return super.insertBefore(newChild, refChild);
@@ -196,7 +218,7 @@
public Node replaceChild(Node newChild, Node oldChild) throws DOMException
{
- if (!(newChild instanceof SOAPHeaderElementImpl || newChild instanceof DocumentFragment))
+ if (needsConversionToHeaderElement(newChild))
newChild = convertToHeaderElement(newChild);
return super.replaceChild(newChild, oldChild);
More information about the jbossws-commits
mailing list