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 | |
aoqi@0 | 30 | /** |
aoqi@0 | 31 | * <p>Enables JAXB unmarshalling of a root document containing optimized binary data formats.</p> |
aoqi@0 | 32 | * |
aoqi@0 | 33 | * <p>This API enables an efficient cooperative processing of optimized |
aoqi@0 | 34 | * binary data formats between a JAXB 2.0 implementation and MIME-based package |
aoqi@0 | 35 | * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the |
aoqi@0 | 36 | * understanding of the packaging format being used to a MIME-based |
aoqi@0 | 37 | * package processor that implements this abstract class.</p> |
aoqi@0 | 38 | * |
aoqi@0 | 39 | * <p>This abstract class identifies if a package requires XOP processing, {@link #isXOPPackage()} and provides retrieval of binary content stored as attachments by content-id.</p> |
aoqi@0 | 40 | * |
aoqi@0 | 41 | * <h2>Identifying the content-id, cid, to pass to <code>getAttachment*(String cid)</code></h2> |
aoqi@0 | 42 | * <ul> |
aoqi@0 | 43 | * <li> |
aoqi@0 | 44 | * For XOP processing, the infoset representation of the cid is described |
aoqi@0 | 45 | * in step 2a in |
aoqi@0 | 46 | * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#interpreting_xop_packages">Section 3.2 Interpreting XOP Packages</a> |
aoqi@0 | 47 | * </li> |
aoqi@0 | 48 | * <li> |
aoqi@0 | 49 | * For WS-I AP 1.0, the cid is identified as an element or attribute of |
aoqi@0 | 50 | * type <code>ref:swaRef </code> specified in |
aoqi@0 | 51 | * <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html#Referencing_Attachments_from_the_SOAP_Envelope">Section 4.4 Referencing Attachments from the SOAP Envelope</a> |
aoqi@0 | 52 | * </li> |
aoqi@0 | 53 | * </ul> |
aoqi@0 | 54 | * |
aoqi@0 | 55 | * @author Marc Hadley |
aoqi@0 | 56 | * @author Kohsuke Kawaguchi |
aoqi@0 | 57 | * @author Joseph Fialli |
aoqi@0 | 58 | * |
aoqi@0 | 59 | * @since JAXB 2.0 |
aoqi@0 | 60 | * |
aoqi@0 | 61 | * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller) |
aoqi@0 | 62 | * |
aoqi@0 | 63 | * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a> |
aoqi@0 | 64 | * @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 | 65 | * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a> |
aoqi@0 | 66 | */ |
aoqi@0 | 67 | public abstract class AttachmentUnmarshaller { |
aoqi@0 | 68 | /** |
aoqi@0 | 69 | * <p>Lookup MIME content by content-id, <code>cid</code>, and return as a {@link DataHandler}.</p> |
aoqi@0 | 70 | * |
aoqi@0 | 71 | * <p>The returned <code>DataHandler</code> instance must be configured |
aoqi@0 | 72 | * to meet the following required mapping constaint. |
aoqi@0 | 73 | * <table border="2" rules="all" cellpadding="4"> |
aoqi@0 | 74 | * <thead> |
aoqi@0 | 75 | * <tr> |
aoqi@0 | 76 | * <th align="center" colspan="2"> |
aoqi@0 | 77 | * Required Mappings between MIME and Java Types |
aoqi@0 | 78 | * </tr> |
aoqi@0 | 79 | * <tr> |
aoqi@0 | 80 | * <th>MIME Type</th> |
aoqi@0 | 81 | * <th>Java Type</th> |
aoqi@0 | 82 | * </tr> |
aoqi@0 | 83 | * <tr> |
aoqi@0 | 84 | * <th><code>DataHandler.getContentType()</code></th> |
aoqi@0 | 85 | * <th><code>instanceof DataHandler.getContent()</code></th> |
aoqi@0 | 86 | * </tr> |
aoqi@0 | 87 | * </thead> |
aoqi@0 | 88 | * <tbody> |
aoqi@0 | 89 | * <tr> |
aoqi@0 | 90 | * <td>image/gif</td> |
aoqi@0 | 91 | * <td>java.awt.Image</td> |
aoqi@0 | 92 | * </tr> |
aoqi@0 | 93 | * <tr> |
aoqi@0 | 94 | * <td>image/jpeg</td> |
aoqi@0 | 95 | * <td>java.awt.Image</td> |
aoqi@0 | 96 | * </tr> |
aoqi@0 | 97 | * <tr> |
aoqi@0 | 98 | * <td>text/xml or application/xml</td> |
aoqi@0 | 99 | * <td>javax.xml.transform.Source</td> |
aoqi@0 | 100 | * </tr> |
aoqi@0 | 101 | * </tbody> |
aoqi@0 | 102 | * </table> |
aoqi@0 | 103 | * Note that it is allowable to support additional mappings.</p> |
aoqi@0 | 104 | * |
aoqi@0 | 105 | * @param cid It is expected to be a valid lexical form of the XML Schema |
aoqi@0 | 106 | * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()} |
aoqi@0 | 107 | * ==true</code>, it must be a valid URI per the <code>cid:</code> URI scheme (see <a href="http://www.ietf.org/rfc/rfc2387.txt">RFC 2387</a>) |
aoqi@0 | 108 | * |
aoqi@0 | 109 | * @return |
aoqi@0 | 110 | * a {@link DataHandler} that represents the MIME attachment. |
aoqi@0 | 111 | * |
aoqi@0 | 112 | * @throws IllegalArgumentException if the attachment for the given cid is not found. |
aoqi@0 | 113 | */ |
aoqi@0 | 114 | public abstract DataHandler getAttachmentAsDataHandler(String cid); |
aoqi@0 | 115 | |
aoqi@0 | 116 | /** |
aoqi@0 | 117 | * <p>Retrieve the attachment identified by content-id, <code>cid</code>, as a <tt>byte[]</tt></p>. |
aoqi@0 | 118 | * |
aoqi@0 | 119 | * @param cid It is expected to be a valid lexical form of the XML Schema |
aoqi@0 | 120 | * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()} |
aoqi@0 | 121 | * ==true</code>, it must be a valid URI per the <code>cid:</code> URI scheme (see <a href="http://www.ietf.org/rfc/rfc2387.txt">RFC 2387</a>) |
aoqi@0 | 122 | * |
aoqi@0 | 123 | * @return byte[] representation of attachment identified by cid. |
aoqi@0 | 124 | * |
aoqi@0 | 125 | * @throws IllegalArgumentException if the attachment for the given cid is not found. |
aoqi@0 | 126 | */ |
aoqi@0 | 127 | public abstract byte[] getAttachmentAsByteArray(String cid); |
aoqi@0 | 128 | |
aoqi@0 | 129 | /** |
aoqi@0 | 130 | * <p>Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.</p> |
aoqi@0 | 131 | * |
aoqi@0 | 132 | * <p>This method returns <code>true</code> when the constraints specified |
aoqi@0 | 133 | * in <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying XOP Documents</a> are met. |
aoqi@0 | 134 | * This value must not change during the unmarshalling process.</p> |
aoqi@0 | 135 | * |
aoqi@0 | 136 | * @return true when MIME context is a XOP Document. |
aoqi@0 | 137 | */ |
aoqi@0 | 138 | public boolean isXOPPackage() { return false; } |
aoqi@0 | 139 | } |