1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/javax/xml/bind/attachment/AttachmentMarshaller.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,200 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package javax.xml.bind.attachment; 1.30 + 1.31 +import javax.activation.DataHandler; 1.32 +import javax.xml.bind.Marshaller; 1.33 + 1.34 +/** 1.35 + * <p>Enable JAXB marshalling to optimize storage of binary data.</p> 1.36 + * 1.37 + * <p>This API enables an efficient cooperative creation of optimized 1.38 + * binary data formats between a JAXB marshalling process and a MIME-based package 1.39 + * processor. A JAXB implementation marshals the root body of a MIME-based package, 1.40 + * delegating the creation of referenceable MIME parts to 1.41 + * the MIME-based package processor that implements this abstraction.</p> 1.42 + * 1.43 + * <p>XOP processing is enabled when {@link #isXOPPackage()} is true. 1.44 + * See {@link #addMtomAttachment(DataHandler, String, String)} for details. 1.45 + * </p> 1.46 + * 1.47 + * <p>WS-I Attachment Profile 1.0 is supported by 1.48 + * {@link #addSwaRefAttachment(DataHandler)} being called by the 1.49 + * marshaller for each JAXB property related to 1.50 + * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef.</p> 1.51 + * 1.52 + * 1.53 + * @author Marc Hadley 1.54 + * @author Kohsuke Kawaguchi 1.55 + * @author Joseph Fialli 1.56 + * @since JAXB 2.0 1.57 + * 1.58 + * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller) 1.59 + * 1.60 + * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a> 1.61 + * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a> 1.62 + */ 1.63 +public abstract class AttachmentMarshaller { 1.64 + 1.65 + /** 1.66 + * <p>Consider MIME content <code>data</code> for optimized binary storage as an attachment. 1.67 + * 1.68 + * <p> 1.69 + * This method is called by JAXB marshal process when {@link #isXOPPackage()} is 1.70 + * <code>true</code>, for each element whose datatype is "base64Binary", as described in 1.71 + * Step 3 in 1.72 + * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Packages</a>. 1.73 + * 1.74 + * <p> 1.75 + * The method implementor determines whether <code>data</code> shall be attached separately 1.76 + * or inlined as base64Binary data. If the implementation chooses to optimize the storage 1.77 + * of the binary data as a MIME part, it is responsible for attaching <code>data</code> to the 1.78 + * MIME-based package, and then assigning an unique content-id, cid, that identifies 1.79 + * the MIME part within the MIME message. This method returns the cid, 1.80 + * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place 1.81 + * of marshalling the binary data. When the method returns null, the JAXB marshaller 1.82 + * inlines <code>data</code> as base64binary data. 1.83 + * 1.84 + * <p> 1.85 + * The caller of this method is required to meet the following constraint. 1.86 + * If the element infoset item containing <code>data</code> has the attribute 1.87 + * <code>xmime:contentType</code> or if the JAXB property/field representing 1.88 + * <code>data</code>is annotated with a known MIME type, 1.89 + * <code>data.getContentType()</code> should be set to that MIME type. 1.90 + * 1.91 + * <p> 1.92 + * The <code>elementNamespace</code> and <code>elementLocalName</code> 1.93 + * parameters provide the 1.94 + * context that contains the binary data. This information could 1.95 + * be used by the MIME-based package processor to determine if the 1.96 + * binary data should be inlined or optimized as an attachment. 1.97 + * 1.98 + * @param data 1.99 + * represents the data to be attached. Must be non-null. 1.100 + * @param elementNamespace 1.101 + * the namespace URI of the element that encloses the base64Binary data. 1.102 + * Can be empty but never null. 1.103 + * @param elementLocalName 1.104 + * The local name of the element. Always a non-null valid string. 1.105 + * 1.106 + * @return 1.107 + * a valid content-id URI (see <a href="http://www.w3.org/TR/xop10/#RFC2387">RFC 2387</a>) that identifies the attachment containing <code>data</code>. 1.108 + * Otherwise, null if the attachment was not added and should instead be inlined in the message. 1.109 + * 1.110 + * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a> 1.111 + * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a> 1.112 + */ 1.113 + public abstract String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName); 1.114 + 1.115 + /** 1.116 + * <p>Consider binary <code>data</code> for optimized binary storage as an attachment. 1.117 + * 1.118 + * <p>Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream".</p> 1.119 + * 1.120 + * <p> 1.121 + * The <code>elementNamespace</code> and <code>elementLocalName</code> 1.122 + * parameters provide the 1.123 + * context that contains the binary data. This information could 1.124 + * be used by the MIME-based package processor to determine if the 1.125 + * binary data should be inlined or optimized as an attachment. 1.126 + * 1.127 + * @param data 1.128 + * represents the data to be attached. Must be non-null. The actual data region is 1.129 + * specified by <tt>(data,offset,length)</tt> tuple. 1.130 + * 1.131 + * @param offset 1.132 + * The offset within the array of the first byte to be read; 1.133 + * must be non-negative and no larger than array.length 1.134 + * 1.135 + * @param length 1.136 + * The number of bytes to be read from the given array; 1.137 + * must be non-negative and no larger than array.length 1.138 + * 1.139 + * @param mimeType 1.140 + * If the data has an associated MIME type known to JAXB, that is passed 1.141 + * as this parameter. If none is known, "application/octet-stream". 1.142 + * This parameter may never be null. 1.143 + * 1.144 + * @param elementNamespace 1.145 + * the namespace URI of the element that encloses the base64Binary data. 1.146 + * Can be empty but never null. 1.147 + * 1.148 + * @param elementLocalName 1.149 + * The local name of the element. Always a non-null valid string. 1.150 + * 1.151 + * @return content-id URI, cid, to the attachment containing 1.152 + * <code>data</code> or null if data should be inlined. 1.153 + * 1.154 + * @see #addMtomAttachment(DataHandler, String, String) 1.155 + */ 1.156 + public abstract String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName); 1.157 + 1.158 + /** 1.159 + * <p>Read-only property that returns true if JAXB marshaller should enable XOP creation.</p> 1.160 + * 1.161 + * <p>This value must not change during the marshalling process. When this 1.162 + * value is true, the <code>addMtomAttachment(...)</code> method 1.163 + * is invoked when the appropriate binary datatypes are encountered by 1.164 + * the marshal process.</p> 1.165 + * 1.166 + * <p>Marshaller.marshal() must throw IllegalStateException if this value is <code>true</code> 1.167 + * and the XML content to be marshalled violates Step 1 in 1.168 + * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a> 1.169 + * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages. 1.170 + * <i>"Ensure the Original XML Infoset contains no element information item with a 1.171 + * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include"</i> 1.172 + * 1.173 + * <p>When this method returns true and during the marshal process 1.174 + * at least one call to <code>addMtomAttachment(...)</code> returns 1.175 + * a content-id, the MIME-based package processor must label the 1.176 + * root part with the application/xop+xml media type as described in 1.177 + * Step 5 of 1.178 + * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>.<p> 1.179 + * 1.180 + * @return true when MIME context is a XOP Package. 1.181 + */ 1.182 + public boolean isXOPPackage() { return false; } 1.183 + 1.184 + /** 1.185 + * <p>Add MIME <code>data</code> as an attachment and return attachment's content-id, cid.</p> 1.186 + * 1.187 + * <p> 1.188 + * This method is called by JAXB marshal process for each element/attribute typed as 1.189 + * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor 1.190 + * implementing this method is responsible for attaching the specified data to a 1.191 + * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment 1.192 + * within the MIME-based package. 1.193 + * 1.194 + * <p>Caller inserts the returned content-id, cid, into the XML content being marshalled.</p> 1.195 + * 1.196 + * @param data 1.197 + * represents the data to be attached. Must be non-null. 1.198 + * @return 1.199 + * must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from 1.200 + * <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html#Referencing_Attachments_from_the_SOAP_Envelope">WS-I Attachments Profile Version 1.0.</a> 1.201 + */ 1.202 + public abstract String addSwaRefAttachment(DataHandler data); 1.203 +}