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 ds...@apache.org on 2006/04/21 03:21:56 UTC

svn commit: r395750 - in /webservices/axis2/trunk/java/modules: codegen/src/org/apache/axis2/wsdl/template/java/DatabindingTemplate.xsl jibx/src/org/apache/axis2/jibx/JiBXDataSource.java jibx/src/org/apache/axis2/jibx/OMJiBXElementImpl.java

Author: dsosnoski
Date: Thu Apr 20 18:21:53 2006
New Revision: 395750

URL: http://svn.apache.org/viewcvs?rev=395750&view=rev
Log:
Restructured JiBX binding support to use new Axiom OMDataSource approach.

Added:
    webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java
Removed:
    webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/OMJiBXElementImpl.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/DatabindingTemplate.xsl

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/DatabindingTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/DatabindingTemplate.xsl?rev=395750&r1=395749&r2=395750&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/DatabindingTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/DatabindingTemplate.xsl Thu Apr 20 18:21:53 2006
@@ -266,13 +266,18 @@
                     };
                 </xsl:if>
                 
-                private org.apache.axiom.om.OMElement toOM(<xsl:value-of select="@type"/> param, boolean optimzieContent) {
+                private org.apache.axiom.om.OMElement toOM(<xsl:value-of select="@type"/> param, org.apache.axiom.soap.SOAPFactory factory, boolean optimzieContent) {
                     if (param instanceof org.jibx.runtime.IMarshallable){
                         if (bindingFactory == null) {
                             throw new RuntimeException("Could not find JiBX binding information for <xsl:value-of select='$firstType'/>, JiBX binding unusable");
                         }
-                        return new org.apache.axis2.jibx.OMJiBXElementImpl
-                            ((org.jibx.runtime.IMarshallable)param, bindingFactory);
+                        org.jibx.runtime.IMarshallable marshallable =
+                            (org.jibx.runtime.IMarshallable)param;
+                        int index = marshallable.JiBX_getIndex();
+                        org.apache.axis2.jibx.JiBXDataSource source =
+                            new org.apache.axis2.jibx.JiBXDataSource(marshallable, bindingFactory);
+                        org.apache.axiom.om.OMNamespace namespace = factory.createOMNamespace(bindingFactory.getElementNamespaces()[index], null);
+                        return factory.createOMElement(source, bindingFactory.getElementNames()[index], namespace);
                     } else {
                         throw new RuntimeException("No JiBX &lt;mapping> defined for class <xsl:value-of select='@type'/>");
                     }
@@ -281,7 +286,7 @@
                 private org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory, <xsl:value-of select="@type"/> param, boolean optimizeContent) {
                     org.apache.axiom.soap.SOAPEnvelope envelope = factory.getDefaultEnvelope();
                     if (param != null){
-                        envelope.getBody().addChild(toOM(param, optimizeContent));
+                        envelope.getBody().addChild(toOM(param, factory, optimizeContent));
                     }
                     return envelope;
                 }

Added: webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java?rev=395750&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java (added)
+++ webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java Thu Apr 20 18:21:53 2006
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2006 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.jibx;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMOutputFormat;
+import org.jibx.runtime.IBindingFactory;
+import org.jibx.runtime.IMarshallable;
+import org.jibx.runtime.IMarshallingContext;
+import org.jibx.runtime.IXMLWriter;
+import org.jibx.runtime.JiBXException;
+import org.jibx.runtime.impl.StAXWriter;
+
+/**
+ * Data source for OM element backed by JiBX data bound object.
+ */
+public class JiBXDataSource implements OMDataSource
+{
+    /** Bound object for output. */
+    private final IMarshallable outObject;
+    
+    /** Binding factory for creating marshaller. */
+    private final IBindingFactory bindingFactory;
+    
+    /**
+     * Constructor from object and binding factory.
+     * 
+     * @param obj
+     * @param factory
+     */
+    public JiBXDataSource(IMarshallable obj, IBindingFactory factory) {
+        outObject = obj;
+        bindingFactory = factory;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.axiom.om.OMDataSource#serialize(java.io.OutputStream, org.apache.axiom.om.OMOutputFormat)
+     */
+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+        try {
+            IMarshallingContext ctx = bindingFactory.createMarshallingContext();
+            ctx.setOutput(output, "UTF-8");
+            outObject.marshal(ctx);
+        } catch (JiBXException e) {
+            throw new XMLStreamException("Error in JiBX marshalling", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.axiom.om.OMDataSource#serialize(java.io.Writer, org.apache.axiom.om.OMOutputFormat)
+     */
+    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+        try {
+            IMarshallingContext ctx = bindingFactory.createMarshallingContext();
+            ctx.setOutput(writer);
+            outObject.marshal(ctx);
+        } catch (JiBXException e) {
+            throw new XMLStreamException("Error in JiBX marshalling", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.axiom.om.OMDataSource#serialize(javax.xml.stream.XMLStreamWriter)
+     */
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        try {
+            IXMLWriter writer = new StAXWriter(bindingFactory.getNamespaces(),
+                xmlWriter);
+            IMarshallingContext ctx = bindingFactory.createMarshallingContext();
+            ctx.setXmlWriter(writer);
+            outObject.marshal(ctx);
+        } catch (JiBXException e) {
+            throw new XMLStreamException("Error in JiBX marshalling", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.axiom.om.OMDataSource#getReader()
+     */
+    public XMLStreamReader getReader() throws XMLStreamException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        serialize(bos, null);
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        return inputFactory.createXMLStreamReader(new ByteArrayInputStream(bos.toByteArray()));
+    }
+}
\ No newline at end of file