325N/A/*
325N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage javax.xml.bind.attachment;
325N/A
325N/Aimport javax.activation.DataHandler;
325N/A
325N/A/**
325N/A * <p>Enables JAXB unmarshalling of a root document containing optimized binary data formats.</p>
325N/A *
325N/A * <p>This API enables an efficient cooperative processing of optimized
325N/A * binary data formats between a JAXB 2.0 implementation and MIME-based package
325N/A * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the
325N/A * understanding of the packaging format being used to a MIME-based
325N/A * package processor that implements this abstract class.</p>
325N/A *
325N/A * <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>
325N/A *
325N/A * <h2>Identifying the content-id, cid, to pass to <code>getAttachment*(String cid)</code></h2>
325N/A * <ul>
325N/A * <li>
325N/A * For XOP processing, the infoset representation of the cid is described
325N/A * in step 2a in
325N/A * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#interpreting_xop_packages">Section 3.2 Interpreting XOP Packages</a>
325N/A * </li>
325N/A * <li>
325N/A * For WS-I AP 1.0, the cid is identified as an element or attribute of
325N/A * type <code>ref:swaRef </code> specified in
325N/A * <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>
325N/A * </li>
325N/A * </ul>
325N/A *
325N/A * @author Marc Hadley
325N/A * @author Kohsuke Kawaguchi
325N/A * @author Joseph Fialli
325N/A *
325N/A * @since JAXB 2.0
325N/A *
325N/A * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller)
325N/A *
325N/A * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
325N/A * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
325N/A * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
325N/A */
325N/Apublic abstract class AttachmentUnmarshaller {
325N/A /**
325N/A * <p>Lookup MIME content by content-id, <code>cid</code>, and return as a {@link DataHandler}.</p>
325N/A *
325N/A * <p>The returned <code>DataHandler</code> instance must be configured
325N/A * to meet the following required mapping constaint.
325N/A * <table border="2" rules="all" cellpadding="4">
325N/A * <thead>
325N/A * <tr>
325N/A * <th align="center" colspan="2">
325N/A * Required Mappings between MIME and Java Types
325N/A * </tr>
325N/A * <tr>
325N/A * <th>MIME Type</th>
325N/A * <th>Java Type</th>
325N/A * </tr>
325N/A * <tr>
325N/A * <th><code>DataHandler.getContentType()</code></th>
325N/A * <th><code>instanceof DataHandler.getContent()</code></th>
325N/A * </tr>
325N/A * </thead>
325N/A * <tbody>
325N/A * <tr>
325N/A * <td>image/gif</td>
325N/A * <td>java.awt.Image</td>
325N/A * </tr>
325N/A * <tr>
325N/A * <td>image/jpeg</td>
325N/A * <td>java.awt.Image</td>
325N/A * </tr>
325N/A * <tr>
325N/A * <td>text/xml or application/xml</td>
325N/A * <td>javax.xml.transform.Source</td>
325N/A * </tr>
325N/A * </tbody>
325N/A * </table>
325N/A * Note that it is allowable to support additional mappings.</p>
325N/A *
325N/A * @param cid It is expected to be a valid lexical form of the XML Schema
325N/A * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()}
325N/A * ==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>)
325N/A *
325N/A * @return
325N/A * a {@link DataHandler} that represents the MIME attachment.
325N/A *
325N/A * @throws IllegalArgumentException if the attachment for the given cid is not found.
325N/A */
325N/A public abstract DataHandler getAttachmentAsDataHandler(String cid);
325N/A
325N/A /**
325N/A * <p>Retrieve the attachment identified by content-id, <code>cid</code>, as a <tt>byte[]</tt></p>.
325N/A *
325N/A * @param cid It is expected to be a valid lexical form of the XML Schema
325N/A * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()}
325N/A * ==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>)
325N/A *
325N/A * @return byte[] representation of attachment identified by cid.
325N/A *
325N/A * @throws IllegalArgumentException if the attachment for the given cid is not found.
325N/A */
325N/A public abstract byte[] getAttachmentAsByteArray(String cid);
325N/A
325N/A /**
325N/A * <p>Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.</p>
325N/A *
325N/A * <p>This method returns <code>true</code> when the constraints specified
325N/A * in <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying XOP Documents</a> are met.
325N/A * This value must not change during the unmarshalling process.</p>
325N/A *
325N/A * @return true when MIME context is a XOP Document.
325N/A */
325N/A public boolean isXOPPackage() { return false; }
325N/A}