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