axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ami...@apache.org
Subject svn commit: r559350 - in /webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding: ./ utils/writer/
Date Wed, 25 Jul 2007 08:25:37 GMT
Author: amilas
Date: Wed Jul 25 01:25:36 2007
New Revision: 559350

URL: http://svn.apache.org/viewvc?view=rev&rev=559350
Log:
set a new MTOM aware writer to serialize adb beans

Added:
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLSerializer.java
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLStreamWriter.java
Modified:
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java?view=diff&rev=559350&r1=559349&r2=559350
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBDataSource.java
Wed Jul 25 01:25:36 2007
@@ -22,6 +22,9 @@
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axis2.databinding.utils.writer.OMElementStreamWriter;
+import org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter;
+import org.apache.axis2.databinding.utils.writer.MTOMAwareXMLSerializer;
+import org.apache.axis2.databinding.utils.writer.MTOMAwareOMBuilder;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -74,8 +77,12 @@
      * @throws XMLStreamException
      * @see OMDataSource#serialize(javax.xml.stream.XMLStreamWriter)
      */
-    public abstract void serialize(XMLStreamWriter xmlWriter)
-            throws XMLStreamException;
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException{
+        MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new MTOMAwareXMLSerializer(xmlWriter);
+        serialize(mtomAwareXMLStreamWriter);
+    }
+
+    public abstract void serialize(MTOMAwareXMLStreamWriter xmlWriter) throws XMLStreamException;
 
 
     /**
@@ -85,9 +92,9 @@
     public XMLStreamReader getReader() throws XMLStreamException {
         // since only ADBBeans related to elements can be serialized
         // we are safe in passing null here.
-        OMElementStreamWriter omElementStreamWriter = new OMElementStreamWriter();
-        serialize(omElementStreamWriter);
-        return omElementStreamWriter.getOMElement().getXMLStreamReader();
+        MTOMAwareOMBuilder mtomAwareOMBuilder = new MTOMAwareOMBuilder();
+        serialize(mtomAwareOMBuilder);
+        return mtomAwareOMBuilder.getOMElement().getXMLStreamReader();
     }
 
 }

Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java?view=auto&rev=559350
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
(added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
Wed Jul 25 01:25:36 2007
@@ -0,0 +1,240 @@
+/*
+ * 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.axis2.databinding.utils.writer;
+
+import org.apache.axiom.om.*;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.namespace.NamespaceContext;
+import javax.activation.DataHandler;
+import java.util.Stack;
+import java.util.Map;
+import java.util.HashMap;
+
+
+public class MTOMAwareOMBuilder implements MTOMAwareXMLStreamWriter {
+    // this is the om Element we are going to create
+    private OMElement rootElement;
+    private OMFactory omFactory;
+
+    private OMElement currentOMElement;
+
+    private Stack omElementStack;
+
+    // this map contains the namespace key and OMNamespace
+    private Map namespaceOMNamesapceMap;
+
+    private int prefixNum;
+
+    private OMStreamNamespaceContext omStreamNamespaceContext;
+
+
+    public MTOMAwareOMBuilder() {
+        omFactory = OMAbstractFactory.getOMFactory();
+        omElementStack = new Stack();
+        currentOMElement = null;
+        omStreamNamespaceContext = new OMStreamNamespaceContext();
+        namespaceOMNamesapceMap = new HashMap();
+        prefixNum = 0;
+
+    }
+
+    // serailizer must have finish serializing when we call this method.
+    public OMElement getOMElement() throws XMLStreamException {
+        if (!omElementStack.isEmpty()) {
+            throw new XMLStreamException("This is an invalid Xml ");
+        }
+        return rootElement;
+    }
+
+    private OMNamespace getOMNamespace(String namespace, String prefix) throws XMLStreamException
{
+        OMNamespace omNamespace = null;
+        if (namespace != null) {
+            if (namespaceOMNamesapceMap.containsKey(namespace)) {
+                omNamespace = (OMNamespace) namespaceOMNamesapceMap.get(namespace);
+            } else {
+                if (prefix == null) {
+                    prefix = "ns" + ++prefixNum;
+                } else if (this.omStreamNamespaceContext.getNamespaceURI(prefix) != null)
{
+                    throw new XMLStreamException("the prefix ==> " + prefix +
+                            " Already exists for namespace ==> " + namespace);
+                }
+                omNamespace = omFactory.createOMNamespace(namespace, prefix);
+                this.omStreamNamespaceContext.registerNamespace(namespace, prefix);
+                namespaceOMNamesapceMap.put(namespace, omNamespace);
+            }
+        }
+        return omNamespace;
+    }
+
+    public void writeStartElement(String localName) throws XMLStreamException {
+        writeStartElement(null, localName, null);
+    }
+
+    public void writeStartElement(String namespace, String localName) throws XMLStreamException
{
+        writeStartElement(null, localName, namespace);
+    }
+
+    public void writeStartElement(String prefix, String localName, String namespace) throws
XMLStreamException {
+        OMNamespace omNamespace = getOMNamespace(namespace, prefix);
+        currentOMElement = omFactory.createOMElement(localName, omNamespace);
+        if (!omElementStack.isEmpty()) {
+            // we always keep the parent at the top of the stack
+            OMElement parent = (OMElement) omElementStack.peek();
+            parent.addChild(currentOMElement);
+        } else {
+            // i.e this must be an start root element
+            rootElement = currentOMElement;
+        }
+        // set this as the top element
+        omElementStack.push(currentOMElement);
+    }
+
+    public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException
{
+        writeEmptyElement(null, localName, namespaceURI);
+    }
+
+    public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws
XMLStreamException {
+        writeStartElement(prefix, localName, namespaceURI);
+        writeEndElement();
+    }
+
+    public void writeEmptyElement(String localName) throws XMLStreamException {
+        writeEmptyElement(null, localName, null);
+    }
+
+    public void writeEndElement() throws XMLStreamException {
+        omElementStack.pop();
+    }
+
+    public void writeEndDocument() throws XMLStreamException {
+        // nothing to do
+    }
+
+    public void close() throws XMLStreamException {
+        // nothing to do
+    }
+
+    public void flush() throws XMLStreamException {
+        // nothing to do
+
+
+    }
+
+    public void setDataHandler(DataHandler dataHandler) {
+        OMText omText = omFactory.createOMText(dataHandler, true);
+        currentOMElement.addChild(omText);
+    }
+
+    public void writeAttribute(String attributeName, String attributeValue) throws XMLStreamException
{
+        writeAttribute(null, null, attributeName, attributeValue);
+    }
+
+    public void writeAttribute(String prefix, String namespace, String attributeName, String
attributeValue) throws XMLStreamException {
+        currentOMElement.addAttribute(attributeName, attributeValue, getOMNamespace(namespace,
prefix));
+    }
+
+    public void writeAttribute(String namespace, String attributeName, String attributeValue)
throws XMLStreamException {
+        writeAttribute(null, namespace, attributeName, attributeValue);
+    }
+
+    public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
{
+        if (namespaceURI != null) {
+            OMNamespace omNamespace = getOMNamespace(namespaceURI, prefix);
+            currentOMElement.declareNamespace(omNamespace);
+        }
+    }
+
+    public void writeDefaultNamespace(String namespace) throws XMLStreamException {
+        rootElement.declareDefaultNamespace(namespace);
+        getOMNamespace(namespace, "");
+    }
+
+    public void writeComment(String string) throws XMLStreamException {
+        omFactory.createOMComment(currentOMElement, string);
+    }
+
+    public void writeProcessingInstruction(String string) throws XMLStreamException {
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public void writeProcessingInstruction(String string, String string1) throws XMLStreamException
{
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public void writeCData(String string) throws XMLStreamException {
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public void writeDTD(String string) throws XMLStreamException {
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public void writeEntityRef(String string) throws XMLStreamException {
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public void writeStartDocument() throws XMLStreamException {
+        // nothing to do
+    }
+
+    public void writeStartDocument(String string) throws XMLStreamException {
+        // nothing to do
+    }
+
+    public void writeStartDocument(String string, String string1) throws XMLStreamException
{
+        // nothing to do
+    }
+
+    public void writeCharacters(String string) throws XMLStreamException {
+        currentOMElement.setText(string);
+    }
+
+    public void writeCharacters(char[] chars, int i, int i1) throws XMLStreamException {
+        writeCharacters(new String(chars, i, i1));
+    }
+
+    public String getPrefix(String namespace) throws XMLStreamException {
+        return this.omStreamNamespaceContext.getPrefix(namespace);
+    }
+
+    public void setPrefix(String prefix, String uri) throws XMLStreamException {
+        // this method will add the namespace correctly.
+        getOMNamespace(uri, prefix);
+    }
+
+    public void setDefaultNamespace(String namespace) throws XMLStreamException {
+        rootElement.declareDefaultNamespace(namespace);
+        getOMNamespace(namespace, "");
+    }
+
+    public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException
{
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return this.omStreamNamespaceContext;
+    }
+
+    public Object getProperty(String string) throws IllegalArgumentException {
+        throw new UnsupportedOperationException("this method has not yet been implemented");
+    }
+
+    public void writeDataHandler(DataHandler dataHandler) throws XMLStreamException {
+        OMText omText = omFactory.createOMText(dataHandler, true);
+        currentOMElement.addChild(omText);
+    }
+}

Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLSerializer.java?view=auto&rev=559350
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLSerializer.java
(added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLSerializer.java
Wed Jul 25 01:25:36 2007
@@ -0,0 +1,170 @@
+/*
+ * 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.axis2.databinding.utils.writer;
+
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.om.OMAbstractFactory;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.namespace.NamespaceContext;
+import javax.activation.DataHandler;
+
+/**
+ * this class wrapps the existing xmlStreamWriter and implements the new method
+ * writeDataHandler
+ */
+public class MTOMAwareXMLSerializer implements MTOMAwareXMLStreamWriter {
+
+    private XMLStreamWriter xmlStreamWriter;
+
+    public MTOMAwareXMLSerializer(XMLStreamWriter xmlStreamWriter) {
+        this.xmlStreamWriter = xmlStreamWriter;
+    }
+
+    public void writeStartElement(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeStartElement(string);
+    }
+
+    public void writeStartElement(String string, String string1) throws XMLStreamException
{
+        this.xmlStreamWriter.writeStartElement(string, string1);
+    }
+
+    public void writeStartElement(String string, String string1, String string2) throws XMLStreamException
{
+        this.xmlStreamWriter.writeStartElement(string, string1, string2);
+    }
+
+    public void writeEmptyElement(String string, String string1) throws XMLStreamException
{
+        this.xmlStreamWriter.writeEmptyElement(string, string1);
+    }
+
+    public void writeEmptyElement(String string, String string1, String string2) throws XMLStreamException
{
+        this.xmlStreamWriter.writeEmptyElement(string, string1, string2);
+    }
+
+    public void writeEmptyElement(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeEmptyElement(string);
+    }
+
+    public void writeEndElement() throws XMLStreamException {
+        this.xmlStreamWriter.writeEndElement();
+    }
+
+    public void writeEndDocument() throws XMLStreamException {
+        this.xmlStreamWriter.writeEndDocument();
+    }
+
+    public void close() throws XMLStreamException {
+        this.xmlStreamWriter.close();
+    }
+
+    public void flush() throws XMLStreamException {
+        this.xmlStreamWriter.flush();
+    }
+
+    public void writeAttribute(String string, String string1) throws XMLStreamException {
+        this.xmlStreamWriter.writeAttribute(string, string1);
+    }
+
+    public void writeAttribute(String string, String string1, String string2, String string3)
throws XMLStreamException {
+        this.xmlStreamWriter.writeAttribute(string, string1, string2, string3);
+    }
+
+    public void writeAttribute(String string, String string1, String string2) throws XMLStreamException
{
+        this.xmlStreamWriter.writeAttribute(string, string1, string2);
+    }
+
+    public void writeNamespace(String string, String string1) throws XMLStreamException {
+        this.xmlStreamWriter.writeNamespace(string, string1);
+    }
+
+    public void writeDefaultNamespace(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeDefaultNamespace(string);
+    }
+
+    public void writeComment(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeComment(string);
+    }
+
+    public void writeProcessingInstruction(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeProcessingInstruction(string);
+    }
+
+    public void writeProcessingInstruction(String string, String string1) throws XMLStreamException
{
+        this.xmlStreamWriter.writeProcessingInstruction(string, string1);
+    }
+
+    public void writeCData(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeCData(string);
+    }
+
+    public void writeDTD(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeDTD(string);
+    }
+
+    public void writeEntityRef(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeEntityRef(string);
+    }
+
+    public void writeStartDocument() throws XMLStreamException {
+        this.xmlStreamWriter.writeStartDocument();
+    }
+
+    public void writeStartDocument(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeStartDocument(string);
+    }
+
+    public void writeStartDocument(String string, String string1) throws XMLStreamException
{
+        this.xmlStreamWriter.writeStartDocument(string, string1);
+    }
+
+    public void writeCharacters(String string) throws XMLStreamException {
+        this.xmlStreamWriter.writeCharacters(string);
+    }
+
+    public void writeCharacters(char[] chars, int i, int i1) throws XMLStreamException {
+        this.xmlStreamWriter.writeCharacters(chars, i, i1);
+    }
+
+    public String getPrefix(String string) throws XMLStreamException {
+        return this.xmlStreamWriter.getPrefix(string);
+    }
+
+    public void setPrefix(String string, String string1) throws XMLStreamException {
+        this.xmlStreamWriter.setPrefix(string, string1);
+    }
+
+    public void setDefaultNamespace(String string) throws XMLStreamException {
+        this.xmlStreamWriter.setDefaultNamespace(string);
+    }
+
+    public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException
{
+        this.xmlStreamWriter.setNamespaceContext(namespaceContext);
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return this.xmlStreamWriter.getNamespaceContext();
+    }
+
+    public Object getProperty(String string) throws IllegalArgumentException {
+        return this.xmlStreamWriter.getProperty(string);
+    }
+
+    public void writeDataHandler(DataHandler dataHandler) throws XMLStreamException {
+        OMTextImpl omText = new OMTextImpl(dataHandler, OMAbstractFactory.getOMFactory());
+        omText.internalSerializeAndConsume(this.xmlStreamWriter);
+    }
+}

Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLStreamWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLStreamWriter.java?view=auto&rev=559350
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLStreamWriter.java
(added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareXMLStreamWriter.java
Wed Jul 25 01:25:36 2007
@@ -0,0 +1,9 @@
+package org.apache.axis2.databinding.utils.writer;
+
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+import javax.activation.DataHandler;
+
+public interface MTOMAwareXMLStreamWriter extends XMLStreamWriter {
+    public void writeDataHandler(DataHandler dataHandler) throws XMLStreamException;
+}

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java?view=diff&rev=559350&r1=559349&r2=559350
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java
Wed Jul 25 01:25:36 2007
@@ -20,6 +20,7 @@
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.namespace.NamespaceContext;
+import javax.activation.DataHandler;
 import java.util.Stack;
 import java.util.Map;
 import java.util.HashMap;
@@ -131,6 +132,12 @@
 
     public void flush() throws XMLStreamException {
         // nothing to do
+
+    }
+
+    public void setDataHandler(DataHandler dataHandler){
+        OMText omText = omFactory.createOMText(dataHandler,true);
+        currentOMElement.addChild(omText);
     }
 
     public void writeAttribute(String attributeName, String attributeValue) throws XMLStreamException
{



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


Mime
View raw message