Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.xml.bind.attachment; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import javax.activation.DataHandler; |
aoqi@0 | 29 | import javax.xml.bind.Marshaller; |
aoqi@0 | 30 | |
aoqi@0 | 31 | /** |
aoqi@0 | 32 | * <p>Enable JAXB marshalling to optimize storage of binary data.</p> |
aoqi@0 | 33 | * |
aoqi@0 | 34 | * <p>This API enables an efficient cooperative creation of optimized |
aoqi@0 | 35 | * binary data formats between a JAXB marshalling process and a MIME-based package |
aoqi@0 | 36 | * processor. A JAXB implementation marshals the root body of a MIME-based package, |
aoqi@0 | 37 | * delegating the creation of referenceable MIME parts to |
aoqi@0 | 38 | * the MIME-based package processor that implements this abstraction.</p> |
aoqi@0 | 39 | * |
aoqi@0 | 40 | * <p>XOP processing is enabled when {@link #isXOPPackage()} is true. |
aoqi@0 | 41 | * See {@link #addMtomAttachment(DataHandler, String, String)} for details. |
aoqi@0 | 42 | * </p> |
aoqi@0 | 43 | * |
aoqi@0 | 44 | * <p>WS-I Attachment Profile 1.0 is supported by |
aoqi@0 | 45 | * {@link #addSwaRefAttachment(DataHandler)} being called by the |
aoqi@0 | 46 | * marshaller for each JAXB property related to |
aoqi@0 | 47 | * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef.</p> |
aoqi@0 | 48 | * |
aoqi@0 | 49 | * |
aoqi@0 | 50 | * @author Marc Hadley |
aoqi@0 | 51 | * @author Kohsuke Kawaguchi |
aoqi@0 | 52 | * @author Joseph Fialli |
aoqi@0 | 53 | * @since JAXB 2.0 |
aoqi@0 | 54 | * |
aoqi@0 | 55 | * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller) |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a> |
aoqi@0 | 58 | * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a> |
aoqi@0 | 59 | */ |
aoqi@0 | 60 | public abstract class AttachmentMarshaller { |
aoqi@0 | 61 | |
aoqi@0 | 62 | /** |
aoqi@0 | 63 | * <p>Consider MIME content <code>data</code> for optimized binary storage as an attachment. |
aoqi@0 | 64 | * |
aoqi@0 | 65 | * <p> |
aoqi@0 | 66 | * This method is called by JAXB marshal process when {@link #isXOPPackage()} is |
aoqi@0 | 67 | * <code>true</code>, for each element whose datatype is "base64Binary", as described in |
aoqi@0 | 68 | * Step 3 in |
aoqi@0 | 69 | * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Packages</a>. |
aoqi@0 | 70 | * |
aoqi@0 | 71 | * <p> |
aoqi@0 | 72 | * The method implementor determines whether <code>data</code> shall be attached separately |
aoqi@0 | 73 | * or inlined as base64Binary data. If the implementation chooses to optimize the storage |
aoqi@0 | 74 | * of the binary data as a MIME part, it is responsible for attaching <code>data</code> to the |
aoqi@0 | 75 | * MIME-based package, and then assigning an unique content-id, cid, that identifies |
aoqi@0 | 76 | * the MIME part within the MIME message. This method returns the cid, |
aoqi@0 | 77 | * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place |
aoqi@0 | 78 | * of marshalling the binary data. When the method returns null, the JAXB marshaller |
aoqi@0 | 79 | * inlines <code>data</code> as base64binary data. |
aoqi@0 | 80 | * |
aoqi@0 | 81 | * <p> |
aoqi@0 | 82 | * The caller of this method is required to meet the following constraint. |
aoqi@0 | 83 | * If the element infoset item containing <code>data</code> has the attribute |
aoqi@0 | 84 | * <code>xmime:contentType</code> or if the JAXB property/field representing |
aoqi@0 | 85 | * <code>data</code>is annotated with a known MIME type, |
aoqi@0 | 86 | * <code>data.getContentType()</code> should be set to that MIME type. |
aoqi@0 | 87 | * |
aoqi@0 | 88 | * <p> |
aoqi@0 | 89 | * The <code>elementNamespace</code> and <code>elementLocalName</code> |
aoqi@0 | 90 | * parameters provide the |
aoqi@0 | 91 | * context that contains the binary data. This information could |
aoqi@0 | 92 | * be used by the MIME-based package processor to determine if the |
aoqi@0 | 93 | * binary data should be inlined or optimized as an attachment. |
aoqi@0 | 94 | * |
aoqi@0 | 95 | * @param data |
aoqi@0 | 96 | * represents the data to be attached. Must be non-null. |
aoqi@0 | 97 | * @param elementNamespace |
aoqi@0 | 98 | * the namespace URI of the element that encloses the base64Binary data. |
aoqi@0 | 99 | * Can be empty but never null. |
aoqi@0 | 100 | * @param elementLocalName |
aoqi@0 | 101 | * The local name of the element. Always a non-null valid string. |
aoqi@0 | 102 | * |
aoqi@0 | 103 | * @return |
aoqi@0 | 104 | * 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>. |
aoqi@0 | 105 | * Otherwise, null if the attachment was not added and should instead be inlined in the message. |
aoqi@0 | 106 | * |
aoqi@0 | 107 | * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a> |
aoqi@0 | 108 | * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a> |
aoqi@0 | 109 | */ |
aoqi@0 | 110 | public abstract String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName); |
aoqi@0 | 111 | |
aoqi@0 | 112 | /** |
aoqi@0 | 113 | * <p>Consider binary <code>data</code> for optimized binary storage as an attachment. |
aoqi@0 | 114 | * |
aoqi@0 | 115 | * <p>Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream".</p> |
aoqi@0 | 116 | * |
aoqi@0 | 117 | * <p> |
aoqi@0 | 118 | * The <code>elementNamespace</code> and <code>elementLocalName</code> |
aoqi@0 | 119 | * parameters provide the |
aoqi@0 | 120 | * context that contains the binary data. This information could |
aoqi@0 | 121 | * be used by the MIME-based package processor to determine if the |
aoqi@0 | 122 | * binary data should be inlined or optimized as an attachment. |
aoqi@0 | 123 | * |
aoqi@0 | 124 | * @param data |
aoqi@0 | 125 | * represents the data to be attached. Must be non-null. The actual data region is |
aoqi@0 | 126 | * specified by <tt>(data,offset,length)</tt> tuple. |
aoqi@0 | 127 | * |
aoqi@0 | 128 | * @param offset |
aoqi@0 | 129 | * The offset within the array of the first byte to be read; |
aoqi@0 | 130 | * must be non-negative and no larger than array.length |
aoqi@0 | 131 | * |
aoqi@0 | 132 | * @param length |
aoqi@0 | 133 | * The number of bytes to be read from the given array; |
aoqi@0 | 134 | * must be non-negative and no larger than array.length |
aoqi@0 | 135 | * |
aoqi@0 | 136 | * @param mimeType |
aoqi@0 | 137 | * If the data has an associated MIME type known to JAXB, that is passed |
aoqi@0 | 138 | * as this parameter. If none is known, "application/octet-stream". |
aoqi@0 | 139 | * This parameter may never be null. |
aoqi@0 | 140 | * |
aoqi@0 | 141 | * @param elementNamespace |
aoqi@0 | 142 | * the namespace URI of the element that encloses the base64Binary data. |
aoqi@0 | 143 | * Can be empty but never null. |
aoqi@0 | 144 | * |
aoqi@0 | 145 | * @param elementLocalName |
aoqi@0 | 146 | * The local name of the element. Always a non-null valid string. |
aoqi@0 | 147 | * |
aoqi@0 | 148 | * @return content-id URI, cid, to the attachment containing |
aoqi@0 | 149 | * <code>data</code> or null if data should be inlined. |
aoqi@0 | 150 | * |
aoqi@0 | 151 | * @see #addMtomAttachment(DataHandler, String, String) |
aoqi@0 | 152 | */ |
aoqi@0 | 153 | public abstract String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName); |
aoqi@0 | 154 | |
aoqi@0 | 155 | /** |
aoqi@0 | 156 | * <p>Read-only property that returns true if JAXB marshaller should enable XOP creation.</p> |
aoqi@0 | 157 | * |
aoqi@0 | 158 | * <p>This value must not change during the marshalling process. When this |
aoqi@0 | 159 | * value is true, the <code>addMtomAttachment(...)</code> method |
aoqi@0 | 160 | * is invoked when the appropriate binary datatypes are encountered by |
aoqi@0 | 161 | * the marshal process.</p> |
aoqi@0 | 162 | * |
aoqi@0 | 163 | * <p>Marshaller.marshal() must throw IllegalStateException if this value is <code>true</code> |
aoqi@0 | 164 | * and the XML content to be marshalled violates Step 1 in |
aoqi@0 | 165 | * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a> |
aoqi@0 | 166 | * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages. |
aoqi@0 | 167 | * <i>"Ensure the Original XML Infoset contains no element information item with a |
aoqi@0 | 168 | * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include"</i> |
aoqi@0 | 169 | * |
aoqi@0 | 170 | * <p>When this method returns true and during the marshal process |
aoqi@0 | 171 | * at least one call to <code>addMtomAttachment(...)</code> returns |
aoqi@0 | 172 | * a content-id, the MIME-based package processor must label the |
aoqi@0 | 173 | * root part with the application/xop+xml media type as described in |
aoqi@0 | 174 | * Step 5 of |
aoqi@0 | 175 | * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>.<p> |
aoqi@0 | 176 | * |
aoqi@0 | 177 | * @return true when MIME context is a XOP Package. |
aoqi@0 | 178 | */ |
aoqi@0 | 179 | public boolean isXOPPackage() { return false; } |
aoqi@0 | 180 | |
aoqi@0 | 181 | /** |
aoqi@0 | 182 | * <p>Add MIME <code>data</code> as an attachment and return attachment's content-id, cid.</p> |
aoqi@0 | 183 | * |
aoqi@0 | 184 | * <p> |
aoqi@0 | 185 | * This method is called by JAXB marshal process for each element/attribute typed as |
aoqi@0 | 186 | * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor |
aoqi@0 | 187 | * implementing this method is responsible for attaching the specified data to a |
aoqi@0 | 188 | * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment |
aoqi@0 | 189 | * within the MIME-based package. |
aoqi@0 | 190 | * |
aoqi@0 | 191 | * <p>Caller inserts the returned content-id, cid, into the XML content being marshalled.</p> |
aoqi@0 | 192 | * |
aoqi@0 | 193 | * @param data |
aoqi@0 | 194 | * represents the data to be attached. Must be non-null. |
aoqi@0 | 195 | * @return |
aoqi@0 | 196 | * must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from |
aoqi@0 | 197 | * <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> |
aoqi@0 | 198 | */ |
aoqi@0 | 199 | public abstract String addSwaRefAttachment(DataHandler data); |
aoqi@0 | 200 | } |