[jbossws-commits] JBossWS SVN: r2794 - in trunk/jbossws-core/src/java/org/jboss/ws/core: soap and 1 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Apr 11 09:00:36 EDT 2007


Author: thomas.diesler at jboss.com
Date: 2007-04-11 09:00:35 -0400 (Wed, 11 Apr 2007)
New Revision: 2794

Added:
   trunk/jbossws-core/src/java/org/jboss/ws/core/utils/DocumentBuilderFactoryImpl.java
Modified:
   trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchSOAPBinding.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java
Log:
Reuse generic soap content element name

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchSOAPBinding.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchSOAPBinding.java	2007-04-11 12:39:55 UTC (rev 2793)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchSOAPBinding.java	2007-04-11 13:00:35 UTC (rev 2794)
@@ -23,27 +23,35 @@
 
 // $Id$
 
-import org.jboss.logging.Logger;
-import org.jboss.ws.core.MessageAbstraction;
-import org.jboss.ws.core.soap.*;
-import org.jboss.ws.core.utils.DOMWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.namespace.QName;
-import javax.xml.soap.*;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.WebServiceException;
 import javax.xml.ws.Service.Mode;
-import javax.xml.ws.WebServiceException;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.StringReader;
 
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.MessageAbstraction;
+import org.jboss.ws.core.soap.SOAPBodyElementDoc;
+import org.jboss.ws.core.soap.SOAPBodyImpl;
+import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.SOAPMessageImpl;
+import org.jboss.ws.core.soap.XMLFragment;
+import org.jboss.ws.core.utils.DOMWriter;
+
 /**
  * A helper that 
  * 
@@ -57,14 +65,14 @@
 
    private JAXBContext jaxbContext;
    private Class type;
-   private Mode mode;   
-   
+   private Mode mode;
+
    public DispatchSOAPBinding(Mode mode, Class type, JAXBContext jaxbContext)
    {
       this.mode = mode;
       this.type = type;
       this.jaxbContext = jaxbContext;
-   }  
+   }
 
    public MessageAbstraction getRequestMessage(Object obj)
    {
@@ -83,18 +91,18 @@
             {
                reqMsg = (SOAPMessageImpl)factory.createMessage();
                SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMsg.getSOAPBody();
-               SOAPContentElement bodyElement = new SOAPBodyElementDoc(new QName("DispatchSOAPBodyElement"));
+               SOAPContentElement bodyElement = new SOAPBodyElementDoc(SOAPBodyElementDoc.GENERIC_PARAM_NAME);
                bodyElement = (SOAPContentElement)soapBody.addChildElement(bodyElement);
                XMLFragment xmlFragment = new XMLFragment(source);
                bodyElement.setXMLFragment(xmlFragment);
 
                // validate payload if necessary
-               if(validateDispatch)
+               if (validateDispatch)
                {
                   // expand to DOM will validate the contents
-                  xmlFragment.toElement();                      
+                  xmlFragment.toElement();
                }
-               
+
             }
             if (mode == Mode.MESSAGE)
             {
@@ -113,7 +121,7 @@
 
             reqMsg = (SOAPMessageImpl)factory.createMessage();
             SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMsg.getSOAPBody();
-            SOAPContentElement bodyElement = new SOAPBodyElementDoc(new QName("DispatchSOAPBodyElement"));
+            SOAPContentElement bodyElement = new SOAPBodyElementDoc(SOAPBodyElementDoc.GENERIC_PARAM_NAME);
             bodyElement = (SOAPContentElement)soapBody.addChildElement(bodyElement);
             StreamSource source = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
             bodyElement.setXMLFragment(new XMLFragment(source));
@@ -137,7 +145,7 @@
    public Object getReturnObject(MessageAbstraction message)
    {
       SOAPMessage resMsg = (SOAPMessage)message;
-      
+
       Object retObj = null;
       try
       {

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-11 12:39:55 UTC (rev 2793)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-04-11 13:00:35 UTC (rev 2794)
@@ -74,6 +74,9 @@
    // provide logging
    private static Logger log = Logger.getLogger(SOAPContentElement.class);
 
+   public static final QName GENERIC_PARAM_NAME = new QName("genericParam");
+   public static final QName GENERIC_RETURN_NAME = new QName("genericReturn");
+   
    // The associated parameter
    private ParameterMetaData paramMetaData;
 
@@ -83,9 +86,6 @@
    // while transitioning DOM expansion needs to be locked
    private boolean lockDOMExpansion = false;
 
-   public static final QName PROVIDER_RETURN_VALUE_NAME = new QName("invokeReturn");
-   public static final QName PROVIDER_PARAM_NAME = new QName("invokeParam");
-
    /** Construct a SOAPContentElement
     */
    public SOAPContentElement(Name name)

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java	2007-04-11 12:39:55 UTC (rev 2793)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java	2007-04-11 13:00:35 UTC (rev 2794)
@@ -23,6 +23,21 @@
 
 // $Id: $
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.xml.namespace.QName;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.transform.Source;
+
 import org.jboss.logging.Logger;
 import org.jboss.ws.Constants;
 import org.jboss.ws.WSException;
