[jbossws-commits] JBossWS SVN: r2780 - trunk/jbossws-core/src/java/org/jboss/ws/core/soap.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Apr 10 09:21:22 EDT 2007


Author: thomas.diesler at jboss.com
Date: 2007-04-10 09:21:22 -0400 (Tue, 10 Apr 2007)
New Revision: 2780

Modified:
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
Log:
Fix handling of encodingStyle attribute

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-04-10 08:32:15 UTC (rev 2779)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-04-10 13:21:22 UTC (rev 2780)
@@ -406,11 +406,6 @@
       super.setAttributeNS(namespaceURI, qualifiedName, value);
    }
 
-   public void setEncodingStyle(String encodingStyle) throws SOAPException
-   {
-      super.setEncodingStyle(encodingStyle);
-   }
-
    public void setIdAttribute(String name, boolean isId) throws DOMException
    {
       log.trace("setIdAttribute: [name=" + name + ",value=" + isId + "]");

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java	2007-04-10 08:32:15 UTC (rev 2779)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java	2007-04-10 13:21:22 UTC (rev 2780)
@@ -69,11 +69,6 @@
    private Element element;
    // The element name
    private Name elementName;
-   // 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)
@@ -533,16 +528,6 @@
    }
 
    /**
-    * Returns the encoding style for this SOAPElement object.
-    *
-    * @return a String giving the encoding style
-    */
-   public String getEncodingStyle()
-   {
-      return encodingStyle;
-   }
-
-   /**
     * Returns an Iterator over the namespace prefix Strings declared by this element.
     * <p/>
     * The prefixes returned by this iterator can be passed to the method getNamespaceURI to retrieve the URI of each namespace.
@@ -657,7 +642,21 @@
    }
 
    /**
+    * Returns the encoding style for this SOAPElement object.
+    * @return a String giving the encoding style
+    */
+   public String getEncodingStyle()
+   {
+      // JBCTS-440 #getEncodingStyleTest1 expects the initial value of the encodingStyle property to be null
+      String encodingStyle = getAttribute(Constants.PREFIX_ENV + ":encodingStyle");
+      return (encodingStyle.length() > 0 ? encodingStyle : null);
+   }
+
+   /**
     * Sets the encoding style for this SOAPElement object to one specified.
+    * 
+    * @see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383495
+    * @see http://www.w3.org/TR/soap12-part1/#soapencattr
     *
     * @param encodingStyle a String giving the encoding style
     * @throws IllegalArgumentException if there was a problem in the encoding style being set.
@@ -665,16 +664,9 @@
     */
    public void setEncodingStyle(String encodingStyle) throws SOAPException
    {
-      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;
+      String namespaceURI = getNamespaceURI(Constants.PREFIX_ENV);
+      NameImpl name = new NameImpl("encodingStyle", Constants.PREFIX_ENV, namespaceURI);
+      addAttribute(name, encodingStyle);
    }
 
    public String getTagName()

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java	2007-04-10 08:32:15 UTC (rev 2779)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java	2007-04-10 13:21:22 UTC (rev 2780)
@@ -64,7 +64,7 @@
       String prefix = getPrefix();
       String namespaceURI = getNamespaceURI();
       String localName = getLocalName();
-      
+
       if ("Envelope".equals(localName) == false)
          throw new IllegalArgumentException("Cannot create SOAP envelope from: " + element.getElementQName());
 
@@ -72,8 +72,10 @@
       addNamespaceDeclaration(prefix, namespaceURI);
 
       // the Element source might already contain a Header and Body declaration
-      if(null == soapPart.getEnvelope().getHeader()) addHeader();
-      if(null == soapPart.getEnvelope().getBody()) addBody();
+      if (null == soapPart.getEnvelope().getHeader())
+         addHeader();
+      if (null == soapPart.getEnvelope().getBody())
+         addBody();
    }
 
    /** Construct a SOAP envelope for the given SOAP version URI.
@@ -92,16 +94,6 @@
       addBody();
    }
 
-   private void assertEnvelopeNamespace(String namespaceURI)
-   {
-      if (!Constants.NS_SOAP12_ENV.equals(namespaceURI) && !Constants.NS_SOAP11_ENV.equals(namespaceURI))
-      {
-         QName faultCode = Constants.SOAP11_FAULT_CODE_VERSION_MISMATCH;
-         String faultString = "Invalid SOAP envelope namespace: " + namespaceURI;
-         throw new SOAPFaultException(faultCode, faultString, null, null);
-      }
-   }
-
    public SOAPMessage getSOAPMessage()
    {
       return soapPart.getSOAPMessage();
@@ -128,11 +120,22 @@
       return (SOAPHeader)addChildElement(header);
    }
 
+   @Override
+   public SOAPElement addAttribute(Name name, String value) throws SOAPException
+   {
+      String envNamespace = getNamespaceURI();
+      if (Constants.NS_SOAP12_ENV.equals(envNamespace) && name.equals(new NameImpl("encodingStyle", Constants.PREFIX_ENV, envNamespace)))
+         throw new SOAPException("Cannot set encodingStyle on: " + getElementQName());
+
+      return super.addAttribute(name, value);
+   }
+
    /** Make sure the child is either a SOAPHeader or SOAPBody */
    public SOAPElement addChildElement(SOAPElement child) throws SOAPException
    {
-      if ((child instanceof SOAPHeader) == false && (child instanceof SOAPBody) == false)
-         throw new IllegalArgumentException("SOAPHeader or SOAPBody expected");
+      String envNamespace = getNamespaceURI();
+      if (Constants.NS_SOAP12_ENV.equals(envNamespace) && !(child instanceof SOAPHeader) && !(child instanceof SOAPBody))
+         throw new SOAPException("SOAPHeader or SOAPBody expected");
 
       return super.addChildElement(child);
    }
