You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by th...@apache.org on 2006/10/06 12:20:57 UTC

svn commit: r453543 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-api/src/main/java/org/apache/axiom/om/impl/mtom/ axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/ axio...

Author: thilina
Date: Fri Oct  6 03:20:54 2006
New Revision: 453543

URL: http://svn.apache.org/viewvc?view=rev&rev=453543
Log:
1. Moving the MTOMBuilder to correct package
2. Creating a XML level XOP builder to handle non mtom XOP optimised documents : Fixing http://issues.apache.org/jira/browse/WSCOMMONS-85
3. Fixing the http://issues.apache.org/jira/browse/WSCOMMONS-107

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
      - copied, changed from r452761, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilder.java
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/mtom/
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/ImageSampleTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java?view=auto&rev=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java Fri Oct  6 03:20:54 2006
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axiom.om.impl.builder;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.MTOMConstants;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.util.ElementHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import sun.misc.GC.LatencyRequest;
+
+public class XOPAwareStAXOMBuilder extends StAXOMBuilder {
+
+	/**
+	 * <code>Attachments</code> handles deferred parsing of incoming MIME
+	 * Messages.
+	 */
+	Attachments attachments;
+
+	/**
+	 * Constructor StAXOMBuilder.
+	 * 
+	 * @param ombuilderFactory
+	 * @param parser
+	 */
+	public XOPAwareStAXOMBuilder(OMFactory ombuilderFactory,
+			XMLStreamReader parser, Attachments attachments) {
+		super(ombuilderFactory, parser);
+		this.attachments = attachments;
+	}
+
+	/**
+	 * Constructor linked to existing element.
+	 * 
+	 * @param factory
+	 * @param parser
+	 * @param element
+	 */
+	public XOPAwareStAXOMBuilder(OMFactory factory, XMLStreamReader parser,
+			OMElement element,Attachments attachments) {
+		super(factory, parser, element);
+		this.attachments = attachments;
+	}
+
+	/**
+	 * @param filePath -
+	 *            Path to the XML file
+	 * @throws XMLStreamException
+	 * @throws FileNotFoundException
+	 */
+	public XOPAwareStAXOMBuilder(String filePath,Attachments attachments) throws XMLStreamException,
+			FileNotFoundException {
+		super(filePath);
+		this.attachments = attachments;
+	}
+
+	/**
+	 * @param inStream -
+	 *            instream which contains the XML
+	 * @throws XMLStreamException
+	 */
+	public XOPAwareStAXOMBuilder(InputStream inStream,Attachments attachments)
+			throws XMLStreamException {
+		super(inStream);
+		this.attachments = attachments;
+	}
+
+	/**
+	 * Constructor StAXXOPAwareOMBuilder.
+	 * 
+	 * @param parser
+	 */
+	public XOPAwareStAXOMBuilder(XMLStreamReader parser,Attachments attachments) {
+		super(parser);
+		this.attachments = attachments;
+	}
+
+	/**
+	 * Method createOMElement. Overriding the createOMElement of StAXOMBuilder
+	 * to to XOP aware building
+	 * 
+	 * @return Returns OMNode.
+	 * @throws OMException
+	 */
+	protected OMNode createOMElement() throws OMException {
+
+		String elementName = parser.getLocalName();
+		String namespaceURI = parser.getNamespaceURI();
+		if (MTOMConstants.XOP_INCLUDE.equalsIgnoreCase(elementName)
+				&& MTOMConstants.XOP_NAMESPACE_URI
+						.equalsIgnoreCase(namespaceURI)) {
+			OMText node;
+			String contentID = ElementHelper.getContentID(parser, getDocument()
+					.getCharsetEncoding());
+
+			if (lastNode == null) {
+				throw new OMException(
+						"XOP:Include element is not supported here");
+			} else if (lastNode.isComplete() & lastNode.getParent() != null) {
+				node = omfactory.createOMText(contentID, (OMElement) lastNode
+						.getParent(), this);
+				((OMNodeEx) lastNode).setNextOMSibling(node);
+				((OMNodeEx) node).setPreviousOMSibling(lastNode);
+			} else {
+				OMElement e = (OMElement) lastNode;
+				node = omfactory.createOMText(contentID, (OMElement) lastNode,this);
+				e.setFirstChild(node);
+			}
+			return node;
+		} else {
+			return super.createOMElement();
+		}
+	}
+	
+	public DataHandler getDataHandler(String blobContentID) throws OMException {
+		return attachments.getDataHandler(blobContentID);
+	}
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java (from r452761, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java?view=diff&rev=453543&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilder.java&r1=452761&p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java&r2=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java Fri Oct  6 03:20:54 2006
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.apache.axiom.om.impl.mtom;
+package org.apache.axiom.soap.impl.builder;
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMElement;
@@ -25,113 +25,84 @@
 import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 
-public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder implements MTOMConstants {
-	
-    /**
-     * <code>Attachments</code> handles deferred parsing of incoming MIME
-     * Messages.
-     */
-    Attachments attachments;
-
-    int partIndex = 0;
-
-    public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,
-                                    SOAPFactory factory,
-                                    Attachments attachments, String soapVersion) {
-        super(parser, factory, soapVersion);
-        this.attachments = attachments;
-    }
-
-    /**
-     * @param reader
-     * @param attachments
-     */
-    public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
-                                    Attachments attachments, String soapVersion) {
-        super(reader, soapVersion);
-        this.attachments = attachments;
-    }
-
-    protected OMNode createOMElement() throws OMException {
-
-        elementLevel++;
-        String elementName = parser.getLocalName();
-
-        String namespaceURI = parser.getNamespaceURI();
-
-        // create an OMBlob if the element is an <xop:Include>
-
-        if (XOP_INCLUDE.equalsIgnoreCase(elementName)
-                && XOP_NAMESPACE_URI
-                .equalsIgnoreCase(namespaceURI)) {
-            // do we need to check prfix as well. Meaning, should it be "XOP" ?
-
-
-            OMText node;
-            if (lastNode == null) {
-                // Decide whether to ckeck the level >3 or not
-                throw new OMException(
-                        "XOP:Include element is not supported here");
-            }
-            
-            String contentID = ElementHelper.getContentID(parser, getDocument().getCharsetEncoding());
-
-            // This cannot happen. XOP:Include is always the only child of an parent element
-            // cause it is same as having some text
-            try {
-                OMElement e = (OMElement) lastNode;
-                //node = new OMTextImpl(contentID, (OMElement) lastNode, this);
-                node = this.omfactory.createOMText(contentID, (OMElement) lastNode, this);
-                e.setFirstChild(node);
-            } catch (ClassCastException e) {
-                throw new OMException(
-                        "Last Node & Parent of an OMText should be an Element" +
-                                e);
-            }
-
-            return node;
-
-        } else {
-            OMElement node;
-            if (lastNode == null) {
-                node = constructNode(null, elementName, true);
-                setSOAPEnvelope(node);
-            } else if (lastNode.isComplete()) {
-                node =
-                        constructNode((OMElement) lastNode.getParent(),
-                                elementName,
-                                false);
-                ((OMNodeEx)lastNode).setNextOMSibling(node);
-                ((OMNodeEx)node).setPreviousOMSibling(lastNode);
-            } else {
-                OMElement e = (OMElement) lastNode;
-                node = constructNode((OMElement) lastNode, elementName, false);
-                e.setFirstChild(node);
-            }
-
-            
-            // This code seems suspicious.  The constructNode call
-            // does the attribute processing.  The parser is now at a different node,
-            // and thus processAttributes will either throw an exception or get the
-            // wrong attributes. (scheu)
-            
-            // fill in the attributes
-            processAttributes(node);
-            //TODO Exception when trying to log . check this
-            //			log.info("Build the OMElelment {" + node.getLocalName() + '}'
-            //					+ node.getLocalName() + "By the StaxSOAPModelBuilder");
-            return node;
-        }
-    }
-
-    public DataHandler getDataHandler(String blobContentID) throws OMException {
-        return attachments.getDataHandler(blobContentID);
-    }
+public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder implements
+		MTOMConstants {
+
+	/**
+	 * <code>Attachments</code> handles deferred parsing of incoming MIME
+	 * Messages.
+	 */
+	Attachments attachments;
+
+	private Log log = LogFactory.getLog(getClass());
+
+	int partIndex = 0;
+
+	public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,
+			SOAPFactory factory, Attachments attachments, String soapVersion) {
+		super(parser, factory, soapVersion);
+		this.attachments = attachments;
+	}
+
+	/**
+	 * @param reader
+	 * @param attachments
+	 */
+	public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
+			Attachments attachments, String soapVersion) {
+		super(reader, soapVersion);
+		this.attachments = attachments;
+	}
+
+	protected OMNode createOMElement() throws OMException {
+
+		String elementName = parser.getLocalName();
+		String namespaceURI = parser.getNamespaceURI();
+
+		// create an OMBlob if the element is an <xop:Include>
+		if (XOP_INCLUDE.equalsIgnoreCase(elementName)
+				&& XOP_NAMESPACE_URI.equalsIgnoreCase(namespaceURI)) {
+			elementLevel++;
+			OMText node;
+			String contentID = ElementHelper.getContentID(parser, getDocument()
+					.getCharsetEncoding());
+
+			if (lastNode == null) {
+				throw new OMException(
+						"XOP:Include element is not supported here");
+			} else if (lastNode.isComplete() & lastNode.getParent() != null) {
+				node = omfactory.createOMText(contentID, (OMElement) lastNode
+						.getParent(), this);
+				((OMNodeEx) lastNode).setNextOMSibling(node);
+				((OMNodeEx) node).setPreviousOMSibling(lastNode);
+			} else {
+				OMElement e = (OMElement) lastNode;
+				node = omfactory.createOMText(contentID, (OMElement) lastNode,
+						this);
+				e.setFirstChild(node);
+			}
+			return node;
+
+		} else {
+			return super.createOMElement();
+		}
+	}
+
+	public DataHandler getDataHandler(String blobContentID) throws OMException {
+		DataHandler dataHandler = attachments.getDataHandler(blobContentID);
+		if (dataHandler == null) {
+			throw new OMException(
+					"Referenced Attachment not found in the MIME Message. ContentID:"
+							+ blobContentID);
+		}
+		return dataHandler;
+	}
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java?view=diff&rev=453543&r1=453542&r2=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java Fri Oct  6 03:20:54 2006
@@ -171,8 +171,7 @@
             node = constructNode(null, elementName, true);
             setSOAPEnvelope(node);
         } else if (lastNode.isComplete()) {
-            node =
-                    constructNode((OMElement) lastNode.getParent(),
+            node =constructNode((OMElement) lastNode.getParent(),
                             elementName,
                             false);
             ((OMNodeEx) lastNode).setNextOMSibling(node);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java?view=diff&rev=453543&r1=453542&r2=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java Fri Oct  6 03:20:54 2006
@@ -19,9 +19,9 @@
 import org.apache.axiom.om.*;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.OMNamespaceImpl;
-import org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Node;
 import org.w3c.dom.Text;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?view=diff&rev=453543&r1=453542&r2=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java Fri Oct  6 03:20:54 2006
@@ -20,10 +20,10 @@
 import org.apache.axiom.om.*;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.OMNamespaceImpl;
-import org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/ImageSampleTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/ImageSampleTest.java?view=diff&rev=453543&r1=453542&r2=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/ImageSampleTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/ImageSampleTest.java Fri Oct  6 03:20:54 2006
@@ -45,7 +45,7 @@
 import org.apache.axiom.om.impl.OMNamespaceImpl;
 import org.apache.axiom.om.impl.llom.OMElementImpl;
 import org.apache.axiom.om.impl.llom.OMTextImpl;
-import org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 
 public class ImageSampleTest extends AbstractTestCase {
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java?view=diff&rev=453543&r1=453542&r2=453543
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java Fri Oct  6 03:20:54 2006
@@ -22,6 +22,7 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLInputFactory;
@@ -61,17 +62,10 @@
 
     public void testCreateOMElement() throws Exception {
         OMElement root = builder.getDocumentElement();
-//        System.out.println(root.getLocalName() + " : "
-//                + root.getNamespace().getName());
         OMElement body = (OMElement) root.getFirstOMChild();
-//        System.out.println(body.getLocalName() + " : "
-//                + body.getNamespace().getName());
-
         OMElement data = (OMElement) body.getFirstOMChild();
-//        System.out.println(data.getLocalName() + " : "
-//                + data.getNamespace().getName());
+
         Iterator childIt = data.getChildren();
-        //while (childIt.hasNext()) {
         OMElement child = (OMElement) childIt.next();
         OMText blob = (OMText) child.getFirstOMChild();
         /*



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org