001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.schema.populate.other;
020:
021: import junit.framework.TestCase;
022:
023: import javax.xml.stream.XMLStreamReader;
024: import javax.xml.stream.XMLInputFactory;
025: import java.io.ByteArrayInputStream;
026: import java.lang.reflect.Method;
027:
028: import org.apache.axiom.soap.SOAPEnvelope;
029: import org.apache.axiom.soap.SOAPFactory;
030: import org.apache.axiom.om.OMAbstractFactory;
031: import org.apache.axiom.om.OMElement;
032: import org.apache.axiom.om.impl.builder.StAXOMBuilder;
033:
034: public class ADBInOutTest extends TestCase {
035:
036: private String xmlString = "<tempElt xmlns=\"http://soapinterop.org1/types\">"
037: + "hello" + "</tempElt>";
038: private String xmlString2 = "<header1 xmlns=\"http://soapinterop.org1/types\">"
039: + "<varString>Hello</varString>"
040: + "<varInt>5</varInt>"
041: + "<varFloat>3.3</varFloat>" + "</header1>";
042:
043: public void testPopulate() throws Exception {
044:
045: XMLStreamReader reader = XMLInputFactory.newInstance()
046: .createXMLStreamReader(
047: new ByteArrayInputStream(xmlString.getBytes()));
048: SOAPEnvelope defaultEnvelope = OMAbstractFactory
049: .getSOAP11Factory().getDefaultEnvelope();
050: OMElement documentElement = new StAXOMBuilder(reader)
051: .getDocumentElement();
052: defaultEnvelope.getBody().addChild(documentElement);
053: XMLStreamReader xmlStreamReader = defaultEnvelope.getBody()
054: .getFirstElement().getXMLStreamReader();
055: while (xmlStreamReader.hasNext()) {
056: System.out.println("event " + xmlStreamReader.next());
057: System.out.println("text "
058: + (xmlStreamReader.hasText() ? xmlStreamReader
059: .getText() : ""));
060: System.out.println("localName "
061: + (xmlStreamReader.hasName() ? xmlStreamReader
062: .getLocalName() : ""));
063: }
064: }
065:
066: public void testPopulate2() throws Exception {
067:
068: XMLStreamReader reader = XMLInputFactory.newInstance()
069: .createXMLStreamReader(
070: new ByteArrayInputStream(xmlString.getBytes()));
071: XMLStreamReader reader2 = XMLInputFactory
072: .newInstance()
073: .createXMLStreamReader(
074: new ByteArrayInputStream(xmlString2.getBytes()));
075:
076: SOAPFactory soap11Factory = OMAbstractFactory
077: .getSOAP11Factory();
078:
079: SOAPEnvelope defaultEnvelope = soap11Factory
080: .getDefaultEnvelope();
081: OMElement documentElement = new StAXOMBuilder(reader)
082: .getDocumentElement();
083: defaultEnvelope.getBody().addChild(documentElement);
084:
085: OMElement documentElement2 = new StAXOMBuilder(reader2)
086: .getDocumentElement();
087: defaultEnvelope.getHeader().addChild(documentElement2);
088:
089: XMLStreamReader xmlStreamReader = defaultEnvelope.getBody()
090: .getFirstElement().getXMLStreamReader();
091: while (xmlStreamReader.hasNext()) {
092: System.out.println("event " + xmlStreamReader.next());
093: System.out.println("text "
094: + (xmlStreamReader.hasText() ? xmlStreamReader
095: .getText() : ""));
096: System.out.println("localName "
097: + (xmlStreamReader.hasName() ? xmlStreamReader
098: .getLocalName() : ""));
099: }
100: }
101: }
|