You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2005/03/14 06:53:09 UTC
svn commit: r157393 [3/3] - in
webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src:
java/org/apache/axis/impl/llom/ java/org/apache/axis/impl/llom/builder/
java/org/apache/axis/impl/llom/exception/
java/org/apache/axis/impl/llom/factory/ java/org/apache/axis/impl/llom/mtom/
java/org/apache/axis/impl/llom/serialize/
java/org/apache/axis/impl/llom/traverse/ test-resources/
test/org/apache/axis/mtom/
Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java?view=diff&r1=157392&r2=157393
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/StreamingOMSerializer.java Sun Mar 13 21:53:01 2005
@@ -1,150 +0,0 @@
-package org.apache.axis.impl.llom.serialize;
-
-import java.util.Vector;
-
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-
-/**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- */
-public class StreamingOMSerializer implements XMLStreamConstants {
-
- private Vector prefixList = new Vector();
-
- public void serialize(Object obj, XMLStreamWriter writer) throws XMLStreamException {
-
- if (!(obj instanceof XMLStreamReader)) {
- throw new UnsupportedOperationException("Unsupported input object. Must be of the the type XMLStreamReader");
- }
-
- XMLStreamReader node = (XMLStreamReader) obj;
- serializeNode(node, writer);
- }
-
- protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- while (reader.hasNext()) {
- int event = reader.next();
- if (event == START_ELEMENT) {
- serializeElement(reader, writer);
- } else if (event == ATTRIBUTE) {
- serializeAttributes(reader, writer);
- } else if (event == CHARACTERS) {
- serializeText(reader, writer);
- } else if (event == COMMENT) {
- serializeComment(reader, writer);
- } else if (event == CDATA) {
- serializeCData(reader, writer);
- } else if (event == END_ELEMENT) {
- serializeEndElement(writer);
- }
- writer.flush();
- }
- }
-
- /**
-
- */
- protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
-
- String prefix = reader.getPrefix();
- String nameSpaceName = reader.getNamespaceURI();
- if (prefix != null) {
- writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
- //add the own namespace
- if (!prefixList.contains(prefix)) {
- writer.writeNamespace(prefix, nameSpaceName);
- prefixList.add(prefix);
- }
- } else {
- writer.writeStartElement(nameSpaceName, reader.getLocalName());
- //add the own namespace
- writer.writeDefaultNamespace(nameSpaceName);
-
- }
-
-
-
- //add attributes
- serializeAttributes(reader, writer);
- //add the namespaces
- serializeNamespaces(reader, writer);
-
-
- }
-
- protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
- writer.writeEndElement();
- }
-
- /**
- */
- protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- writer.writeCharacters(reader.getText());
- }
-
- protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- writer.writeCData(reader.getText());
- }
-
-
- protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- writer.writeComment(reader.getText());
- }
-
- /**
- * @param writer
- * @throws XMLStreamException
- */
-
-
- protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
-
- int count = reader.getAttributeCount();
- String prefix = null;
- String namespaceName = null;
- for (int i = 0; i < count; i++) {
- prefix = reader.getAttributePrefix(i);
- namespaceName = reader.getAttributeNamespace(i);
- if (prefix != null && !namespaceName.equals("")) {
- writer.writeAttribute(prefix,
- namespaceName,
- reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- } else {
- writer.writeAttribute(reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- }
- }
- }
-
-
- protected void serializeNamespaces(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- int count = reader.getNamespaceCount();
- String namespacePrefix;
- for (int i = 0; i < count; i++) {
- namespacePrefix = reader.getNamespacePrefix(i);
- if (!prefixList.contains(namespacePrefix)) {
- writer.writeNamespace(namespacePrefix, reader.getNamespaceURI(i));
- prefixList.add(namespacePrefix);
- }
- }
-
- }
-
-}
Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/XMLSerilazer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/XMLSerilazer.java?view=diff&r1=157392&r2=157393
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/XMLSerilazer.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/serialize/XMLSerilazer.java Sun Mar 13 21:53:01 2005
@@ -1,145 +0,0 @@
-package org.apache.axis.impl.llom.serialize;
-
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axis.om.OMElement;
-import org.apache.axis.om.StreamingWrapper;
-
-/**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
- * User: Eran Chinthaka - Lanka Software Foundation Date: Nov 18, 2004 Time:
- * 11:29:48 AM
- */
-public class XMLSerilazer {
- private static StringBuffer b;
- private StreamingWrapper streamingWrapper;
- private OMElement startingElement;
-
- public XMLSerilazer(StreamingWrapper streamingWrapper) {
- this.streamingWrapper = streamingWrapper;
-
- }
-
- public StringBuffer serialize(OMElement element) {
-
- return b;
- }
-
-
- public static String printEvent(StreamingWrapper streamingWrapper) {
-
- switch (streamingWrapper.getEventType()) {
- case XMLStreamReader.START_ELEMENT:
- b.append("<");
- printName(streamingWrapper, b);
- for (int i = 0; i < streamingWrapper.getNamespaceCount(); i++) {
- b.append(" ");
- String n = streamingWrapper.getNamespacePrefix(i);
- if ("xmlns".equals(n)) {
- b.append("xmlns=\"" + streamingWrapper.getNamespaceURI(i) + "\"");
- } else {
- b.append("xmlns:" + n);
- b.append("=\"");
- b.append(streamingWrapper.getNamespaceURI(i));
- b.append("\"");
- }
- }
-
- for (int i = 0; i < streamingWrapper.getAttributeCount(); i++) {
- b.append(" ");
- printName(streamingWrapper.getAttributePrefix(i),
- streamingWrapper.getAttributeNamespace(i),
- streamingWrapper.getAttributeLocalName(i),
- b);
- b.append("=\"");
- b.append(streamingWrapper.getAttributeValue(i));
- b.append("\"");
- }
-
- b.append(">");
- break;
- case XMLStreamReader.END_ELEMENT:
- b.append("</");
- printName(streamingWrapper, b);
- for (int i = 0; i < streamingWrapper.getNamespaceCount(); i++) {
- b.append(" ");
- String n = streamingWrapper.getNamespacePrefix(i);
- if ("xmlns".equals(n)) {
- b.append("xmlns=\"" + streamingWrapper.getNamespaceURI(i) + "\"");
- } else {
- b.append("xmlns:" + n);
- b.append("=\"");
- b.append(streamingWrapper.getNamespaceURI(i));
- b.append("\"");
- }
- }
- b.append(">");
- break;
- case XMLStreamReader.SPACE:
- case XMLStreamReader.CHARACTERS:
- int start = streamingWrapper.getTextStart();
- int length = streamingWrapper.getTextLength();
- b.append(new String(streamingWrapper.getTextCharacters(),
- start,
- length));
- break;
- case XMLStreamReader.CDATA:
- b.append("<![CDATA[");
- if (streamingWrapper.hasText())
- b.append(streamingWrapper.getText());
- b.append("]]>");
- break;
-
- case XMLStreamReader.COMMENT:
- b.append("<!--");
- if (streamingWrapper.hasText())
- b.append(streamingWrapper.getText());
- b.append("-->");
- break;
- case XMLStreamReader.START_DOCUMENT:
-// b.append("<?xml");
-// b.append(" version='" + streamingWrapper.getVersion() + "'");
-// b.append(" encoding='" + streamingWrapper.getCharacterEncodingScheme() + "'");
-// if (streamingWrapper.isStandalone())
-// b.append(" standalone='yes'");
-// else
-// b.append(" standalone='no'");
-// b.append("?>");
- break;
-
- }
- return b.toString();
- }
-
- private static void printName(String prefix,
- String uri,
- String localName,
- StringBuffer b) {
- if (uri != null && !("".equals(uri))) b.append("['" + uri + "']:");
- if (prefix != null && !("".equals(prefix))) b.append(prefix + ":");
- if (localName != null) b.append(localName);
- }
-
- private static void printName(StreamingWrapper streamingWrapper, StringBuffer b) {
- if (streamingWrapper.hasName()) {
- String prefix = streamingWrapper.getPrefix();
- String uri = streamingWrapper.getNamespaceURI();
- String localName = streamingWrapper.getLocalName();
- printName(prefix, uri, localName, b);
- }
- }
-
-}
Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenIterator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenIterator.java?view=diff&r1=157392&r2=157393
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenIterator.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenIterator.java Sun Mar 13 21:53:01 2005
@@ -1,98 +0,0 @@
-package org.apache.axis.impl.llom.traverse;
-
-import java.util.Iterator;
-
-import org.apache.axis.om.OMException;
-import org.apache.axis.om.OMNode;
-
-/**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
- */
-public class OMChildrenIterator implements Iterator {
-
- protected OMNode currentChild;
- protected OMNode lastChild;
- protected boolean nextCalled = false;
- protected boolean removeCalled = false;
-
-
- public OMChildrenIterator(OMNode currentChild) {
- this.currentChild = currentChild;
- }
-
- /**
- * Removes from the underlying collection the last element returned by the
- * iterator (optional operation). This method can be called only once per
- * call to <tt>next</tt>. The behavior of an iterator is unspecified if the
- * underlying collection is modified while the iteration is in progress in
- * any way other than by calling this method.
- *
- * @throws UnsupportedOperationException if the <tt>remove</tt> operation is
- * not supported by this Iterator.
- * @throws IllegalStateException if the <tt>next</tt> method has not
- * yet been called, or the <tt>remove</tt>
- * method has already been called
- * after the last call to the
- * <tt>next</tt> method.
- */
- public void remove() {
-
- if (!nextCalled) {
- throw new IllegalStateException("next method has not yet being called");
- }
- if (removeCalled) {
- throw new IllegalStateException("remove has already being called");
- }
-
- removeCalled = true;
-
- //since this acts on the last child there is no need to mess with the current child
- if (lastChild == null) {
- throw new OMException("cannot remove a child at this stage!");
- }
- lastChild.detach();
- }
-
- /**
- * 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() {
- return (currentChild != null);
- }
-
- /**
- * 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() {
- nextCalled = true;
- removeCalled = false;
- if (hasNext()) {
- lastChild = currentChild;
- currentChild = currentChild.getNextSibling();
- return lastChild;
- }
- return null;
-
- }
-}
Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenQNameIterator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenQNameIterator.java?view=diff&r1=157392&r2=157393
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenQNameIterator.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/java/org/apache/axis/impl/llom/traverse/OMChildrenQNameIterator.java Sun Mar 13 21:53:01 2005
@@ -1,115 +0,0 @@
-package org.apache.axis.impl.llom.traverse;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axis.impl.llom.OMNamedNodeImpl;
-import org.apache.axis.om.OMNode;
-
-/**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
- */
-public class OMChildrenQNameIterator extends OMChildrenIterator {
-
-
- private QName givenQName;
-
- private boolean needToMoveForward = true;
- private boolean isMatchingNodeFound = false;
-
- 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;
-
-
- }
-
-
-}
Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeBase64Out.txt
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeBase64Out.txt?view=diff&r1=157392&r2=157393
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeBase64Out.txt (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test-resources/OMSerializeBase64Out.txt Sun Mar 13 21:53:01 2005
@@ -1 +0,0 @@
-<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><m:data xmlns:m="http://www.example.org/stuff"><m:value>rO0ABXNyAA9qYXZhLmxhbmcuRmxvYXTa7cmi2zzw7AIAAUYABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwP7pRGg==</m:value><m:sig m:contentType="application/pkcs7-signature">rO0ABXQAE1Byb2dyYW1taW5nIFByb2plY3Q=</m:sig><m:photo m:contentType="image/png">rO0ABXVyAAJbQqzzF/gGCFTgAgAAeHAAAAAGaWKKapGG</m:photo></m:data></soap:Body></soap:Envelope>
\ No newline at end of file
Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/mtom/MTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/mtom/MTOMTest.java?view=diff&r1=157392&r2=157393
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/mtom/MTOMTest.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM/src/test/org/apache/axis/mtom/MTOMTest.java Sun Mar 13 21:53:01 2005
@@ -1,160 +0,0 @@
-/*
- * 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.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.impl.llom.OMAttributeImpl;
-import org.apache.axis.impl.llom.OMElementImpl;
-import org.apache.axis.impl.llom.OMNamespaceImpl;
-import org.apache.axis.impl.llom.builder.StAXOMBuilder;
-import org.apache.axis.impl.llom.mtom.MTOMXMLStreamWriter;
-import org.apache.axis.impl.llom.mtom.OMBlob;
-import org.apache.axis.impl.llom.serialize.SimpleOMSerializer;
-import org.apache.axis.om.OMAttribute;
-import org.apache.axis.om.OMElement;
-
-/**
- * @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;
-
- StAXOMBuilder 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";
- serializeSetUp();
- builder = new StAXOMBuilder(new FileInputStream(outFileName));
-
- }
-
- protected void serializeSetUp() {
- File outMTOMFile;
-
- try {
-
- outMTOMFile = new File(outFileName);
- MTOMXMLStreamWriter MTOMWriter = new MTOMXMLStreamWriter(
- new FileOutputStream(outMTOMFile));
-
- SimpleOMSerializer MTOMser = new SimpleOMSerializer();
-
- OMNamespaceImpl soap = new OMNamespaceImpl(
- "http://www.w3.org/2003/05/soap-envelope", "soap");
- OMElement Envelope = new OMElementImpl("Envelope", soap);
- OMElement Body = new OMElementImpl("Body", soap);
-
- OMNamespaceImpl m = new OMNamespaceImpl(
- "http://www.example.org/stuff", "m");
- OMElement data = new OMElementImpl("data", m);
-
- OMNamespaceImpl mime = new OMNamespaceImpl(
- "http://www.w3.org/2003/06/xmlmime", "m");
-
- OMElement text = new OMElementImpl("name", m);
- 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);
-
- 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