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

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

ohair@286: * ohair@286: *

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

ohair@286: * ohair@286: *

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

ohair@286: * ohair@286: *

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

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

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

ohair@286: * ohair@286: *

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

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

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

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

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

ohair@286: * ohair@286: *

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

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