package com.sun.xml.internal.ws.api.addressing;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Writer;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPHeader;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
final class extends AbstractHeaderImpl {
private final String ,;
private final WSEndpointReference ;
(QName tagName, WSEndpointReference epr) {
this.nsUri = tagName.getNamespaceURI();
this.localName = tagName.getLocalPart();
this.epr = epr;
}
public @NotNull String () {
return nsUri;
}
public @NotNull String () {
return localName;
}
@Nullable
public String (@NotNull String nsUri, @NotNull String localName) {
try {
XMLStreamReader sr = epr.read("EndpointReference");
while(sr.getEventType()!= XMLStreamConstants.START_ELEMENT)
sr.next();
return sr.getAttributeValue(nsUri,localName);
} catch (XMLStreamException e) {
throw new AssertionError(e);
}
}
public XMLStreamReader () throws XMLStreamException {
return epr.read(localName);
}
public void (XMLStreamWriter w) throws XMLStreamException {
epr.writeTo(localName, w);
}
public void (SOAPMessage saaj) throws SOAPException {
try {
Transformer t = XmlUtil.newTransformer();
SOAPHeader header = saaj.getSOAPHeader();
if (header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
epr.writeTo(localName, w);
w.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false);
fac.setNamespaceAware(true);
Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
header.appendChild(eprNodeToAdd);
} catch (Exception e) {
throw new SOAPException(e);
}
}
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
epr.writeTo(localName,contentHandler,errorHandler,true);
}
}