You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2012/06/24 19:16:47 UTC

svn commit: r1353297 - in /axis/axis2/java/core/trunk/modules/jaxbri/src/main: java/org/apache/axis2/jaxbri/JaxbRIDataSource.java resources/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl

Author: veithen
Date: Sun Jun 24 17:16:46 2012
New Revision: 1353297

URL: http://svn.apache.org/viewvc?rev=1353297&view=rev
Log:
Avoid generating the same class (JAXBRIDataSource) over and over again.

Added:
    axis/axis2/java/core/trunk/modules/jaxbri/src/main/java/org/apache/axis2/jaxbri/JaxbRIDataSource.java   (with props)
Modified:
    axis/axis2/java/core/trunk/modules/jaxbri/src/main/resources/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl

Added: axis/axis2/java/core/trunk/modules/jaxbri/src/main/java/org/apache/axis2/jaxbri/JaxbRIDataSource.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxbri/src/main/java/org/apache/axis2/jaxbri/JaxbRIDataSource.java?rev=1353297&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxbri/src/main/java/org/apache/axis2/jaxbri/JaxbRIDataSource.java (added)
+++ axis/axis2/java/core/trunk/modules/jaxbri/src/main/java/org/apache/axis2/jaxbri/JaxbRIDataSource.java Sun Jun 24 17:16:46 2012
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.jaxbri;
+
+import java.io.Writer;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.builder.SAXOMBuilder;
+
+public class JaxbRIDataSource implements org.apache.axiom.om.OMDataSource {
+    private final JAXBContext context;
+    
+    /**
+     * Bound object for output.
+     */
+    private final Object outObject;
+
+    /**
+     * Bound class for output.
+     */
+    private final Class outClazz;
+
+    /**
+     * Marshaller.
+     */
+    private final Marshaller marshaller;
+
+    /**
+     * Namespace
+     */
+    private String nsuri;
+
+    /**
+     * Local name
+     */
+    private String name;
+
+    /**
+     * Constructor from object and marshaller.
+     *
+     * @param obj
+     * @param marshaller
+     */
+    public JaxbRIDataSource(JAXBContext context, Class clazz, Object obj, Marshaller marshaller, String nsuri, String name) {
+        this.context = context;
+        this.outClazz = clazz;
+        this.outObject = obj;
+        this.marshaller = marshaller;
+        this.nsuri = nsuri;
+        this.name = name;
+    }
+
+    public void serialize(java.io.OutputStream output, org.apache.axiom.om.OMOutputFormat format) throws XMLStreamException {
+        try {
+            marshaller.marshal(new JAXBElement(
+                    new QName(nsuri, name), outObject.getClass(), outObject), output);
+        } catch (JAXBException e) {
+            throw new XMLStreamException("Error in JAXB marshalling", e);
+        }
+    }
+
+    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+        try {
+            marshaller.marshal(new JAXBElement(
+                    new QName(nsuri, name), outObject.getClass(), outObject), writer);
+        } catch (JAXBException e) {
+            throw new XMLStreamException("Error in JAXB marshalling", e);
+        }
+    }
+
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        try {
+            marshaller.marshal(new JAXBElement(
+                    new QName(nsuri, name), outObject.getClass(), outObject), xmlWriter);
+        } catch (JAXBException e) {
+            throw new XMLStreamException("Error in JAXB marshalling", e);
+        }
+    }
+
+    public javax.xml.stream.XMLStreamReader getReader() throws javax.xml.stream.XMLStreamException {
+        try {
+            SAXOMBuilder builder = new SAXOMBuilder();
+            Marshaller marshaller = context.createMarshaller();
+            marshaller.marshal(new JAXBElement(
+                    new QName(nsuri, name), outObject.getClass(), outObject), builder);
+
+            return builder.getRootElement().getXMLStreamReader();
+        } catch (JAXBException e) {
+            throw new XMLStreamException("Error in JAXB marshalling", e);
+        }
+    }
+}

Propchange: axis/axis2/java/core/trunk/modules/jaxbri/src/main/java/org/apache/axis2/jaxbri/JaxbRIDataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: axis/axis2/java/core/trunk/modules/jaxbri/src/main/resources/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxbri/src/main/resources/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl?rev=1353297&r1=1353296&r2=1353297&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxbri/src/main/resources/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl (original)
+++ axis/axis2/java/core/trunk/modules/jaxbri/src/main/resources/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl Sun Jun 24 17:16:46 2012
@@ -70,7 +70,8 @@
 
                         org.apache.axiom.om.OMFactory factory = org.apache.axiom.om.OMAbstractFactory.getOMFactory();
 
