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: aoqi@0: /** aoqi@0: *

Enables JAXB unmarshalling of a root document containing optimized binary data formats.

aoqi@0: * aoqi@0: *

This API enables an efficient cooperative processing of optimized aoqi@0: * binary data formats between a JAXB 2.0 implementation and MIME-based package aoqi@0: * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the aoqi@0: * understanding of the packaging format being used to a MIME-based aoqi@0: * package processor that implements this abstract class.

aoqi@0: * aoqi@0: *

This abstract class identifies if a package requires XOP processing, {@link #isXOPPackage()} and provides retrieval of binary content stored as attachments by content-id.

aoqi@0: * aoqi@0: *

Identifying the content-id, cid, to pass to getAttachment*(String cid)

aoqi@0: * aoqi@0: * aoqi@0: * @author Marc Hadley aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: * @author Joseph Fialli aoqi@0: * aoqi@0: * @since JAXB 2.0 aoqi@0: * aoqi@0: * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller) aoqi@0: * aoqi@0: * @see XML-binary Optimized Packaging aoqi@0: * @see WS-I Attachments Profile Version 1.0. aoqi@0: * @see Describing Media Content of Binary Data in XML aoqi@0: */ aoqi@0: public abstract class AttachmentUnmarshaller { aoqi@0: /** aoqi@0: *

Lookup MIME content by content-id, cid, and return as a {@link DataHandler}.

aoqi@0: * aoqi@0: *

The returned DataHandler instance must be configured aoqi@0: * to meet the following required mapping constaint. aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: *
aoqi@0: * Required Mappings between MIME and Java Types aoqi@0: *
MIME TypeJava Type
DataHandler.getContentType()instanceof DataHandler.getContent()
image/gifjava.awt.Image
image/jpegjava.awt.Image
text/xml or application/xmljavax.xml.transform.Source
aoqi@0: * Note that it is allowable to support additional mappings.

aoqi@0: * aoqi@0: * @param cid It is expected to be a valid lexical form of the XML Schema aoqi@0: * xs:anyURI datatype. If {@link #isXOPPackage()} aoqi@0: * ==true, it must be a valid URI per the cid: URI scheme (see RFC 2387) aoqi@0: * aoqi@0: * @return aoqi@0: * a {@link DataHandler} that represents the MIME attachment. aoqi@0: * aoqi@0: * @throws IllegalArgumentException if the attachment for the given cid is not found. aoqi@0: */ aoqi@0: public abstract DataHandler getAttachmentAsDataHandler(String cid); aoqi@0: aoqi@0: /** aoqi@0: *

Retrieve the attachment identified by content-id, cid, as a byte[]

. aoqi@0: * aoqi@0: * @param cid It is expected to be a valid lexical form of the XML Schema aoqi@0: * xs:anyURI datatype. If {@link #isXOPPackage()} aoqi@0: * ==true, it must be a valid URI per the cid: URI scheme (see RFC 2387) aoqi@0: * aoqi@0: * @return byte[] representation of attachment identified by cid. aoqi@0: * aoqi@0: * @throws IllegalArgumentException if the attachment for the given cid is not found. aoqi@0: */ aoqi@0: public abstract byte[] getAttachmentAsByteArray(String cid); aoqi@0: aoqi@0: /** aoqi@0: *

Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.

aoqi@0: * aoqi@0: *

This method returns true when the constraints specified aoqi@0: * in Identifying XOP Documents are met. aoqi@0: * This value must not change during the unmarshalling process.

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