aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package javax.xml.bind.attachment; aoqi@0: aoqi@0: import javax.activation.DataHandler; aoqi@0: import javax.xml.bind.Marshaller; aoqi@0: aoqi@0: /** aoqi@0: *

Enable JAXB marshalling to optimize storage of binary data.

aoqi@0: * aoqi@0: *

This API enables an efficient cooperative creation of optimized aoqi@0: * binary data formats between a JAXB marshalling process and a MIME-based package aoqi@0: * processor. A JAXB implementation marshals the root body of a MIME-based package, aoqi@0: * delegating the creation of referenceable MIME parts to aoqi@0: * the MIME-based package processor that implements this abstraction.

aoqi@0: * aoqi@0: *

XOP processing is enabled when {@link #isXOPPackage()} is true. aoqi@0: * See {@link #addMtomAttachment(DataHandler, String, String)} for details. aoqi@0: *

aoqi@0: * aoqi@0: *

WS-I Attachment Profile 1.0 is supported by aoqi@0: * {@link #addSwaRefAttachment(DataHandler)} being called by the aoqi@0: * marshaller for each JAXB property related to aoqi@0: * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef.

aoqi@0: * aoqi@0: * aoqi@0: * @author Marc Hadley aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: * @author Joseph Fialli aoqi@0: * @since JAXB 2.0 aoqi@0: * aoqi@0: * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller) aoqi@0: * aoqi@0: * @see XML-binary Optimized Packaging aoqi@0: * @see WS-I Attachments Profile Version 1.0. aoqi@0: */ aoqi@0: public abstract class AttachmentMarshaller { aoqi@0: aoqi@0: /** aoqi@0: *

Consider MIME content data for optimized binary storage as an attachment. aoqi@0: * aoqi@0: *

aoqi@0: * This method is called by JAXB marshal process when {@link #isXOPPackage()} is aoqi@0: * true, for each element whose datatype is "base64Binary", as described in aoqi@0: * Step 3 in aoqi@0: * Creating XOP Packages. aoqi@0: * aoqi@0: *

aoqi@0: * The method implementor determines whether data shall be attached separately aoqi@0: * or inlined as base64Binary data. If the implementation chooses to optimize the storage aoqi@0: * of the binary data as a MIME part, it is responsible for attaching data to the aoqi@0: * MIME-based package, and then assigning an unique content-id, cid, that identifies aoqi@0: * the MIME part within the MIME message. This method returns the cid, aoqi@0: * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place aoqi@0: * of marshalling the binary data. When the method returns null, the JAXB marshaller aoqi@0: * inlines data as base64binary data. aoqi@0: * aoqi@0: *

aoqi@0: * The caller of this method is required to meet the following constraint. aoqi@0: * If the element infoset item containing data has the attribute aoqi@0: * xmime:contentType or if the JAXB property/field representing aoqi@0: * datais annotated with a known MIME type, aoqi@0: * data.getContentType() should be set to that MIME type. aoqi@0: * aoqi@0: *

aoqi@0: * The elementNamespace and elementLocalName aoqi@0: * parameters provide the aoqi@0: * context that contains the binary data. This information could aoqi@0: * be used by the MIME-based package processor to determine if the aoqi@0: * binary data should be inlined or optimized as an attachment. aoqi@0: * aoqi@0: * @param data aoqi@0: * represents the data to be attached. Must be non-null. aoqi@0: * @param elementNamespace aoqi@0: * the namespace URI of the element that encloses the base64Binary data. aoqi@0: * Can be empty but never null. aoqi@0: * @param elementLocalName aoqi@0: * The local name of the element. Always a non-null valid string. aoqi@0: * aoqi@0: * @return aoqi@0: * a valid content-id URI (see RFC 2387) that identifies the attachment containing data. aoqi@0: * Otherwise, null if the attachment was not added and should instead be inlined in the message. aoqi@0: * aoqi@0: * @see XML-binary Optimized Packaging aoqi@0: * @see Describing Media Content of Binary Data in XML aoqi@0: */ aoqi@0: public abstract String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName); aoqi@0: aoqi@0: /** aoqi@0: *

Consider binary data for optimized binary storage as an attachment. aoqi@0: * aoqi@0: *

Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream".

aoqi@0: * aoqi@0: *

aoqi@0: * The elementNamespace and elementLocalName aoqi@0: * parameters provide the aoqi@0: * context that contains the binary data. This information could aoqi@0: * be used by the MIME-based package processor to determine if the aoqi@0: * binary data should be inlined or optimized as an attachment. aoqi@0: * aoqi@0: * @param data aoqi@0: * represents the data to be attached. Must be non-null. The actual data region is aoqi@0: * specified by (data,offset,length) tuple. aoqi@0: * aoqi@0: * @param offset aoqi@0: * The offset within the array of the first byte to be read; aoqi@0: * must be non-negative and no larger than array.length aoqi@0: * aoqi@0: * @param length aoqi@0: * The number of bytes to be read from the given array; aoqi@0: * must be non-negative and no larger than array.length aoqi@0: * aoqi@0: * @param mimeType aoqi@0: * If the data has an associated MIME type known to JAXB, that is passed aoqi@0: * as this parameter. If none is known, "application/octet-stream". aoqi@0: * This parameter may never be null. aoqi@0: * aoqi@0: * @param elementNamespace aoqi@0: * the namespace URI of the element that encloses the base64Binary data. aoqi@0: * Can be empty but never null. aoqi@0: * aoqi@0: * @param elementLocalName aoqi@0: * The local name of the element. Always a non-null valid string. aoqi@0: * aoqi@0: * @return content-id URI, cid, to the attachment containing aoqi@0: * data or null if data should be inlined. aoqi@0: * aoqi@0: * @see #addMtomAttachment(DataHandler, String, String) aoqi@0: */ aoqi@0: public abstract String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName); aoqi@0: aoqi@0: /** aoqi@0: *

Read-only property that returns true if JAXB marshaller should enable XOP creation.

aoqi@0: * aoqi@0: *

This value must not change during the marshalling process. When this aoqi@0: * value is true, the addMtomAttachment(...) method aoqi@0: * is invoked when the appropriate binary datatypes are encountered by aoqi@0: * the marshal process.

aoqi@0: * aoqi@0: *

Marshaller.marshal() must throw IllegalStateException if this value is true aoqi@0: * and the XML content to be marshalled violates Step 1 in aoqi@0: * Creating XOP Pacakges aoqi@0: * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages. aoqi@0: * "Ensure the Original XML Infoset contains no element information item with a aoqi@0: * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include" aoqi@0: * aoqi@0: *

When this method returns true and during the marshal process aoqi@0: * at least one call to addMtomAttachment(...) returns aoqi@0: * a content-id, the MIME-based package processor must label the aoqi@0: * root part with the application/xop+xml media type as described in aoqi@0: * Step 5 of aoqi@0: * Creating XOP Pacakges.

aoqi@0: * aoqi@0: * @return true when MIME context is a XOP Package. aoqi@0: */ aoqi@0: public boolean isXOPPackage() { return false; } aoqi@0: aoqi@0: /** aoqi@0: *

Add MIME data as an attachment and return attachment's content-id, cid.

aoqi@0: * aoqi@0: *

aoqi@0: * This method is called by JAXB marshal process for each element/attribute typed as aoqi@0: * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor aoqi@0: * implementing this method is responsible for attaching the specified data to a aoqi@0: * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment aoqi@0: * within the MIME-based package. aoqi@0: * aoqi@0: *

Caller inserts the returned content-id, cid, into the XML content being marshalled.

aoqi@0: * aoqi@0: * @param data aoqi@0: * represents the data to be attached. Must be non-null. aoqi@0: * @return aoqi@0: * must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from aoqi@0: * WS-I Attachments Profile Version 1.0. aoqi@0: */ aoqi@0: public abstract String addSwaRefAttachment(DataHandler data); aoqi@0: }