1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.xml.bind.attachment; 27 28 import javax.activation.DataHandler; 29 30 /** 31 * <p>Enables JAXB unmarshalling of a root document containing optimized binary data formats.</p> 32 * 33 * <p>This API enables an efficient cooperative processing of optimized 34 * binary data formats between a JAXB 2.0 implementation and MIME-based package 35 * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the 36 * understanding of the packaging format being used to a MIME-based 37 * package processor that implements this abstract class.</p> 38 * 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> 40 * 41 * <h2>Identifying the content-id, cid, to pass to <code>getAttachment*(String cid)</code></h2> 42 * <ul> 43 * <li> 44 * For XOP processing, the infoset representation of the cid is described 45 * in step 2a in 46 * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#interpreting_xop_packages">Section 3.2 Interpreting XOP Packages</a> 47 * </li> 48 * <li> 49 * For WS-I AP 1.0, the cid is identified as an element or attribute of 50 * type <code>ref:swaRef </code> specified in 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> 52 * </li> 53 * </ul> 54 * 55 * @author Marc Hadley 56 * @author Kohsuke Kawaguchi 57 * @author Joseph Fialli 58 * 59 * @since 1.6, JAXB 2.0 60 * 61 * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller) 62 * 63 * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a> 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> 65 * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a> 66 */ 67 public abstract class AttachmentUnmarshaller { 68 /** 69 * <p>Lookup MIME content by content-id, <code>cid</code>, and return as a {@link DataHandler}.</p> 70 * 71 * <p>The returned <code>DataHandler</code> instance must be configured 72 * to meet the following required mapping constaint. 73 * <table summary="" border="2" rules="all" cellpadding="4"> 74 * <thead> 75 * <tr> 76 * <th align="center" colspan="2"> 77 * Required Mappings between MIME and Java Types 78 * </tr> 79 * <tr> 80 * <th>MIME Type</th> 81 * <th>Java Type</th> 82 * </tr> 83 * <tr> 84 * <th><code>DataHandler.getContentType()</code></th> 85 * <th><code>instanceof DataHandler.getContent()</code></th> 86 * </tr> 87 * </thead> 88 * <tbody> 89 * <tr> 90 * <td>image/gif</td> 91 * <td>java.awt.Image</td> 92 * </tr> 93 * <tr> 94 * <td>image/jpeg</td> 95 * <td>java.awt.Image</td> 96 * </tr> 97 * <tr> 98 * <td>text/xml or application/xml</td> 99 * <td>javax.xml.transform.Source</td> 100 * </tr> 101 * </tbody> 102 * </table> 103 * Note that it is allowable to support additional mappings. 104 * 105 * @param cid It is expected to be a valid lexical form of the XML Schema 106 * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()} 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>) 108 * 109 * @return 110 * a {@link DataHandler} that represents the MIME attachment. 111 * 112 * @throws IllegalArgumentException if the attachment for the given cid is not found. 113 */ 114 public abstract DataHandler getAttachmentAsDataHandler(String cid); 115 116 /** 117 * <p>Retrieve the attachment identified by content-id, <code>cid</code>, as a <tt>byte[]</tt></p>. 118 * 119 * @param cid It is expected to be a valid lexical form of the XML Schema 120 * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()} 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>) 122 * 123 * @return byte[] representation of attachment identified by cid. 124 * 125 * @throws IllegalArgumentException if the attachment for the given cid is not found. 126 */ 127 public abstract byte[] getAttachmentAsByteArray(String cid); 128 129 /** 130 * <p>Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.</p> 131 * 132 * <p>This method returns <code>true</code> when the constraints specified 133 * in <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying XOP Documents</a> are met. 134 * This value must not change during the unmarshalling process.</p> 135 * 136 * @return true when MIME context is a XOP Document. 137 */ 138 public boolean isXOPPackage() { return false; } 139 }