001: package javax.xml.bind.attachment;
002:
003: import javax.activation.DataHandler;
004:
005: /**
006: * <p>Enables JAXB unmarshalling of a root document containing optimized binary data formats.</p>
007: *
008: * <p>This API enables an efficient cooperative processing of optimized
009: * binary data formats between a JAXB 2.0 implementation and MIME-based package
010: * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the
011: * understanding of the packaging format being used to a MIME-based
012: * package processor that implements this abstract class.</p>
013: *
014: * <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>
015: *
016: * <h2>Identifying the content-id, cid, to pass to <code>getAttachment*(String cid)</code></h2>
017: * <ul>
018: * <li>
019: * For XOP processing, the infoset representation of the cid is described
020: * in step 2a in
021: * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#interpreting_xop_packages">Section 3.2 Interpreting XOP Packages</a>
022: * </li>
023: * <li>
024: * For WS-I AP 1.0, the cid is identified as an element or attribute of
025: * type <code>ref:swaRef </code> specified in
026: * <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>
027: * </li>
028: * </ul>
029: *
030: * @author Marc Hadley
031: * @author Kohsuke Kawaguchi
032: * @author Joseph Fialli
033: *
034: * @since JAXB 2.0
035: *
036: * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller)
037: *
038: * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
039: * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
040: * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
041: */
042: public abstract class AttachmentUnmarshaller {
043: /**
044: * <p>Lookup MIME content by content-id, <code>cid</code>, and return as a {@link DataHandler}.</p>
045: *
046: * <p>The returned <code>DataHandler</code> instance must be configured
047: * to meet the following required mapping constaint.
048: * <table border="2" rules="all" cellpadding="4">
049: * <thead>
050: * <tr>
051: * <th align="center" colspan="2">
052: * Required Mappings between MIME and Java Types
053: * </tr>
054: * <tr>
055: * <th>MIME Type</th>
056: * <th>Java Type</th>
057: * </tr>
058: * </tr>
059: * <tr>
060: * <th><code>DataHandler.getContentType()</code></th>
061: * <th><code>instanceof DataHandler.getContent()</code></th>
062: * </tr>
063: * </thead>
064: * <tbody>
065: * <tr>
066: * <td>image/gif</td>
067: * <td>java.awt.Image</td>
068: * </tr>
069: * <tr>
070: * <td>image/jpeg</td>
071: * <td>java.awt.Image</td>
072: * </tr>
073: * <tr>
074: * <td>text/xml or application/xml</td>
075: * <td>javax.xml.transform.Source</td>
076: * </tr>
077: * </tbody>
078: * </table>
079: * Note that it is allowable to support additional mappings.</p>
080: *
081: * @param cid It is expected to be a valid lexical form of the XML Schema
082: * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()}
083: * ==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>)
084: *
085: * @return
086: * a {@link DataHandler} that represents the MIME attachment.
087: *
088: * @throws IllegalArgumentException if the attachment for the given cid is not found.
089: */
090: public abstract DataHandler getAttachmentAsDataHandler(String cid);
091:
092: /**
093: * <p>Retrieve the attachment identified by content-id, <code>cid</code>, as a <tt>byte[]</tt></p>.
094: *
095: * @param cid It is expected to be a valid lexical form of the XML Schema
096: * <code>xs:anyURI</code> datatype. If <code>{@link #isXOPPackage()}
097: * ==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>)
098: *
099: * @return byte[] representation of attachment identified by cid.
100: *
101: * @throws IllegalArgumentException if the attachment for the given cid is not found.
102: */
103: public abstract byte[] getAttachmentAsByteArray(String cid);
104:
105: /**
106: * <p>Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.</p>
107: *
108: * <p>This method returns <code>true</code> when the constraints specified
109: * in <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying XOP Documents</a> are met.
110: * This value must not change during the unmarshalling process.</p>
111: *
112: * @return true when MIME context is a XOP Document.
113: */
114: public boolean isXOPPackage() {
115: return false;
116: }
117: }
|