@@ -183,4 +186,14 @@
    {
       return soapPart;
    }
+
+   private void assertEnvelopeNamespace(String namespaceURI)
+   {
+      if (!Constants.NS_SOAP12_ENV.equals(namespaceURI) && !Constants.NS_SOAP11_ENV.equals(namespaceURI))
+      {
+         QName faultCode = Constants.SOAP11_FAULT_CODE_VERSION_MISMATCH;
+         String faultString = "Invalid SOAP envelope namespace: " + namespaceURI;
+         throw new SOAPFaultException(faultCode, faultString, null, null);
+      }
+   }
 }

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-04-10 08:32:15 UTC (rev 2779)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java	2007-04-10 13:21:22 UTC (rev 2780)
@@ -53,31 +53,15 @@
    {
       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 static SOAPHeaderElementImpl convertToHeaderElement(Node node)
-   {
-      if (!(node instanceof SOAPElementImpl))
-         throw new IllegalArgumentException("SOAPElement expected");
-
-      SOAPElementImpl element = (SOAPElementImpl)node;
-
-      // convert to SOAPHeaderElement
-      element.detachNode();
-      return new SOAPHeaderElementImpl(element);
-   }
-   
    /** Add a SOAPHeaderElement as a child of this SOAPHeader instance.
     */
    public SOAPElement addChildElement(SOAPElement child) throws SOAPException
    {
+      QName qname = child.getElementQName();
+      if (qname == null || qname.getNamespaceURI().length() == 0 || qname.getPrefix().length() == 0)
+         throw new SOAPException("Invalid SOAPHeaderElement name: " + qname);
+
       // Check that we get a SOAPHeaderElement
       if ((child instanceof SOAPHeaderElement) == false)
          child = convertToHeaderElement(child);
@@ -93,7 +77,7 @@
       // 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);
    }
 
@@ -107,16 +91,16 @@
       return addHeaderElement(((NameImpl)name).toQName());
    }
 
-   public SOAPHeaderElement addHeaderElement(QName name) throws SOAPException
+   public SOAPHeaderElement addHeaderElement(QName qname) throws SOAPException
    {
-      if (name == null || name.getNamespaceURI().length() == 0 || name.getPrefix().length() == 0)
-         throw new SOAPException("Invalid SOAPHeaderElement name: " + name);
+      if (qname == null || qname.getNamespaceURI().length() == 0 || qname.getPrefix().length() == 0)
+         throw new SOAPException("Invalid SOAPHeaderElement name: " + qname);
 
-      SOAPHeaderElementImpl headerElement = new SOAPHeaderElementImpl(name);
+      SOAPHeaderElementImpl headerElement = new SOAPHeaderElementImpl(qname);
       addChildElement(headerElement);
       return headerElement;
    }
-   
+
    /** Returns an Iterator over all the SOAPHeaderElement objects in this SOAPHeader object.
     */
    public Iterator examineAllHeaderElements()
@@ -281,7 +265,25 @@
    {
       if (supportedSoapUri == null)
          throw new SOAPException("supported URI cannot be null");
-      
+
       return addUpgradeHeaderElement(Collections.singletonList(supportedSoapUri).iterator());
    }
+
+   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 static SOAPHeaderElementImpl convertToHeaderElement(Node node)
+   {
+      if (!(node instanceof SOAPElementImpl))
+         throw new IllegalArgumentException("SOAPElement expected");
+
+      SOAPElementImpl element = (SOAPElementImpl)node;
+
+      // convert to SOAPHeaderElement
+      element.detachNode();
+      return new SOAPHeaderElementImpl(element);
+   }
 }
\ No newline at end of file




More information about the jbossws-commits mailing list