@@ -43,20 +58,6 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.xml.namespace.QName;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.transform.Source;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.List;
-
 /**
  * Represents the XML_VALID state of an {@link SOAPContentElement}.<br>
  * Aggregates a {@link XMLFragment}.
@@ -98,7 +99,14 @@
       }
       else if (nextState == State.DOM_VALID)
       {
-         expandContainerChildren();
+         try
+         {
+            expandContainerChildren();
+         }
+         catch (SOAPException ex)
+         {
+            throw new WSException("Cannot expand container children", ex);
+         }
          next = new DOMContent(container);
       }
       else
@@ -138,7 +146,7 @@
    {
       throw new IllegalStateException("Object value not available");
    }
-   
+
    private Object unmarshallObjectContents()
    {
 
@@ -282,7 +290,7 @@
     * Turn the xml fragment into a DOM repersentation and append
     * all children to the container.
     */
-   private void expandContainerChildren()
+   private void expandContainerChildren() throws SOAPException
    {
       // Do nothing if the source of the XMLFragment is the container itself
       Element domElement = xmlFragment.toElement();
@@ -292,78 +300,58 @@
       String rootLocalName = domElement.getLocalName();
       String rootPrefix = domElement.getPrefix();
       String rootNS = domElement.getNamespaceURI();
-      Name contentRootName = new NameImpl(rootLocalName, rootPrefix, rootNS);
+      NameImpl contentRootName = new NameImpl(rootLocalName, rootPrefix, rootNS);
 
       // Make sure the content root element name matches this element name
       Name name = container.getElementName();
       QName qname = container.getElementQName();
-      boolean artificalElement = (SOAPContentElement.PROVIDER_PARAM_NAME.equals(qname) || SOAPContentElement.PROVIDER_RETURN_VALUE_NAME.equals(qname));
-      
-      if ( !artificalElement && !contentRootName.equals(name) )
+      boolean artificalElement = (SOAPContentElement.GENERIC_PARAM_NAME.equals(qname) || SOAPContentElement.GENERIC_RETURN_NAME.equals(qname));
+
+      if (!artificalElement && !contentRootName.equals(name))
          throw new WSException("Content root name does not match element name: " + contentRootName + " != " + name);
 
       // Remove all child nodes
       container.removeContents();
 
-
-      try
+      // In case of dispatch and provider we use artifical element names
+      // These need to be replaced (costly!)
+      if (artificalElement)
       {
-         // In some cases we are using artifical element names
-         // These need to be replaced (costly!)
-         if(artificalElement)
-         {
-            QName tmp = null;
-            if (rootPrefix != null)
-               tmp = new QName(rootNS, rootLocalName, rootPrefix);
-            else
-               tmp = new QName(rootNS, rootLocalName);
-            container.setElementQNameInternal(tmp);
-         }
+         QName xmlName = contentRootName.toQName();
+         container.setElementQNameInternal(xmlName);
       }
-      catch (SOAPException e)
-      {
-         WSException.rethrow(e);
-      }
 
-
       // Copy attributes
       DOMUtils.copyAttributes(container, domElement);
 
       SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
-      
-      try
+
+      NodeList nlist = domElement.getChildNodes();
+      for (int i = 0; i < nlist.getLength(); i++)
       {
-         NodeList nlist = domElement.getChildNodes();
-         for (int i = 0; i < nlist.getLength(); i++)
+         Node child = nlist.item(i);
+         short childType = child.getNodeType();
+         if (childType == Node.ELEMENT_NODE)
          {
-            Node child = nlist.item(i);
-            short childType = child.getNodeType();
-            if (childType == Node.ELEMENT_NODE)
-            {
-               SOAPElement soapElement = soapFactory.createElement((Element)child);
-               container.addChildElement(soapElement);
-               if (Constants.NAME_XOP_INCLUDE.equals(name) || container.isXOPParameter())
-                  XOPContext.inlineXOPData(soapElement);
-            }
-            else if (childType == Node.TEXT_NODE)
-            {
-               String nodeValue = child.getNodeValue();
-               container.addTextNode(nodeValue);
-            }
-            else if (childType == Node.CDATA_SECTION_NODE)
-            {
-               String nodeValue = child.getNodeValue();
-               container.addTextNode(nodeValue);
-            }
-            else
-            {
-               log.trace("Ignore child type: " + childType);
-            }
+            SOAPElement soapElement = soapFactory.createElement((Element)child);
+            container.addChildElement(soapElement);
+            if (Constants.NAME_XOP_INCLUDE.equals(name) || container.isXOPParameter())
+               XOPContext.inlineXOPData(soapElement);
          }
+         else if (childType == Node.TEXT_NODE)
+         {
+            String nodeValue = child.getNodeValue();
+            container.addTextNode(nodeValue);
+         }
+         else if (childType == Node.CDATA_SECTION_NODE)
+         {
+            String nodeValue = child.getNodeValue();
+            container.addTextNode(nodeValue);
+         }
+         else
+         {
+            log.trace("Ignore child type: " + childType);
+         }
       }
-      catch (SOAPException e)
-      {
-         throw new WSException("Failed to transition to DOM", e);
-      }
    }
 }

