ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r157534 [4/4] - in webservices/axis/trunk/archive/java/scratch/Thilina/MTOM: lib/ src/java/org/apache/axis/impl/ src/java/org/apache/axis/om/impl/ src/java/org/apache/axis/om/impl/llom/ src/java/org/apache/axis/om/impl/llom/builder/ src/java/org/apache/axis/om/impl/llom/exception/ src/java/org/apache/axis/om/impl/llom/mtom/ src/java/org/apache/axis/om/impl/llom/serialize/ src/java/org/apache/axis/om/impl/llom/traverse/ src/test-resources/ src/test/org/apache/axis/om/ src/test/org/apache/axis/om/impl/ src/test/org/apache/axis/om/impl/llom/ src/test/org/apache/axis/om/impl/llom/mtom/
Date Tue, 15 Mar 2005 10:56:40 GMT
Added: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenQNameIterator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenQNameIterator.java?view=auto&rev=157534
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenQNameIterator.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenQNameIterator.java
Tue Mar 15 02:56:31 2005
@@ -0,0 +1,135 @@
+/*
+ * 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.axis.om.impl.llom.traverse;
+
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.impl.llom.OMNamedNodeImpl;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Class OMChildrenQNameIterator
+ */
+public class OMChildrenQNameIterator extends OMChildrenIterator {
+    /**
+     * Field givenQName
+     */
+    private QName givenQName;
+
+    /**
+     * Field needToMoveForward
+     */
+    private boolean needToMoveForward = true;
+
+    /**
+     * Field isMatchingNodeFound
+     */
+    private boolean isMatchingNodeFound = false;
+
+    /**
+     * Constructor OMChildrenQNameIterator
+     *
+     * @param currentChild
+     * @param givenQName
+     */
+    public OMChildrenQNameIterator(OMNode currentChild, QName givenQName) {
+        super(currentChild);
+        this.givenQName = givenQName;
+    }
+
+    /**
+     * Returns <tt>true</tt> if the iteration has more elements. (In other
+     * words, returns <tt>true</tt> if <tt>next</tt> would return
an element
+     * rather than throwing an exception.)
+     *
+     * @return <tt>true</tt> if the iterator has more elements.
+     */
+    public boolean hasNext() {
+        while (needToMoveForward) {
+            if (currentChild != null) {
+
+                // check the current node for the criteria
+                if ((currentChild instanceof OMNamedNodeImpl)
+                        && (isQNamesMatch(
+                                   ((OMNamedNodeImpl) currentChild).getQName(),
+                                   this.givenQName))) {
+                    isMatchingNodeFound = true;
+                    needToMoveForward = false;
+                } else {
+
+                    // get the next named node
+                    currentChild = currentChild.getNextSibling();
+                    isMatchingNodeFound = needToMoveForward = !(currentChild
+                                                                           == null);
+                }
+            } else {
+                needToMoveForward = false;
+            }
+        }
+        return isMatchingNodeFound;
+    }
+
+    /**
+     * Returns the next element in the iteration.
+     *
+     * @return the next element in the iteration.
+     * @throws java.util.NoSuchElementException
+     *          iteration has no more elements.
+     */
+    public Object next() {
+
+        // reset the flags
+        needToMoveForward = true;
+        isMatchingNodeFound = false;
+        nextCalled = true;
+        removeCalled = false;
+        lastChild = currentChild;
+        currentChild = currentChild.getNextSibling();
+        return lastChild;
+    }
+
+    /**
+     * Here I can not use the overriden equals method of QName, as one might want to get
+     * some element just by giving the localname, even though a matching element has a namespace
uri as well.
+     * This will not be supported in the equals method of the QName
+     *
+     * @param elementQName
+     * @param qNameToBeMatched
+     * @return
+     */
+    private boolean isQNamesMatch(QName elementQName, QName qNameToBeMatched) {
+
+        // if no QName was given, that means one needs all
+        if (qNameToBeMatched == null) {
+            return true;
+        }
+
+        // if the given localname is null, whatever value this.qname has, its a match
+        boolean localNameMatch =
+        (qNameToBeMatched.getLocalPart() == null)
+                || (qNameToBeMatched.getLocalPart() == "")
+                || ((elementQName != null)
+                               && elementQName.getLocalPart().equalsIgnoreCase(
+                                       qNameToBeMatched.getLocalPart()));
+        boolean namespaceURIMatch =
+        (qNameToBeMatched.getNamespaceURI() == null)
+                || (qNameToBeMatched.getNamespaceURI() == "")
+                || ((elementQName != null)
+                               && elementQName.getNamespaceURI().equalsIgnoreCase(
+                                       qNameToBeMatched.getNamespaceURI()));
+        return localNameMatch && namespaceURIMatch;
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java?view=auto&rev=157534
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
Tue Mar 15 02:56:31 2005
@@ -0,0 +1,112 @@
+/*
+ * 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.axis.om.impl.llom.traverse;
+
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Class OMChildrenWithSpecificAttributeIterator
+ */
+public class OMChildrenWithSpecificAttributeIterator
+        extends OMChildrenIterator {
+    /**
+     * Field attributeName
+     */
+    private QName attributeName;
+
+    /**
+     * Field attributeValue
+     */
+    private String attributeValue;
+
+    /**
+     * Field detach
+     */
+    private boolean detach;
+
+    /**
+     * Constructor OMChildrenWithSpecificAttributeIterator
+     *
+     * @param currentChild
+     * @param attributeName
+     * @param attributeValue
+     * @param detach
+     */
+    public OMChildrenWithSpecificAttributeIterator(OMNode currentChild,
+                                                   QName attributeName, String attributeValue,
boolean detach) {
+        super(currentChild);
+        this.attributeName = attributeName;
+        this.attributeValue = attributeValue;
+        this.detach = detach;
+    }
+
+    /**
+     * Method hasNext
+     *
+     * @return
+     */
+    public boolean hasNext() {
+
+        // First check whether we have a child, using the super class
+        if (currentChild == null) {
+            return false;
+        }
+        boolean isMatchingNodeFound = false;
+        boolean needToMoveForward = true;
+
+        // now we have a child to check. If its an OMElement and matches the criteria, then
we are done
+        while (needToMoveForward) {
+
+            // check the current node for the criteria
+            if (currentChild instanceof OMElement) {
+                OMAttribute attr =
+                        ((OMElement) currentChild).getAttributeWithQName(
+                        attributeName);
+                if ((attr != null)
+                        && attr.getValue().equalsIgnoreCase(attributeValue)) {
+                    isMatchingNodeFound = true;
+                    needToMoveForward = false;
+                } else {
+                    currentChild = currentChild.getNextSibling();
+                    needToMoveForward = !(currentChild == null);
+                }
+            } else {
+
+                // get the next named node
+                currentChild = currentChild.getNextSibling();
+                needToMoveForward = !(currentChild == null);
+            }
+        }
+        return isMatchingNodeFound;
+    }
+
+    /**
+     * Method next
+     *
+     * @return
+     */
+    public Object next() {
+        Object o = super.next();
+        if ((o != null) && detach) {
+            ((OMElement) o).detach();
+        }
+        return o;
+    }
+}

Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeMTOMOut.txt
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeMTOMOut.txt?view=diff&r1=157533&r2=157534
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeMTOMOut.txt
(original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeMTOMOut.txt
Tue Mar 15 02:56:31 2005
@@ -1,17 +1,17 @@
 MIME-Version: 1.0
 Content-Type: multipart/Related; 
-	boundary="----=_Part_0_5525185.1110549010843"
+	boundary="----=_Part_0_31212095.1110790995812"
 
-------=_Part_0_5525185.1110549010843
+------=_Part_0_31212095.1110790995812
 Content-Type: application/xop+xml
 Content-Transfer-Encoding: 8bit
 Content-ID: <http://example.org/my.hsh>
 
-<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><m:data
xmlns:m="http://www.example.org/stuff"><m:name m:contentType="text/plain"><xop:Include
xmlns:xop="http://www.w3.org/2004/08/xop/Include" href="cid:http://example.org/my.hsh1110549010656"></xop:Include></m:name></m:data></soap:Body></soap:Envelope>
-------=_Part_0_5525185.1110549010843
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><m:data
xmlns:m="http://www.example.org/stuff"><m:name m:contentType="text/plain"><xop:Include
xmlns:xop="http://www.w3.org/2004/08/xop/Include" href="cid:http://example.org/my.hsh1110790995593"></xop:Include></m:name></m:data></soap:Body></soap:Envelope>
+------=_Part_0_31212095.1110790995812
 Content-Type: text/plain; charset=Cp1252
 Content-Transfer-Encoding: binary
-Content-ID: <http://example.org/my.hsh1110549010656>
+Content-ID: <http://example.org/my.hsh1110790995593>
 
 Programming Project
-------=_Part_0_5525185.1110549010843--
+------=_Part_0_31212095.1110790995812--

Added: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/OMTextImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/OMTextImplTest.java?view=auto&rev=157534
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/OMTextImplTest.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/OMTextImplTest.java
Tue Mar 15 02:56:31 2005
@@ -0,0 +1,99 @@
+/*
+ * Created on Mar 14, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.om.impl.llom;
+
+import java.io.*;
+
+import junit.framework.TestCase;
+import org.apache.axis.encoding.*;
+import javax.activation.*;
+import org.apache.axis.om.impl.llom.mtom.*;
+
+/**
+ * @author TGunarathne
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class OMTextImplTest extends TestCase {
+	Object expectedObject;
+	
+	OMTextImpl textNode;
+	
+	String expectedBase64;
+	
+	public static void main(String[] args) {
+		junit.swingui.TestRunner.run(OMTextImplTest.class);
+	}
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		expectedObject = new String("Lanka Software Foundation");
+		ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+		ObjectOutputStream objectOutStream = new ObjectOutputStream(byteStream);
+		objectOutStream.writeObject(expectedObject);
+		expectedBase64 = Base64.encode(byteStream.toByteArray());
+		textNode = new OMTextImpl(expectedBase64, "text/plain");	
+	}
+	
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+	
+	/**
+	 * Constructor for OMTextImplTest.
+	 * @param name
+	 */
+	public OMTextImplTest(String name) {
+		super(name);
+	}
+	
+	public void testBase64Encode() {
+		Object actualObject1;
+		try {
+			byte[] tempa = Base64.decode(expectedBase64);
+			ObjectInputStream objectInStream = new ObjectInputStream(
+					new ByteArrayInputStream(tempa));
+			actualObject1 = objectInStream.readObject();
+			assertEquals("Base64 Encoding Check", expectedObject, actualObject1);
+		} catch (IOException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		} catch (ClassNotFoundException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+	}
+	
+	public void testGetDataHandler() {
+		String actualObject;
+		
+		DataHandler DH = textNode.getDataHandler();
+		
+		ByteArrayDataSource ds = (ByteArrayDataSource) DH.getDataSource();
+		try {
+			InputStream inStream = ds.getInputStream();
+			ObjectInputStream obj = new ObjectInputStream(inStream);
+			
+			actualObject = (String) obj.readObject();
+			
+			assertEquals("OMTextImpl GetDataHandler Check", expectedObject,
+					actualObject);
+		} catch (ClassNotFoundException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+			
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
+}
\ No newline at end of file

Added: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/mtom/MTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/mtom/MTOMTest.java?view=auto&rev=157534
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/mtom/MTOMTest.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/om/impl/llom/mtom/MTOMTest.java
Tue Mar 15 02:56:31 2005
@@ -0,0 +1,171 @@
+/*
+ * Created on Mar 9, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.om.impl.llom.mtom;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+
+import junit.framework.TestCase;
+
+import org.apache.axis.om.OMAttribute;
+import javax.xml.stream.*;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.impl.llom.OMAttributeImpl;
+import org.apache.axis.om.impl.llom.OMElementImpl;
+import org.apache.axis.om.impl.llom.OMNamespaceImpl;
+import org.apache.axis.om.impl.llom.builder.MTOMStAXSOAPModelBuilder;
+import org.apache.axis.om.impl.llom.mtom.MTOMXMLStreamWriter;
+import org.apache.axis.om.impl.llom.mtom.OMBlob;
+import org.apache.axis.om.impl.llom.serialize.SimpleOMSerializer;
+
+/**
+ * @author TGunarathne
+ * 
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Style - Code Templates
+ */
+public class MTOMTest extends TestCase {
+	String expectedObject;
+
+	String outFileName;
+	
+	String outBase64FileName;
+
+	MTOMStAXSOAPModelBuilder builder;
+
+	DataHandler expectedDH;
+
+	public static void main(String[] args) {
+		junit.swingui.TestRunner.run(MTOMTest.class);
+	}
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		outFileName = "mtom/src/test-resources/OMSerializeMTOMOut.txt";
+		outBase64FileName = "mtom/src/test-resources/OMSerializeBase64Out.xml";
+		serializeSetUp();
+		builder = new MTOMStAXSOAPModelBuilder(new FileInputStream(outFileName));
+
+	}
+
+	protected void serializeSetUp() {
+		File outMTOMFile;
+		File outBase64File;
+		
+
+		try {
+
+			outMTOMFile = new File(outFileName);
+			outBase64File = new File(outBase64FileName);
+			MTOMXMLStreamWriter mtomWriter = new MTOMXMLStreamWriter(
+					new FileOutputStream(outMTOMFile));
+			XMLStreamWriter baseWriter =XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(outBase64File));
+			
+			//SimpleOMSerializer mtomSimpleOMSerialiser = new SimpleOMSerializer();
+
+			OMNamespaceImpl soap = new OMNamespaceImpl("http://schemas.xmlsoap.org/soap/envelope/",
"soap");
+			OMElement envelope = new OMElementImpl("Envelope", soap);
+			OMElement body = new OMElementImpl("Body", soap);
+
+			OMNamespaceImpl dataName = new OMNamespaceImpl(
+					"http://www.example.org/stuff", "m");
+			OMElement data = new OMElementImpl("data", dataName);
+
+			OMNamespaceImpl mime = new OMNamespaceImpl(
+					"http://www.w3.org/2003/06/xmlmime", "m");
+
+			OMElement text = new OMElementImpl("name", dataName);
+			OMAttribute cType1 = new OMAttributeImpl("contentType", mime,
+					"text/plain");
+			text.insertAttribute(cType1);
+			expectedObject = new String("Programming Project");
+			expectedDH = new DataHandler(expectedObject, "text/plain");
+			OMBlob textData = new OMBlob(expectedDH);
+
+			envelope.addChild(body);
+			body.addChild(data);
+			data.addChild(text);
+			text.addChild(textData);
+			
+			envelope.serialize(baseWriter,false);
+			baseWriter.flush();
+
+			envelope.serialize(mtomWriter,false);
+			//MTOMser.serialize(Envelope, MTOMWriter);
+			mtomWriter.flush();
+			mtomWriter.complete();
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Constructor for OMBlobTest.
+	 * 
+	 * @param name
+	 */
+	public MTOMTest(String name) {
+		super(name);
+	}
+
+	public void testGetDataHandler() {
+		try {
+			OMElement root = (OMElement) builder.getDocumentElement();
+			System.out.println(root.getLocalName() + " : "
+					+ root.getNamespaceName());
+			OMElement body = (OMElement) root.getFirstChild();
+			System.out.println(body.getLocalName() + " : "
+					+ body.getNamespaceName());
+			OMElement data = (OMElement) body.getFirstChild();
+			System.out.println(data.getLocalName() + " : "
+					+ data.getNamespaceName());
+			Iterator childIt = data.getChildren();
+			//while (childIt.hasNext()) {
+			OMElement child = (OMElement) childIt.next();
+			OMBlob blob = (OMBlob) child.getFirstChild();
+			/*
+			 * Following is the procedure the user has to follow to read objects
+			 * in OBBlob User has to know the object type & whether it is
+			 * serializable. If it is not he has to use a Custom Defined
+			 * DataSource to get the Object.
+			 */
+
+			DataHandler actualDH;
+			actualDH = blob.getDataHandler();
+			//assertEquals("DataHandler
+			// check",expectedDH.getContent(),(actualDH =
+			// blob.getDataHandler()).getContent());
+			Object actualObject = actualDH.getContent(); //This returns a
+														 // String cause string
+														 // is serializable
+			assertEquals("Object check", expectedObject, (String) actualObject);
+
+			System.out.println(child.getLocalName() + ":-\t" + actualObject);
+
+			//}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+}
\ No newline at end of file



Mime
View raw message