001: /*
002: * SignatureConfirmation.java
003: *
004: * Created on September 11, 2006, 3:06 PM
005: *
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.ws.security.opt.impl.tokens;
028:
029: import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
030: import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
031: import com.sun.xml.ws.security.opt.impl.util.JAXBUtil;
032: import com.sun.xml.ws.security.secext11.ObjectFactory;
033: import com.sun.xml.ws.security.secext11.SignatureConfirmationType;
034: import java.io.OutputStream;
035: import java.util.HashMap;
036: import java.util.Iterator;
037: import java.util.Map;
038: import javax.xml.bind.JAXBElement;
039: import javax.xml.bind.Marshaller;
040: import javax.xml.bind.JAXBException;
041: import javax.xml.namespace.QName;
042: import com.sun.xml.wss.impl.MessageConstants;
043: import com.sun.xml.stream.buffer.XMLStreamBufferResult;
044: import com.sun.xml.ws.api.SOAPVersion;
045: import javax.xml.stream.XMLStreamException;
046:
047: /**
048: *
049: * @author Ashutosh.Shahi@sun.com
050: */
051: public class SignatureConfirmation extends SignatureConfirmationType
052: implements SecurityHeaderElement, SecurityElementWriter {
053:
054: private final ObjectFactory objFac = new ObjectFactory();
055: private SOAPVersion soapVersion = SOAPVersion.SOAP_11;
056:
057: /** Creates a new instance of SignatureConfirmation */
058: public SignatureConfirmation(String id, SOAPVersion sv) {
059: setId(id);
060: this .soapVersion = sv;
061: }
062:
063: public String getNamespaceURI() {
064: return MessageConstants.WSSE11_NS;
065: }
066:
067: public String getLocalPart() {
068: return MessageConstants.SIGNATURE_CONFIRMATION_LNAME;
069: }
070:
071: public String getAttribute(String nsUri, String localName) {
072: throw new UnsupportedOperationException();
073: }
074:
075: public String getAttribute(QName name) {
076: throw new UnsupportedOperationException();
077: }
078:
079: public javax.xml.stream.XMLStreamReader readHeader()
080: throws javax.xml.stream.XMLStreamException {
081: XMLStreamBufferResult xbr = new XMLStreamBufferResult();
082: JAXBElement<SignatureConfirmationType> scElem = objFac
083: .createSignatureConfirmation(this );
084: try {
085: getMarshaller().marshal(scElem, xbr);
086:
087: } catch (JAXBException je) {
088: throw new XMLStreamException(je);
089: }
090: return xbr.getXMLStreamBuffer().readAsXMLStreamReader();
091: }
092:
093: public void writeTo(OutputStream os) {
094: }
095:
096: public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter)
097: throws javax.xml.stream.XMLStreamException {
098: JAXBElement<SignatureConfirmationType> scElem = objFac
099: .createSignatureConfirmation(this );
100: try {
101: // If writing to Zephyr, get output stream and use JAXB UTF-8 writer
102: if (streamWriter instanceof Map) {
103: OutputStream os = (OutputStream) ((Map) streamWriter)
104: .get("sjsxp-outputstream");
105: if (os != null) {
106: streamWriter.writeCharacters(""); // Force completion of open elems
107: getMarshaller().marshal(scElem, os);
108: return;
109: }
110: }
111:
112: getMarshaller().marshal(scElem, streamWriter);
113: } catch (JAXBException e) {
114: throw new XMLStreamException(e);
115: }
116: }
117:
118: private Marshaller getMarshaller() throws JAXBException {
119: return JAXBUtil.createMarshaller(soapVersion);
120: }
121:
122: /**
123: *
124: * @param id
125: * @return
126: */
127: public boolean refersToSecHdrWithId(String id) {
128: return false;
129: }
130:
131: public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter,
132: HashMap props) throws javax.xml.stream.XMLStreamException {
133: try {
134: Marshaller marshaller = getMarshaller();
135: Iterator<Map.Entry<Object, Object>> itr = props.entrySet()
136: .iterator();
137: while (itr.hasNext()) {
138: Map.Entry<Object, Object> entry = itr.next();
139: marshaller.setProperty((String) entry.getKey(), entry
140: .getValue());
141: }
142: writeTo(streamWriter);
143: } catch (JAXBException jbe) {
144: throw new XMLStreamException(jbe);
145: }
146: }
147:
148: }
|