You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/12/28 21:02:56 UTC
svn commit: r359617 - in /webservices/axis2/trunk/java/modules/adb:
src/org/apache/axis2/databinding/ADBSOAPModelBuilder.java
test/org/apache/axis2/databinding/ADBSOAPModelBuilderTest.java
Author: dims
Date: Wed Dec 28 12:02:52 2005
New Revision: 359617
URL: http://svn.apache.org/viewcvs?rev=359617&view=rev
Log:
In the generated code, we get a pull parser from ADBBean using StaxOMBuilder, then we try to detach the document element and shove it into a envelope.getBody().setFirstChild(). During this step the whole OM is built as detach kicks off a recursive build of the whole tree. To avoid this situation, we have a new builder that creates a SOAPEnvelope/SOAPBody and makes sure that the OM tree built from the pull parser is automatically the child of SOAPBody.
Benefit: if we call serialize on the soapenvelope, we should be able to serialize the stuff from the pull parser directly into output stream (with no intermediate om tree).
Added:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBSOAPModelBuilder.java
webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/ADBSOAPModelBuilderTest.java
Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBSOAPModelBuilder.java?rev=359617&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBSOAPModelBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/ADBSOAPModelBuilder.java Wed Dec 28 12:02:52 2005
@@ -0,0 +1,43 @@
+package org.apache.axis2.databinding;
+
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis2.om.impl.OMNodeEx;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.soap.SOAPEnvelope;
+import org.apache.axis2.soap.SOAPBody;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * Builds a SOAPEnvelope around an ADB pull parser
+ */
+public class ADBSOAPModelBuilder extends StAXOMBuilder {
+ SOAPBody body = null;
+
+ public ADBSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory) {
+ super(factory, parser);
+ document = factory.createSOAPMessage(this);
+ SOAPEnvelope env = factory.getDefaultEnvelope();
+ document.addChild(env);
+ body = env.getBody();
+ ((OMNodeEx)body).setComplete(false);
+ body.setBuilder(this);
+ lastNode = body;
+ }
+
+ public int next() throws OMException {
+ int ret = super.next();
+ try {
+ // Peek to see if the parser has any more and set the done flag.
+ if(!parser.hasNext()) {
+ done = true;
+ ((OMNodeEx)body).setComplete(true);
+ }
+ } catch (XMLStreamException e) {
+ throw new OMException(e);
+ }
+ return ret;
+ }
+}
Added: webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/ADBSOAPModelBuilderTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/ADBSOAPModelBuilderTest.java?rev=359617&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/ADBSOAPModelBuilderTest.java (added)
+++ webservices/axis2/trunk/java/modules/adb/test/org/apache/axis2/databinding/ADBSOAPModelBuilderTest.java Wed Dec 28 12:02:52 2005
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import org.apache.axis2.databinding.utils.ADBPullParser;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class ADBSOAPModelBuilderTest extends XMLTestCase {
+ public void testSimpleArrayList() throws Exception {
+ String expectedXML = "<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><Person xmlns=\"\"><Name xmlns=\"\">FooOne</Name><DependentOne xmlns=\"\"><Name xmlns=\"\">FooTwo</Name><Age xmlns=\"\">25</Age><Sex xmlns=\"\">Male</Sex></DependentOne><DependentTwo xmlns=\"\"><Name xmlns=\"\">FooTwo</Name><Age xmlns=\"\">25</Age><Sex xmlns=\"\">Male</Sex></DependentTwo><Organization xmlns=\"\">Apache</Organization></Person></soapenv:Body></soapenv:Envelope>";
+ ArrayList propertyList = new ArrayList();
+ propertyList.add("Name");
+ propertyList.add("FooOne");
+ propertyList.add(new QName("DependentOne"));
+ propertyList.add(new DummyADBBean());
+ propertyList.add(new QName("DependentTwo"));
+ propertyList.add(new DummyADBBean());
+ propertyList.add("Organization");
+ propertyList.add("Apache");
+ QName projectQName = new QName("Person");
+
+ XMLStreamReader pullParser = ADBPullParser.createPullParser(projectQName, propertyList.toArray(), null);
+ ADBSOAPModelBuilder builder = new ADBSOAPModelBuilder(pullParser, OMAbstractFactory.getSOAP11Factory());
+
+ OMElement root = builder.getDocumentElement();
+ assertTrue("Root element can not be null", root != null);
+ System.out.println(root.toString());
+ Document expectedDOM = newDocument(expectedXML);
+ Document actualDom = newDocument(root.toString());
+ assertXMLEqual(actualDom, expectedDOM);
+ }
+
+ public class DummyADBBean implements ADBBean {
+ ArrayList propertyList = new ArrayList();
+
+ public DummyADBBean() {
+ propertyList.add("Name");
+ propertyList.add("FooTwo");
+ propertyList.add("Age");
+ propertyList.add("25");
+ propertyList.add("Sex");
+ propertyList.add("Male");
+ }
+
+ public DummyADBBean addAnotherBean() {
+ propertyList.add(new QName("Depemdent"));
+ DummyADBBean dummyBean = new DummyADBBean();
+ propertyList.add(dummyBean);
+ return dummyBean;
+ }
+
+ public XMLStreamReader getPullParser(QName adbBeanQName) {
+ return ADBPullParser.createPullParser(adbBeanQName, propertyList.toArray(), null);
+ }
+ }
+
+ private String getStringXML(XMLStreamReader reader) {
+ OMElement omelement = new StAXOMBuilder(reader).getDocumentElement();
+ return omelement.toString();
+ }
+
+ public Document newDocument(String xml)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ return db.parse(new ByteArrayInputStream(xml.getBytes()));
+ }
+}