001 /*
002 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.xml.bind.attachment;
027
028 import javax.activation.DataHandler;
029
030 /**
031 * <p>Enables JAXB unmarshalling of a root document containing optimized binary data formats.</p>
032 *
033 * <p>This API enables an efficient cooperative processing of optimized
034 * binary data formats between a JAXB 2.0 implementation and MIME-based package
035 * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the
036 * understanding of the packaging format being used to a MIME-based
037 * package processor that implements this abstract class.</p>
038 *
039 * <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>
040 *
041 * <h2>Identifying the content-id, cid, to pass to <code>getAttachment*(String cid)</code></h2>
042 * <ul>
043 * <li>
044 * For XOP processing, the infoset representation of the cid is described
045 * in step 2a in
046 * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#interpreting_xop_packages">Section 3.2 Interpreting XOP Packages</a>
047 * </li>
048 * <li>
049 * For WS-I AP 1.0, the cid is identified as an element or attribute of
050 * type <code>ref:swaRef </code> specified in
051 * <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>
052 * </li>
053 * </ul>
054 *
055 * @author Marc Hadley
056 * @author Kohsuke Kawaguchi
057 * @author Joseph Fialli
058 *
059 * @since JAXB 2.0
060 *
061 * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller)
062 *
063 * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
064 * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
065 * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
066 */
067 public abstract class AttachmentUnmarshaller {
068 /**
069 * <p>Lookup MIME content by content-id, <code>cid</code>, and return as a {@link DataHandler}.</p>
070 *
071 * <p>The returned <code>DataHandler</code> instance must be configured
072 * to meet the following required mapping constaint.
073 * <table border="2" rules="all" cellpadding="4">
074 * <thead>
075 * <tr>
076 * <th align="center" colspan="2">
077 * Required Mappings between MIME and Java Types
078 * </tr>
079 * <tr>
080 * <th>MIME Type</th>
081 * <th>Java Type</th>
082 * </tr>
083 * </tr>
084 * <tr>
085 * <th><code>DataHandler.getContentType()</code></th>
086 * <th><code>instanceof DataHandler.getContent()</code></th>
087 * </tr>
088 * </thead>
089 * <tbody>
090 * <tr>
091 * <td>image/gif</td>
092 * <td>java.awt.Image</td>
093 * </tr>
094 * <tr>
095 * <td>image/jpeg</td>
096 * <td>java.awt.Image</td>
097 * </tr>
098 * <tr>
099 * <td>text/xml or application/xml</td>
100 * <td>javax.xml.transform.Source</td>
101 * </tr>
102 * </tbody>
103 * </table>
104 * Note that it is allowable to support additional mappings.</p>
105 *
106 * @param cid It is expected to be a valid lexical form of the XML Schema
107 * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()}
108 * ==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>)
109 *
110 * @return
111 * a {@link DataHandler} that represents the MIME attachment.
112 *
113 * @throws IllegalArgumentException if the attachment for the given cid is not found.
114 */
115 public abstract DataHandler getAttachmentAsDataHandler(String cid);
116
117 /**
118 * <p>Retrieve the attachment identified by content-id, <code>cid</code>, as a <tt>byte[]</tt></p>.
119 *
120 * @param cid It is expected to be a valid lexical form of the XML Schema
121 * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()}
122 * ==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>)
123 *
124 * @return byte[] representation of attachment identified by cid.
125 *
126 * @throws IllegalArgumentException if the attachment for the given cid is not found.
127 */
128 public abstract byte[] getAttachmentAsByteArray(String cid);
129
130 /**
131 * <p>Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.</p>
132 *
133 * <p>This method returns <code>true</code> when the constraints specified
134 * in <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying XOP Documents</a> are met.
135 * This value must not change during the unmarshalling process.</p>
136 *
137 * @return true when MIME context is a XOP Document.
138 */
139 public boolean isXOPPackage() {
140 return false;
141 }
142 }
|