src/share/jaxws_classes/javax/xml/bind/attachment/AttachmentMarshaller.java

Fri, 23 Aug 2013 09:57:21 +0100

author
mkos
date
Fri, 23 Aug 2013 09:57:21 +0100
changeset 397
b99d7e355d4b
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8022885: Update JAX-WS RI integration to 2.2.9-b14140
8013016: Rebase 8009009 against the latest jdk8/jaxws
Reviewed-by: alanb, chegar

ohair@286 1 /*
mkos@397 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package javax.xml.bind.attachment;
ohair@286 27
ohair@286 28 import javax.activation.DataHandler;
ohair@286 29 import javax.xml.bind.Marshaller;
ohair@286 30
ohair@286 31 /**
ohair@286 32 * <p>Enable JAXB marshalling to optimize storage of binary data.</p>
ohair@286 33 *
ohair@286 34 * <p>This API enables an efficient cooperative creation of optimized
ohair@286 35 * binary data formats between a JAXB marshalling process and a MIME-based package
ohair@286 36 * processor. A JAXB implementation marshals the root body of a MIME-based package,
ohair@286 37 * delegating the creation of referenceable MIME parts to
ohair@286 38 * the MIME-based package processor that implements this abstraction.</p>
ohair@286 39 *
ohair@286 40 * <p>XOP processing is enabled when {@link #isXOPPackage()} is true.
ohair@286 41 * See {@link #addMtomAttachment(DataHandler, String, String)} for details.
ohair@286 42 * </p>
ohair@286 43 *
ohair@286 44 * <p>WS-I Attachment Profile 1.0 is supported by
ohair@286 45 * {@link #addSwaRefAttachment(DataHandler)} being called by the
ohair@286 46 * marshaller for each JAXB property related to
ohair@286 47 * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef.</p>
ohair@286 48 *
ohair@286 49 *
ohair@286 50 * @author Marc Hadley
ohair@286 51 * @author Kohsuke Kawaguchi
ohair@286 52 * @author Joseph Fialli
ohair@286 53 * @since JAXB 2.0
ohair@286 54 *
ohair@286 55 * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller)
ohair@286 56 *
ohair@286 57 * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
ohair@286 58 * @see <a href="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
ohair@286 59 */
ohair@286 60 public abstract class AttachmentMarshaller {
ohair@286 61
ohair@286 62 /**
ohair@286 63 * <p>Consider MIME content <code>data</code> for optimized binary storage as an attachment.
ohair@286 64 *
ohair@286 65 * <p>
ohair@286 66 * This method is called by JAXB marshal process when {@link #isXOPPackage()} is
ohair@286 67 * <code>true</code>, for each element whose datatype is "base64Binary", as described in
ohair@286 68 * Step 3 in
ohair@286 69 * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Packages</a>.
ohair@286 70 *
ohair@286 71 * <p>
ohair@286 72 * The method implementor determines whether <code>data</code> shall be attached separately
ohair@286 73 * or inlined as base64Binary data. If the implementation chooses to optimize the storage
ohair@286 74 * of the binary data as a MIME part, it is responsible for attaching <code>data</code> to the
ohair@286 75 * MIME-based package, and then assigning an unique content-id, cid, that identifies
ohair@286 76 * the MIME part within the MIME message. This method returns the cid,
ohair@286 77 * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place
ohair@286 78 * of marshalling the binary data. When the method returns null, the JAXB marshaller
ohair@286 79 * inlines <code>data</code> as base64binary data.
ohair@286 80 *
ohair@286 81 * <p>
ohair@286 82 * The caller of this method is required to meet the following constraint.
ohair@286 83 * If the element infoset item containing <code>data</code> has the attribute
ohair@286 84 * <code>xmime:contentType</code> or if the JAXB property/field representing
ohair@286 85 * <code>data</code>is annotated with a known MIME type,
ohair@286 86 * <code>data.getContentType()</code> should be set to that MIME type.
ohair@286 87 *
ohair@286 88 * <p>
ohair@286 89 * The <code>elementNamespace</code> and <code>elementLocalName</code>
ohair@286 90 * parameters provide the
ohair@286 91 * context that contains the binary data. This information could
ohair@286 92 * be used by the MIME-based package processor to determine if the
ohair@286 93 * binary data should be inlined or optimized as an attachment.
ohair@286 94 *
ohair@286 95 * @param data
ohair@286 96 * represents the data to be attached. Must be non-null.
ohair@286 97 * @param elementNamespace
ohair@286 98 * the namespace URI of the element that encloses the base64Binary data.
ohair@286 99 * Can be empty but never null.
ohair@286 100 * @param elementLocalName
ohair@286 101 * The local name of the element. Always a non-null valid string.
ohair@286 102 *
ohair@286 103 * @return
ohair@286 104 * 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>.
ohair@286 105 * Otherwise, null if the attachment was not added and should instead be inlined in the message.
ohair@286 106 *
ohair@286 107 * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
ohair@286 108 * @see <a href="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
ohair@286 109 */
ohair@286 110 public abstract String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName);
ohair@286 111
ohair@286 112 /**
ohair@286 113 * <p>Consider binary <code>data</code> for optimized binary storage as an attachment.
ohair@286 114 *
ohair@286 115 * <p>Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream".</p>
ohair@286 116 *
ohair@286 117 * <p>
ohair@286 118 * The <code>elementNamespace</code> and <code>elementLocalName</code>
ohair@286 119 * parameters provide the
ohair@286 120 * context that contains the binary data. This information could
ohair@286 121 * be used by the MIME-based package processor to determine if the
ohair@286 122 * binary data should be inlined or optimized as an attachment.
ohair@286 123 *
ohair@286 124 * @param data
ohair@286 125 * represents the data to be attached. Must be non-null. The actual data region is
ohair@286 126 * specified by <tt>(data,offset,length)</tt> tuple.
ohair@286 127 *
ohair@286 128 * @param offset
ohair@286 129 * The offset within the array of the first byte to be read;
ohair@286 130 * must be non-negative and no larger than array.length
ohair@286 131 *
ohair@286 132 * @param length
ohair@286 133 * The number of bytes to be read from the given array;
ohair@286 134 * must be non-negative and no larger than array.length
ohair@286 135 *
ohair@286 136 * @param mimeType
ohair@286 137 * If the data has an associated MIME type known to JAXB, that is passed
ohair@286 138 * as this parameter. If none is known, "application/octet-stream".
ohair@286 139 * This parameter may never be null.
ohair@286 140 *
ohair@286 141 * @param elementNamespace
ohair@286 142 * the namespace URI of the element that encloses the base64Binary data.
ohair@286 143 * Can be empty but never null.
ohair@286 144 *
ohair@286 145 * @param elementLocalName
ohair@286 146 * The local name of the element. Always a non-null valid string.
ohair@286 147 *
ohair@286 148 * @return content-id URI, cid, to the attachment containing
ohair@286 149 * <code>data</code> or null if data should be inlined.
ohair@286 150 *
ohair@286 151 * @see #addMtomAttachment(DataHandler, String, String)
ohair@286 152 */
ohair@286 153 public abstract String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName);
ohair@286 154
ohair@286 155 /**
ohair@286 156 * <p>Read-only property that returns true if JAXB marshaller should enable XOP creation.</p>
ohair@286 157 *
ohair@286 158 * <p>This value must not change during the marshalling process. When this
ohair@286 159 * value is true, the <code>addMtomAttachment(...)</code> method
ohair@286 160 * is invoked when the appropriate binary datatypes are encountered by
ohair@286 161 * the marshal process.</p>
ohair@286 162 *
ohair@286 163 * <p>Marshaller.marshal() must throw IllegalStateException if this value is <code>true</code>
ohair@286 164 * and the XML content to be marshalled violates Step 1 in
ohair@286 165 * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>
ohair@286 166 * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages.
ohair@286 167 * <i>"Ensure the Original XML Infoset contains no element information item with a
ohair@286 168 * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include"</i>
ohair@286 169 *
ohair@286 170 * <p>When this method returns true and during the marshal process
ohair@286 171 * at least one call to <code>addMtomAttachment(...)</code> returns
ohair@286 172 * a content-id, the MIME-based package processor must label the
ohair@286 173 * root part with the application/xop+xml media type as described in
ohair@286 174 * Step 5 of
ohair@286 175 * <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>.<p>
ohair@286 176 *
ohair@286 177 * @return true when MIME context is a XOP Package.
ohair@286 178 */
ohair@286 179 public boolean isXOPPackage() { return false; }
ohair@286 180
ohair@286 181 /**
ohair@286 182 * <p>Add MIME <code>data</code> as an attachment and return attachment's content-id, cid.</p>
ohair@286 183 *
ohair@286 184 * <p>
ohair@286 185 * This method is called by JAXB marshal process for each element/attribute typed as
ohair@286 186 * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor
ohair@286 187 * implementing this method is responsible for attaching the specified data to a
ohair@286 188 * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment
ohair@286 189 * within the MIME-based package.
ohair@286 190 *
ohair@286 191 * <p>Caller inserts the returned content-id, cid, into the XML content being marshalled.</p>
ohair@286 192 *
ohair@286 193 * @param data
ohair@286 194 * represents the data to be attached. Must be non-null.
ohair@286 195 * @return
ohair@286 196 * must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from
ohair@286 197 * <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>
ohair@286 198 */
ohair@286 199 public abstract String addSwaRefAttachment(DataHandler data);
ohair@286 200 }

mercurial