Added: trunk/jbossws-core/src/java/org/jboss/ws/core/utils/DocumentBuilderFactoryImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/utils/DocumentBuilderFactoryImpl.java	                        (rev 0)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/utils/DocumentBuilderFactoryImpl.java	2007-04-11 13:00:35 UTC (rev 2794)
@@ -0,0 +1,88 @@
+/*
+ * 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;
+
+// $Id$
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A DocumentBuilderFactory that delegates to Xerces and is namespace aware by default.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 11-Apr-2007
+ */
+public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory
+{
+   private static Logger log = Logger.getLogger(DocumentBuilderFactoryImpl.class);
+
+   public static final String XERCES_DOCUMENT_BUILDER_FACTORY = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl";
+
+   private DocumentBuilderFactory delegate;
+
+   public DocumentBuilderFactoryImpl()
+   {
+      try
+      {
+         ClassLoader classLoader = getClass().getClassLoader();
+         Class clazz = classLoader.loadClass(XERCES_DOCUMENT_BUILDER_FACTORY);
+         delegate = (DocumentBuilderFactory)clazz.newInstance();
+
+         // namespace aware by default
+         delegate.setNamespaceAware(true);
+      }
+      catch (Exception ex)
+      {
+         throw new IllegalStateException("Cannot create delegate document builder factory: " + XERCES_DOCUMENT_BUILDER_FACTORY, ex);
+      }
+   }
+
+   public Object getAttribute(String name) throws IllegalArgumentException
+   {
+      return delegate.getAttribute(name);
+   }
+
+   public boolean getFeature(String name) throws ParserConfigurationException
+   {
+      return delegate.getFeature(name);
+   }
+
+   public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
+   {
+      DocumentBuilder builder = delegate.newDocumentBuilder();
+      return builder;
+   }
+
+   public void setAttribute(String name, Object value) throws IllegalArgumentException
+   {
+      delegate.setAttribute(name, value);
+   }
+
+   public void setFeature(String name, boolean value) throws ParserConfigurationException
+   {
+      delegate.setFeature(name, value);
+   }
+}


Property changes on: trunk/jbossws-core/src/java/org/jboss/ws/core/utils/DocumentBuilderFactoryImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jbossws-commits mailing list