Author: alex.guizar(a)jboss.com
Date: 2007-03-13 06:56:57 -0400 (Tue, 13 Mar 2007)
New Revision: 2605
Added:
trunk/jbossws-core/src/java/org/jboss/ws/core/utils/SAAJUtils.java
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
Log:
JBCTS-499 implemented SAAJ 1.3 methods in SOAPHeader
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java 2007-03-12 22:16:25
UTC (rev 2604)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java 2007-03-13 10:56:57
UTC (rev 2605)
@@ -35,7 +35,6 @@
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.ws.core.utils.DOMUtils;
-import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -123,15 +122,6 @@
}
@Override
- public Node appendChild(Node newChild) throws DOMException
- {
- if (newChild instanceof SOAPElementImpl && !(newChild instanceof
DetailEntry))
- newChild = convertToDetailEntry((SOAPElementImpl) newChild);
-
- return super.appendChild(newChild);
- }
-
- @Override
public SOAPElement addChildElement(SOAPElement child) throws SOAPException
{
if (!(child instanceof DetailEntry))
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java 2007-03-12
22:16:25 UTC (rev 2604)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java 2007-03-13
10:56:57 UTC (rev 2605)
@@ -39,6 +39,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.core.utils.DOMWriter;
+import org.jboss.ws.core.utils.SAAJUtils;
import org.jboss.xb.QNameBuilder;
import org.w3c.dom.Attr;
@@ -201,46 +202,9 @@
private static void setCode(SOAPElement codeElement, QName code) throws SOAPException
{
- String nsURI = code.getNamespaceURI();
- String prefix = code.getPrefix();
- if (prefix.length() == 0)
- {
- // no given prefix, find prefix currently associated to given URI
- prefix = getNamespacePrefix(codeElement, nsURI);
- if (prefix == null)
- {
- // no prefix currently associated to given URI, declare namespace locally
- prefix = "codeNS";
- codeElement.addNamespaceDeclaration(prefix, nsURI);
- }
- }
- // verify given prefix is associated to given URI
- else if (!nsURI.equals(codeElement.getNamespaceURI(prefix)))
- {
- // prefix is associated with other/no URI, declare namespace locally
- codeElement.addNamespaceDeclaration(prefix, nsURI);
- }
-
- codeElement.setValue(prefix + ":" + code.getLocalPart());
+ SAAJUtils.setQualifiedElementValue(codeElement, code);
}
- /**
- * Returns the prefix of the namespace that has the given URI.
- * @param nsURI the URI of the namespace to search for
- * @return the prefix of the namespace or <code>null</code> if not found
- */
- private static String getNamespacePrefix(SOAPElement element, String nsURI)
- {
- Iterator it = element.getVisibleNamespacePrefixes();
- while (it.hasNext())
- {
- String prefix = (String)it.next();
- if (nsURI.equals(element.getNamespaceURI(prefix)))
- return prefix;
- }
- return null;
- }
-
private static SOAPElement addChildValueElement(SOAPElement codeElement) throws
SOAPException
{
return codeElement.addChildElement("Value", codeElement.getPrefix(),
codeElement.getNamespaceURI());
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-03-12
22:16:25 UTC (rev 2604)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-03-13
10:56:57 UTC (rev 2605)
@@ -22,6 +22,8 @@
package org.jboss.ws.core.soap;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import javax.xml.namespace.QName;
@@ -32,8 +34,8 @@
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.Text;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.Constants;
+import org.jboss.ws.core.utils.SAAJUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
@@ -99,25 +101,28 @@
*/
public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException
{
- if (name == null || name.getURI().length() == 0 || name.getPrefix().length() == 0)
+ if (name == null)
throw new SOAPException("Invalid SOAPHeaderElement name: " + name);
+ return addHeaderElement(((NameImpl)name).toQName());
+ }
+
+ public SOAPHeaderElement addHeaderElement(QName name) throws SOAPException
+ {
+ if (name == null || name.getNamespaceURI().length() == 0 ||
name.getPrefix().length() == 0)
+ throw new SOAPException("Invalid SOAPHeaderElement name: " + name);
+
SOAPHeaderElementImpl headerElement = new SOAPHeaderElementImpl(name);
addChildElement(headerElement);
return headerElement;
}
-
- public SOAPHeaderElement addHeaderElement(QName qname) throws SOAPException
- {
- return addHeaderElement(new NameImpl(qname));
- }
/** Returns an Iterator over all the SOAPHeaderElement objects in this SOAPHeader
object.
*/
public Iterator examineAllHeaderElements()
{
// make a defensive copy
- ArrayList list = new ArrayList();
+ ArrayList<SOAPHeaderElement> list = new
ArrayList<SOAPHeaderElement>();
Iterator it = getChildElements();
while (it.hasNext())
{
@@ -135,7 +140,7 @@
throw new IllegalArgumentException("Invalid actor: " + actor);
// make a defensive copy
- ArrayList list = new ArrayList();
+ ArrayList<SOAPHeaderElement> list = new
ArrayList<SOAPHeaderElement>();
Iterator it = getChildElements();
while (it.hasNext())
{
@@ -155,7 +160,7 @@
throw new IllegalArgumentException("Invalid actor: " + actor);
// make a defensive copy
- ArrayList list = new ArrayList();
+ ArrayList<SOAPHeaderElement> list = new
ArrayList<SOAPHeaderElement>();
Iterator it = getChildElements();
while (it.hasNext())
{
@@ -169,7 +174,7 @@
public Iterator extractAllHeaderElements()
{
// make a defensive copy
- ArrayList list = new ArrayList();
+ ArrayList<SOAPHeaderElement> list = new
ArrayList<SOAPHeaderElement>();
Iterator it = getChildElements();
while (it.hasNext())
{
@@ -186,7 +191,7 @@
throw new IllegalArgumentException("Invalid actor: " + actor);
// make a defensive copy
- ArrayList list = new ArrayList();
+ ArrayList<SOAPHeaderElement> list = new
ArrayList<SOAPHeaderElement>();
Iterator it = getChildElements();
while (it.hasNext())
{
@@ -226,25 +231,57 @@
public SOAPHeaderElement addNotUnderstoodHeaderElement(QName qname) throws
SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Header does not support
the concept of NotUnderstood");
+
+ // create NotUnderstood header block
+ QName notUnderstoodName = new QName(getNamespaceURI(), "NotUnderstood",
getPrefix());
+ SOAPHeaderElement notUnderstoodElement = addHeaderElement(notUnderstoodName);
+
+ // set qname attribute
+ SAAJUtils.setQualifiedAttributeValue(notUnderstoodElement, "qname",
qname);
+
+ return notUnderstoodElement;
}
- public SOAPHeaderElement addUpgradeHeaderElement(Iterator soapURIs) throws
SOAPException
+ public SOAPHeaderElement addUpgradeHeaderElement(Iterator supportedSoapUris) throws
SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (supportedSoapUris == null)
+ throw new SOAPException("list of supported URIs cannot be null");
+
+ if (!supportedSoapUris.hasNext())
+ throw new SOAPException("list of supported URIs cannot be empty");
+
+ final String namespaceURI = getNamespaceURI();
+ final String prefix = getPrefix();
+
+ // create Upgrade header block
+ QName upgradeName = new QName(namespaceURI, "Upgrade", prefix);
+ SOAPHeaderElement upgradeElement = addHeaderElement(upgradeName);
+
+ while (supportedSoapUris.hasNext())
+ {
+ String soapUri = (String)supportedSoapUris.next();
+
+ SOAPElement supportedElement =
upgradeElement.addChildElement("SupportedEnvelope", prefix, namespaceURI);
+ SAAJUtils.setQualifiedAttributeValue(supportedElement, "qname", new
QName(soapUri, "Envelope"));
+ }
+ return upgradeElement;
}
- public SOAPHeaderElement addUpgradeHeaderElement(String[] soapURIs) throws
SOAPException
+ public SOAPHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris) throws
SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (supportedSoapUris == null)
+ throw new SOAPException("list of supported URIs cannot be null");
+
+ return addUpgradeHeaderElement(Arrays.asList(supportedSoapUris).iterator());
}
- public SOAPHeaderElement addUpgradeHeaderElement(String soapURI) throws SOAPException
+ public SOAPHeaderElement addUpgradeHeaderElement(String supportedSoapUri) throws
SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (supportedSoapUri == null)
+ throw new SOAPException("supported URI cannot be null");
+
+ return
addUpgradeHeaderElement(Collections.singletonList(supportedSoapUri).iterator());
}
}
\ No newline at end of file
Added: trunk/jbossws-core/src/java/org/jboss/ws/core/utils/SAAJUtils.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/utils/SAAJUtils.java
(rev 0)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/utils/SAAJUtils.java 2007-03-13 10:56:57
UTC (rev 2605)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.utils;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+
+/**
+ * SAAJ utilities.
+ * @author <a href="mailto:alex.guizar@jboss.com">Alejandro
Guizar</a>
+ * @version $Revision$
+ */
+public class SAAJUtils
+{
+ /** Set the qname value to the given element.
+ * @param value a namespace qualified name; its namespace name MUST NOT be empty
+ */
+ public static void setQualifiedElementValue(SOAPElement element, QName value) throws
SOAPException
+ {
+ String prefix = ensureNamespaceDeclared(element, value.getPrefix(),
value.getNamespaceURI());
+ element.setValue(prefix + ':' + value.getLocalPart());
+ }
+
+ /** Set the qname value to the specified attribute of the given element.
+ * @param value a namespace qualified name; its namespace name MUST NOT be empty
+ */
+ public static void setQualifiedAttributeValue(SOAPElement element, String
attributeName, QName value) throws SOAPException
+ {
+ String prefix = ensureNamespaceDeclared(element, value.getPrefix(),
value.getNamespaceURI());
+ element.setAttribute(attributeName, prefix + ':' + value.getLocalPart());
+ }
+
+ /** Ensures the given namespace is declared in the scope of the given element.
+ */
+ private static String ensureNamespaceDeclared(SOAPElement element, String prefix,
String nsURI) throws SOAPException
+ {
+ if (prefix.length() == 0)
+ {
+ // no given prefix, find prefix currently associated to given URI
+ prefix = getNamespacePrefix(element, nsURI);
+ if (prefix == null)
+ {
+ // no prefix currently associated to given URI, declare namespace locally
+ prefix = "valueNS";
+ element.addNamespaceDeclaration(prefix, nsURI);
+ }
+ }
+ // verify given prefix is associated to given URI
+ else if (!nsURI.equals(element.getNamespaceURI(prefix)))
+ {
+ // prefix is associated with other/no URI, declare namespace locally
+ element.addNamespaceDeclaration(prefix, nsURI);
+ }
+ return prefix;
+ }
+
+ /**
+ * Returns the prefix of the namespace that has the given URI.
+ * @param nsURI the URI of the namespace to search for
+ * @return the prefix of the namespace or <code>null</code> if not found
+ */
+ public static String getNamespacePrefix(SOAPElement element, String nsURI)
+ {
+ Iterator it = element.getVisibleNamespacePrefixes();
+ while (it.hasNext())
+ {
+ String prefix = (String)it.next();
+ if (nsURI.equals(element.getNamespaceURI(prefix)))
+ return prefix;
+ }
+ return null;
+ }
+}
Property changes on: trunk/jbossws-core/src/java/org/jboss/ws/core/utils/SAAJUtils.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF