Home » xml-commons-external-1.4.01-src » javax » xml » bind » attachment » [javadoc | source]

    1   /*
    2    * Copyright 2005-2006 Sun Microsystems, Inc.  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.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   package javax.xml.bind.attachment;
   26   
   27   import javax.activation.DataHandler;
   28   
   29   /**
   30    * <p>Enables JAXB unmarshalling of a root document containing optimized binary data formats.</p>
   31    *
   32    * <p>This API enables an efficient cooperative processing of optimized
   33    * binary data formats between a JAXB 2.0 implementation and MIME-based package
   34    * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the
   35    * understanding of the packaging format being used to a MIME-based
   36    * package processor that implements this abstract class.</p>
   37    *
   38    * <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>
   39    *
   40    * <h2>Identifying the content-id, cid, to pass to <code>getAttachment*(String cid)</code></h2>
   41    * <ul>
   42    * <li>
   43    * For XOP processing, the infoset representation of the cid is described
   44    * in step 2a in
   45    * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#interpreting_xop_packages">Section 3.2 Interpreting XOP Packages</a>
   46    * </li>
   47    * <li>
   48    * For WS-I AP 1.0, the cid is identified as an element or attribute of
   49    * type <code>ref:swaRef </code> specified in
   50    * <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>
   51    * </li>
   52    * </ul>
   53    *
   54    * @author Marc Hadley
   55    * @author Kohsuke Kawaguchi
   56    * @author Joseph Fialli
   57    *
   58    * @since JAXB 2.0
   59    *
   60    * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller)
   61    *
   62    * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
   63    * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
   64    * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
   65    */
   66   public abstract class AttachmentUnmarshaller {
   67      /**
   68       * <p>Lookup MIME content by content-id, <code>cid</code>, and return as a {@link DataHandler}.</p>
   69       *
   70       * <p>The returned <code>DataHandler</code> instance must be configured
   71       * to meet the following required mapping constaint.
   72       * <table border="2" rules="all" cellpadding="4">
   73       *   <thead>
   74       *     <tr>
   75       *       <th align="center" colspan="2">
   76       *       Required Mappings between MIME and Java Types
   77       *       </tr>
   78       *     <tr>
   79       *       <th>MIME Type</th>
   80       *       <th>Java Type</th>
   81       *     </tr>
   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.</p>
  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   }

Home » xml-commons-external-1.4.01-src » javax » xml » bind » attachment » [javadoc | source]