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