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   import javax.xml.bind.Marshaller;
   29   
   30   /**
   31    * <p>Enable JAXB marshalling to optimize storage of binary data.</p>
   32    *
   33    * <p>This API enables an efficient cooperative creation of optimized
   34    * binary data formats between a JAXB marshalling process and a MIME-based package
   35    * processor. A JAXB implementation marshals the root body of a MIME-based package,
   36    * delegating the creation of referenceable MIME parts to
   37    * the MIME-based package processor that implements this abstraction.</p>
   38    *
   39    * <p>XOP processing is enabled when {@link #isXOPPackage()} is true.
   40    *    See {@link #addMtomAttachment(DataHandler, String, String)} for details.
   41    * </p>
   42    *
   43    * <p>WS-I Attachment Profile 1.0 is supported by
   44    * {@link #addSwaRefAttachment(DataHandler)} being called by the
   45    * marshaller for each JAXB property related to
   46    * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef.</p>
   47    *
   48    *
   49    * @author Marc Hadley
   50    * @author Kohsuke Kawaguchi
   51    * @author Joseph Fialli
   52    * @since JAXB 2.0
   53    *
   54    * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller)
   55    *
   56    * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
   57    * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
   58    */
   59   public abstract class AttachmentMarshaller {
   60   
   61       /**
   62        * <p>Consider MIME content <code>data</code> for optimized binary storage as an attachment.
   63        *
   64        * <p>
   65        * This method is called by JAXB marshal process when {@link #isXOPPackage()} is
   66        * <code>true</code>, for each element whose datatype is "base64Binary", as described in
   67        * Step 3 in
   68        * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Packages</a>.
   69        *
   70        * <p>
   71        * The method implementor determines whether <code>data</code> shall be attached separately
   72        * or inlined as base64Binary data. If the implementation chooses to optimize the storage
   73        * of the binary data as a MIME part, it is responsible for attaching <code>data</code> to the
   74        * MIME-based package, and then assigning an unique content-id, cid, that identifies
   75        * the MIME part within the MIME message. This method returns the cid,
   76        * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place
   77        * of marshalling the binary data. When the method returns null, the JAXB marshaller
   78        * inlines <code>data</code> as base64binary data.
   79        *
   80        * <p>
   81        * The caller of this method is required to meet the following constraint.
   82        * If the element infoset item containing <code>data</code> has the attribute
   83        * <code>xmime:contentType</code> or if the JAXB property/field representing
   84        * <code>data</code>is annotated with a known MIME type,
   85        * <code>data.getContentType()</code> should be set to that MIME type.
   86        *
   87        * <p>
   88        * The <code>elementNamespace</code> and <code>elementLocalName</code>
   89        * parameters provide the
   90        * context that contains the binary data. This information could
   91        * be used by the MIME-based package processor to determine if the
   92        * binary data should be inlined or optimized as an attachment.
   93        *
   94        * @param data
   95        *       represents the data to be attached. Must be non-null.
   96        * @param elementNamespace
   97        *      the namespace URI of the element that encloses the base64Binary data.
   98        *      Can be empty but never null.
   99        * @param elementLocalName
  100        *      The local name of the element. Always a non-null valid string.
  101        *
  102        * @return
  103        *     a valid content-id URI (see <a href="http://www.w3.org/TR/xop10/#RFC2387">RFC 2387</a>) that identifies the attachment containing <code>data</code>.
  104        *     Otherwise, null if the attachment was not added and should instead be inlined in the message.
  105        *
  106        * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
  107        * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
  108        */
  109       public abstract String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName);
  110   
  111       /**
  112        * <p>Consider binary <code>data</code> for optimized binary storage as an attachment.
  113        *
  114        * <p>Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream".</p>
  115        *
  116        * <p>
  117        * The <code>elementNamespace</code> and <code>elementLocalName</code>
  118        * parameters provide the
  119        * context that contains the binary data. This information could
  120        * be used by the MIME-based package processor to determine if the
  121        * binary data should be inlined or optimized as an attachment.
  122        *
  123        * @param data
  124        *      represents the data to be attached. Must be non-null. The actual data region is
  125        *      specified by <tt>(data,offset,length)</tt> tuple.
  126        *
  127        * @param offset
  128        *       The offset within the array of the first byte to be read;
  129        *       must be non-negative and no larger than array.length
  130        *
  131        * @param length
  132        *       The number of bytes to be read from the given array;
  133        *       must be non-negative and no larger than array.length
  134        *
  135        * @param mimeType
  136        *      If the data has an associated MIME type known to JAXB, that is passed
  137        *      as this parameter. If none is known, "application/octet-stream".
  138        *      This parameter may never be null.
  139        *
  140        * @param elementNamespace
  141        *      the namespace URI of the element that encloses the base64Binary data.
  142        *      Can be empty but never null.
  143        *
  144        * @param elementLocalName
  145        *      The local name of the element. Always a non-null valid string.
  146        *
  147        * @return content-id URI, cid, to the attachment containing
  148        *         <code>data</code> or null if data should be inlined.
  149        *
  150        * @see #addMtomAttachment(DataHandler, String, String)
  151        */
  152       public abstract String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName);
  153   
  154       /**
  155        * <p>Read-only property that returns true if JAXB marshaller should enable XOP creation.</p>
  156        *
  157        * <p>This value must not change during the marshalling process. When this
  158        * value is true, the <code>addMtomAttachment(...)</code> method
  159        * is invoked when the appropriate binary datatypes are encountered by
  160        * the marshal process.</p>
  161        *
  162        * <p>Marshaller.marshal() must throw IllegalStateException if this value is <code>true</code>
  163        * and the XML content to be marshalled violates Step 1 in
  164        * <a ref="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>
  165        * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages.
  166        * <i>"Ensure the Original XML Infoset contains no element information item with a
  167        * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include"</i>
  168        *
  169        * <p>When this method returns true and during the marshal process
  170        * at least one call to <code>addMtomAttachment(...)</code> returns
  171        * a content-id, the MIME-based package processor must label the
  172        * root part with the application/xop+xml media type as described in
  173        * Step 5 of
  174        * <a ref="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>.<p>
  175        *
  176        * @return true when MIME context is a XOP Package.
  177        */
  178       public boolean isXOPPackage() { return false; }
  179   
  180      /**
  181       * <p>Add MIME <code>data</code> as an attachment and return attachment's content-id, cid.</p>
  182       *
  183       * <p>
  184       * This method is called by JAXB marshal process for each element/attribute typed as
  185       * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor
  186       * implementing this method is responsible for attaching the specified data to a
  187       * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment
  188       * within the MIME-based package.
  189       *
  190       * <p>Caller inserts the returned content-id, cid, into the XML content being marshalled.</p>
  191       *
  192       * @param data
  193       *       represents the data to be attached. Must be non-null.
  194       * @return
  195       *       must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from
  196       *       <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html#Referencing_Attachments_from_the_SOAP_Envelope">WS-I Attachments Profile Version 1.0.</a>
  197       */
  198       public abstract String addSwaRefAttachment(DataHandler data);
  199   }

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