1 /*
2 * Copyright (c) 1997, 2012, 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
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.message.jaxb;
27
28 import com.sun.istack.internal.NotNull;
29 import com.sun.istack.internal.XMLStreamException2;
30 import com.sun.xml.internal.bind.api.Bridge;
31 import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
32 import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
33 import com.sun.xml.internal.ws.api.message.Header;
34 import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
35 import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
36 import com.sun.xml.internal.ws.message.RootElementSniffer;
37 import com.sun.xml.internal.ws.spi.db.BindingContext;
38 import com.sun.xml.internal.ws.spi.db.XMLBridge;
39 import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil;
40 import org.xml.sax.Attributes;
41 import org.xml.sax.ContentHandler;
42 import org.xml.sax.ErrorHandler;
43 import org.xml.sax.SAXException;
44 import org.xml.sax.SAXParseException;
45
46 import javax.xml.bind.JAXBElement;
47 import javax.xml.bind.JAXBException;
48 import javax.xml.bind.Unmarshaller;
49 import javax.xml.bind.util.JAXBResult;
50 import javax.xml.namespace.QName;
125
126 public @NotNull String getNamespaceURI() {
127 if(nsUri==null)
128 parse();
129 return nsUri;
130 }
131
132 public @NotNull String getLocalPart() {
133 if(localName==null)
134 parse();
135 return localName;
136 }
137
138 public String getAttribute(String nsUri, String localName) {
139 if(atts==null)
140 parse();
141 return atts.getValue(nsUri,localName);
142 }
143
144 public XMLStreamReader readHeader() throws XMLStreamException {
145 try {
146 if(infoset==null) {
147 XMLStreamBufferResult sbr = new XMLStreamBufferResult();
148 bridge.marshal(jaxbObject,sbr);
149 infoset = sbr.getXMLStreamBuffer();
150 }
151 return infoset.readAsXMLStreamReader();
152 } catch (JAXBException e) {
153 throw new XMLStreamException2(e);
154 }
155 }
156
157 public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
158 try {
159 JAXBResult r = new JAXBResult(unmarshaller);
160 // bridge marshals a fragment, so we need to add start/endDocument by ourselves
161 r.getHandler().startDocument();
162 bridge.marshal(jaxbObject,r);
163 r.getHandler().endDocument();
164 return (T)r.getResult();
165 } catch (SAXException e) {
166 throw new JAXBException(e);
167 }
168 }
169 /** @deprecated */
170 public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException {
171 return bridge.unmarshal(new JAXBBridgeSource(this.bridge,jaxbObject));
172 }
173
174 public <T> T readAsJAXB(XMLBridge<T> bond) throws JAXBException {
|
1 /*
2 * Copyright (c) 1997, 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
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.message.jaxb;
27
28 import com.sun.istack.internal.NotNull;
29 import com.sun.istack.internal.XMLStreamException2;
30 import com.sun.xml.internal.bind.api.Bridge;
31 import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
32 import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
33 import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
34 import com.sun.xml.internal.ws.api.message.Header;
35 import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
36 import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
37 import com.sun.xml.internal.ws.message.RootElementSniffer;
38 import com.sun.xml.internal.ws.spi.db.BindingContext;
39 import com.sun.xml.internal.ws.spi.db.XMLBridge;
40 import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil;
41 import org.xml.sax.Attributes;
42 import org.xml.sax.ContentHandler;
43 import org.xml.sax.ErrorHandler;
44 import org.xml.sax.SAXException;
45 import org.xml.sax.SAXParseException;
46
47 import javax.xml.bind.JAXBElement;
48 import javax.xml.bind.JAXBException;
49 import javax.xml.bind.Unmarshaller;
50 import javax.xml.bind.util.JAXBResult;
51 import javax.xml.namespace.QName;
126
127 public @NotNull String getNamespaceURI() {
128 if(nsUri==null)
129 parse();
130 return nsUri;
131 }
132
133 public @NotNull String getLocalPart() {
134 if(localName==null)
135 parse();
136 return localName;
137 }
138
139 public String getAttribute(String nsUri, String localName) {
140 if(atts==null)
141 parse();
142 return atts.getValue(nsUri,localName);
143 }
144
145 public XMLStreamReader readHeader() throws XMLStreamException {
146 if(infoset==null) {
147 MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
148 writeTo(buffer.createFromXMLStreamWriter());
149 infoset = buffer;
150 }
151 return infoset.readAsXMLStreamReader();
152 }
153
154 public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
155 try {
156 JAXBResult r = new JAXBResult(unmarshaller);
157 // bridge marshals a fragment, so we need to add start/endDocument by ourselves
158 r.getHandler().startDocument();
159 bridge.marshal(jaxbObject,r);
160 r.getHandler().endDocument();
161 return (T)r.getResult();
162 } catch (SAXException e) {
163 throw new JAXBException(e);
164 }
165 }
166 /** @deprecated */
167 public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException {
168 return bridge.unmarshal(new JAXBBridgeSource(this.bridge,jaxbObject));
169 }
170
171 public <T> T readAsJAXB(XMLBridge<T> bond) throws JAXBException {
|