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: /*
024: * X509IssuerSerial.java
025: *
026: * Created on August 16, 2006, 4:19 PM
027: *
028: * To change this template, choose Tools | Template Manager
029: * and open the template in the editor.
030: */
031:
032: package com.sun.xml.ws.security.opt.impl.reference;
033:
034: import com.sun.xml.security.core.dsig.X509IssuerSerialType;
035: import com.sun.xml.stream.buffer.XMLStreamBufferResult;
036: import com.sun.xml.ws.api.SOAPVersion;
037: import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
038: import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
039: import com.sun.xml.ws.security.opt.api.reference.Reference;
040: import com.sun.xml.ws.security.opt.impl.util.JAXBUtil;
041: import com.sun.xml.wss.impl.MessageConstants;
042: import java.io.OutputStream;
043: import java.util.HashMap;
044: import java.util.Iterator;
045: import java.util.Map;
046: import javax.xml.bind.JAXBElement;
047: import javax.xml.bind.JAXBException;
048: import javax.xml.bind.Marshaller;
049: import javax.xml.stream.XMLStreamException;
050: import javax.xml.stream.XMLStreamReader;
051: import javax.xml.stream.XMLStreamWriter;
052: import com.sun.xml.security.core.dsig.ObjectFactory;
053:
054: /**
055: *
056: * @author Ashutosh.Shahi@sun.com
057: */
058: public class X509IssuerSerial
059: extends
060: com.sun.xml.ws.security.opt.crypto.dsig.keyinfo.X509IssuerSerial
061: implements SecurityHeaderElement, SecurityElementWriter {
062:
063: private SOAPVersion soapVersion = SOAPVersion.SOAP_11;
064:
065: /** Creates a new instance of X509IssuerSerial */
066: public X509IssuerSerial(SOAPVersion sv) {
067: this .soapVersion = sv;
068: }
069:
070: public boolean refersToSecHdrWithId(final String id) {
071: return false;
072: }
073:
074: public String getId() {
075: throw new UnsupportedOperationException();
076: }
077:
078: public void setId(final String id) {
079: throw new UnsupportedOperationException();
080: }
081:
082: public String getNamespaceURI() {
083: return MessageConstants.DSIG_NS;
084: }
085:
086: public String getLocalPart() {
087: return "X509IssuerSerial".intern();
088: }
089:
090: public XMLStreamReader readHeader() throws XMLStreamException {
091: XMLStreamBufferResult xbr = new XMLStreamBufferResult();
092: JAXBElement<com.sun.xml.ws.security.opt.crypto.dsig.keyinfo.X509IssuerSerial> issuerSerialElem = new ObjectFactory()
093: .createX509DataTypeX509IssuerSerial(this );
094: try {
095: getMarshaller().marshal(issuerSerialElem, xbr);
096:
097: } catch (JAXBException je) {
098: throw new XMLStreamException(je);
099: }
100: return xbr.getXMLStreamBuffer().readAsXMLStreamReader();
101: }
102:
103: public void writeTo(XMLStreamWriter streamWriter)
104: throws XMLStreamException {
105: JAXBElement<com.sun.xml.ws.security.opt.crypto.dsig.keyinfo.X509IssuerSerial> issuerSerialElem = new ObjectFactory()
106: .createX509DataTypeX509IssuerSerial(this );
107: try {
108: // If writing to Zephyr, get output stream and use JAXB UTF-8 writer
109: if (streamWriter instanceof Map) {
110: OutputStream os = (OutputStream) ((Map) streamWriter)
111: .get("sjsxp-outputstream");
112: if (os != null) {
113: streamWriter.writeCharacters(""); // Force completion of open elems
114: getMarshaller().marshal(issuerSerialElem, os);
115: return;
116: }
117: }
118:
119: getMarshaller().marshal(issuerSerialElem, streamWriter);
120: } catch (JAXBException e) {
121: throw new XMLStreamException(e);
122: }
123: }
124:
125: public void writeTo(XMLStreamWriter streamWriter, HashMap props)
126: throws XMLStreamException {
127: try {
128: Marshaller marshaller = getMarshaller();
129: Iterator<Map.Entry<Object, Object>> itr = props.entrySet()
130: .iterator();
131: while (itr.hasNext()) {
132: Map.Entry<Object, Object> entry = itr.next();
133: marshaller.setProperty((String) entry.getKey(), entry
134: .getValue());
135: }
136: writeTo(streamWriter);
137: } catch (JAXBException jbe) {
138: throw new XMLStreamException(jbe);
139: }
140: }
141:
142: public void writeTo(OutputStream os) {
143: }
144:
145: private Marshaller getMarshaller() throws JAXBException {
146: return JAXBUtil.createMarshaller(soapVersion);
147: }
148:
149: }
|