1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
30 import javax.xml.stream.XMLStreamConstants;
31 import javax.xml.stream.XMLStreamReader;
32
33 import com.sun.xml.internal.org.jvnet.staxex.util.XMLStreamReaderToXMLStreamWriter;
34
35 /**
36 * StaxBridge builds Envelope using a XMLStreamReaderToXMLStreamWriter
37 *
38 * @author shih-chang.chen@oracle.com
39 */
40 public class StaxReaderBridge extends StaxBridge {
41 private XMLStreamReader in;
42
43 public StaxReaderBridge(XMLStreamReader reader, SOAPPartImpl soapPart) throws SOAPException {
44 super(soapPart);
45 in = reader;
46 final String soapEnvNS = soapPart.getSOAPNamespace();
47 breakpoint = new XMLStreamReaderToXMLStreamWriter.Breakpoint(reader, saajWriter) {
48 boolean seenBody = false;
49 boolean stopedAtBody = false;
50 public boolean proceedBeforeStartElement() {
51 if (stopedAtBody) return true;
52 if (seenBody) {
53 stopedAtBody = true;
54 return false;
55 }
56 if ("Body".equals(reader.getLocalName()) && soapEnvNS.equals(reader.getNamespaceURI()) ){
57 seenBody = true;
58 }
59 return true;
60 }
61 };
62 }
63
64 public XMLStreamReader getPayloadReader() {
65 return in;
66 }
67
68 public QName getPayloadQName() {
69 return (in.getEventType() == XMLStreamConstants.START_ELEMENT) ? in.getName() : null;
70 }
71
72 public String getPayloadAttributeValue(String attName) {
73 return (in.getEventType() == XMLStreamConstants.START_ELEMENT) ? in.getAttributeValue(null, attName) : null;
74 }
75
76 public String getPayloadAttributeValue(QName attName) {
77 return (in.getEventType() == XMLStreamConstants.START_ELEMENT) ? in.getAttributeValue(attName.getNamespaceURI(), attName.getLocalPart()) : null;
78 }
79 }
|
1 /*
2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
30 import javax.xml.stream.XMLStreamConstants;
31 import javax.xml.stream.XMLStreamReader;
32
33 import com.sun.xml.internal.org.jvnet.staxex.util.XMLStreamReaderToXMLStreamWriter;
34
35 /**
36 * StaxBridge builds Envelope using a XMLStreamReaderToXMLStreamWriter
37 *
38 * @author shih-chang.chen@oracle.com
39 */
40 public class StaxReaderBridge extends StaxBridge {
41 private XMLStreamReader in;
42
43 public StaxReaderBridge(XMLStreamReader reader, SOAPPartImpl soapPart) throws SOAPException {
44 super(soapPart);
45 in = reader;
46 final String soapEnvNS = soapPart.getSOAPNamespace();
47 breakpoint = new XMLStreamReaderToXMLStreamWriter.Breakpoint(reader, saajWriter) {
48 boolean seenBody = false;
49 boolean stopedAtBody = false;
50 @Override
51 public boolean proceedBeforeStartElement() {
52 if (stopedAtBody) return true;
53 if (seenBody) {
54 stopedAtBody = true;
55 return false;
56 }
57 if ("Body".equals(reader.getLocalName()) && soapEnvNS.equals(reader.getNamespaceURI()) ){
58 seenBody = true;
59 }
60 return true;
61 }
62 };
63 }
64
65 @Override
66 public XMLStreamReader getPayloadReader() {
67 return in;
68 }
69
70 @Override
71 public QName getPayloadQName() {
72 return (in.getEventType() == XMLStreamConstants.START_ELEMENT) ? in.getName() : null;
73 }
74
75 @Override
76 public String getPayloadAttributeValue(String attName) {
77 return (in.getEventType() == XMLStreamConstants.START_ELEMENT) ? in.getAttributeValue(null, attName) : null;
78 }
79
80 @Override
81 public String getPayloadAttributeValue(QName attName) {
82 return (in.getEventType() == XMLStreamConstants.START_ELEMENT) ? in.getAttributeValue(attName.getNamespaceURI(), attName.getLocalPart()) : null;
83 }
84 }
|