package com.sun.xml.internal.ws.message.jaxb;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.XMLStreamException2;
import com.sun.xml.internal.bind.api.Bridge;
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
import com.sun.xml.internal.ws.message.RootElementSniffer;
import com.sun.xml.internal.ws.spi.db.BindingContext;
import com.sun.xml.internal.ws.spi.db.XMLBridge;
import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.util.JAXBResult;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPHeader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import java.io.OutputStream;
public final class extends AbstractHeaderImpl {
private final Object ;
private final XMLBridge ;
private String ;
private String ;
private Attributes ;
private XMLStreamBuffer ;
public (BindingContext context, Object jaxbObject) {
this.jaxbObject = jaxbObject;
this.bridge = context.createFragmentBridge();
if (jaxbObject instanceof JAXBElement) {
JAXBElement e = (JAXBElement) jaxbObject;
this.nsUri = e.getName().getNamespaceURI();
this.localName = e.getName().getLocalPart();
}
}
public (XMLBridge bridge, Object jaxbObject) {
this.jaxbObject = jaxbObject;
this.bridge = bridge;
QName tagName = bridge.getTypeInfo().tagName;
this.nsUri = tagName.getNamespaceURI();
this.localName = tagName.getLocalPart();
}
private void () {
RootElementSniffer sniffer = new RootElementSniffer();
try {
bridge.marshal(jaxbObject,sniffer,null);
} catch (JAXBException e) {
nsUri = sniffer.getNsUri();
localName = sniffer.getLocalName();
atts = sniffer.getAttributes();
}
}
public @NotNull String () {
if(nsUri==null)
parse();
return nsUri;
}
public @NotNull String () {
if(localName==null)
parse();
return localName;
}
public String (String nsUri, String localName) {
if(atts==null)
parse();
return atts.getValue(nsUri,localName);
}
public XMLStreamReader () throws XMLStreamException {
if(infoset==null) {
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
writeTo(buffer.createFromXMLStreamWriter());
infoset = buffer;
}
return infoset.readAsXMLStreamReader();
}
public <T> T (Unmarshaller unmarshaller) throws JAXBException {
try {
JAXBResult r = new JAXBResult(unmarshaller);
r.getHandler().startDocument();
bridge.marshal(jaxbObject,r);
r.getHandler().endDocument();
return (T)r.getResult();
} catch (SAXException e) {
throw new JAXBException(e);
}
}
public <T> T (Bridge<T> bridge) throws JAXBException {
return bridge.unmarshal(new JAXBBridgeSource(this.bridge,jaxbObject));
}
public <T> T (XMLBridge<T> bond) throws JAXBException {
return bond.unmarshal(new JAXBBridgeSource(this.bridge,jaxbObject),null);
}
public void (XMLStreamWriter sw) throws XMLStreamException {
try {
String encoding = XMLStreamWriterUtil.getEncoding(sw);
OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), null);
} else {
bridge.marshal(jaxbObject,sw, null);
}
} catch (JAXBException e) {
throw new XMLStreamException2(e);
}
}
public void (SOAPMessage saaj) throws SOAPException {
try {
SOAPHeader header = saaj.getSOAPHeader();
if (header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
bridge.marshal(jaxbObject,header);
} catch (JAXBException e) {
throw new SOAPException(e);
}
}
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
try {
bridge.marshal(jaxbObject,contentHandler,null);
} catch (JAXBException e) {
SAXParseException x = new SAXParseException(e.getMessage(),null,null,-1,-1,e);
errorHandler.fatalError(x);
throw x;
}
}
}