-                        JaxbRIDataSource source = new JaxbRIDataSource( <xsl:value-of select="@type"/>.class,
+                        org.apache.axis2.jaxbri.JaxbRIDataSource source = new org.apache.axis2.jaxbri.JaxbRIDataSource( wsContext,
+                                                                        <xsl:value-of select="@type"/>.class,
                                                                         param,
                                                                         marshaller,
                                                                         methodQName.getNamespaceURI(),
@@ -92,7 +93,8 @@
 
                             org.apache.axiom.om.OMFactory factory = org.apache.axiom.om.OMAbstractFactory.getOMFactory();
 
-                            JaxbRIDataSource source = new JaxbRIDataSource( <xsl:value-of select="@type"/>.class,
+                            org.apache.axis2.jaxbri.JaxbRIDataSource source = new org.apache.axis2.jaxbri.JaxbRIDataSource( wsContext,
+                                                                            <xsl:value-of select="@type"/>.class,
                                                                             param,
                                                                             marshaller,
                                                                             "<xsl:value-of select="qname/@nsuri"/>",
@@ -248,88 +250,5 @@
                 throw org.apache.axis2.AxisFault.makeFault(bex);
             }
         }
-
-        class JaxbRIDataSource implements org.apache.axiom.om.OMDataSource {
-            /**
-             * Bound object for output.
-             */
-            private final Object outObject;
-
-            /**
-             * Bound class for output.
-             */
-            private final Class outClazz;
-
-            /**
-             * Marshaller.
-             */
-            private final javax.xml.bind.Marshaller marshaller;
-
-            /**
-             * Namespace
-             */
-            private String nsuri;
-
-            /**
-             * Local name
-             */
-            private String name;
-
-            /**
-             * Constructor from object and marshaller.
-             *
-             * @param obj
-             * @param marshaller
-             */
-            public JaxbRIDataSource(Class clazz, Object obj, javax.xml.bind.Marshaller marshaller, String nsuri, String name) {
-                this.outClazz = clazz;
-                this.outObject = obj;
-                this.marshaller = marshaller;
-                this.nsuri = nsuri;
-                this.name = name;
-            }
-
-            public void serialize(java.io.OutputStream output, org.apache.axiom.om.OMOutputFormat format) throws javax.xml.stream.XMLStreamException {
-                try {
-                    marshaller.marshal(new javax.xml.bind.JAXBElement(
-                            new javax.xml.namespace.QName(nsuri, name), outObject.getClass(), outObject), output);
-                } catch (javax.xml.bind.JAXBException e) {
-                    throw new javax.xml.stream.XMLStreamException("Error in JAXB marshalling", e);
-                }
-            }
-
-            public void serialize(java.io.Writer writer, org.apache.axiom.om.OMOutputFormat format) throws javax.xml.stream.XMLStreamException {
-                try {
-                    marshaller.marshal(new javax.xml.bind.JAXBElement(
-                            new javax.xml.namespace.QName(nsuri, name), outObject.getClass(), outObject), writer);
-                } catch (javax.xml.bind.JAXBException e) {
-                    throw new javax.xml.stream.XMLStreamException("Error in JAXB marshalling", e);
-                }
-            }
-
-            public void serialize(javax.xml.stream.XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
-                try {
-                    marshaller.marshal(new javax.xml.bind.JAXBElement(
-                            new javax.xml.namespace.QName(nsuri, name), outObject.getClass(), outObject), xmlWriter);
-                } catch (javax.xml.bind.JAXBException e) {
-                    throw new javax.xml.stream.XMLStreamException("Error in JAXB marshalling", e);
-                }
-            }
-
-            public javax.xml.stream.XMLStreamReader getReader() throws javax.xml.stream.XMLStreamException {
-                try {
-                    javax.xml.bind.JAXBContext context = wsContext;
-                    org.apache.axiom.om.impl.builder.SAXOMBuilder builder = new org.apache.axiom.om.impl.builder.SAXOMBuilder();
-                    javax.xml.bind.Marshaller marshaller = context.createMarshaller();
-                    marshaller.marshal(new javax.xml.bind.JAXBElement(
-                            new javax.xml.namespace.QName(nsuri, name), outObject.getClass(), outObject), builder);
-
-                    return builder.getRootElement().getXMLStreamReader();
-                } catch (javax.xml.bind.JAXBException e) {
-                    throw new javax.xml.stream.XMLStreamException("Error in JAXB marshalling", e);
-                }
-            }
-        }
-        
     </xsl:template>
     </xsl:stylesheet>