KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > attachment > AttachmentMarshaller


1 package javax.xml.bind.attachment;
2
3 import javax.activation.DataHandler JavaDoc;
4 import javax.xml.bind.Marshaller;
5
6 /**
7  * <p>Enable JAXB marshalling to optimize storage of binary data.</p>
8  *
9  * <p>This API enables an efficient cooperative creation of optimized
10  * binary data formats between a JAXB marshalling process and a MIME-based package
11  * processor. A JAXB implementation marshals the root body of a MIME-based package,
12  * delegating the creation of referenceable MIME parts to
13  * the MIME-based package processor that implements this abstraction.</p>
14  *
15  * <p>XOP processing is enabled when {@link #isXOPPackage()} is true.
16  * See {@link #addMtomAttachment(DataHandler, String, String)} for details.
17  * </p>
18  *
19  * <p>WS-I Attachment Profile 1.0 is supported by
20  * {@link #addSwaRefAttachment(DataHandler)} being called by the
21  * marshaller for each JAXB property related to
22  * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef.</p>
23  *
24  *
25  * @author Marc Hadley
26  * @author Kohsuke Kawaguchi
27  * @author Joseph Fialli
28  * @since JAXB 2.0
29  *
30  * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller)
31  *
32  * @see <a HREF="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
33  * @see <a HREF="http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html">WS-I Attachments Profile Version 1.0.</a>
34  */

35 public abstract class AttachmentMarshaller {
36
37     /**
38      * <p>Consider MIME content <code>data</code> for optimized binary storage as an attachment.
39      *
40      * <p>
41      * This method is called by JAXB marshal process when {@link #isXOPPackage()} is
42      * <code>true</code>, for each element whose datatype is "base64Binary", as described in
43      * Step 3 in
44      * <a HREF="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Packages</a>.
45      *
46      * <p>
47      * The method implementor determines whether <code>data</code> shall be attached separately
48      * or inlined as base64Binary data. If the implementation chooses to optimize the storage
49      * of the binary data as a MIME part, it is responsible for attaching <code>data</code> to the
50      * MIME-based package, and then assigning an unique content-id, cid, that identifies
51      * the MIME part within the MIME message. This method returns the cid,
52      * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place
53      * of marshalling the binary data. When the method returns null, the JAXB marshaller
54      * inlines <code>data</code> as base64binary data.
55      *
56      * <p>
57      * The caller of this method is required to meet the following constraint.
58      * If the element infoset item containing <code>data</code> has the attribute
59      * <code>xmime:contentType</code> or if the JAXB property/field representing
60      * <code>data</code>is annotated with a known MIME type,
61      * <code>data.getContentType()</code> should be set to that MIME type.
62      *
63      * <p>
64      * The <code>elementNamespace</code> and <code>elementLocalName</code>
65      * parameters provide the
66      * context that contains the binary data. This information could
67      * be used by the MIME-based package processor to determine if the
68      * binary data should be inlined or optimized as an attachment.
69      *
70      * @param data
71      * represents the data to be attached. Must be non-null.
72      * @param elementNamespace
73      * the namespace URI of the element that encloses the base64Binary data.
74      * Can be empty but never null.
75      * @param elementLocalName
76      * The local name of the element. Always a non-null valid string.
77      *
78      * @return
79      * 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>.
80      * Otherwise, null if the attachment was not added and should instead be inlined in the message.
81      *
82      * @see <a HREF="http://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
83      * @see <a HREF="http://www.w3.org/TR/xml-media-types/">Describing Media Content of Binary Data in XML</a>
84      */

85     public abstract String JavaDoc addMtomAttachment(DataHandler JavaDoc data, String JavaDoc elementNamespace, String JavaDoc elementLocalName);
86
87     /**
88      * <p>Consider binary <code>data</code> for optimized binary storage as an attachment.
89      *
90      * <p>Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream".</p>
91      *
92      * <p>
93      * The <code>elementNamespace</code> and <code>elementLocalName</code>
94      * parameters provide the
95      * context that contains the binary data. This information could
96      * be used by the MIME-based package processor to determine if the
97      * binary data should be inlined or optimized as an attachment.
98      *
99      * @param data
100      * represents the data to be attached. Must be non-null. The actual data region is
101      * specified by <tt>(data,offset,length)</tt> tuple.
102      *
103      * @param offset
104      * The offset within the array of the first byte to be read;
105      * must be non-negative and no larger than array.length
106      *
107      * @param length
108      * The number of bytes to be read from the given array;
109      * must be non-negative and no larger than array.length
110      *
111      * @param mimeType
112      * If the data has an associated MIME type known to JAXB, that is passed
113      * as this parameter. If none is known, "application/octet-stream".
114      * This parameter may never be null.
115      *
116      * @param elementNamespace
117      * the namespace URI of the element that encloses the base64Binary data.
118      * Can be empty but never null.
119      *
120      * @param elementLocalName
121      * The local name of the element. Always a non-null valid string.
122      *
123      * @return content-id URI, cid, to the attachment containing
124      * <code>data</code> or null if data should be inlined.
125      *
126      * @see #addMtomAttachment(DataHandler, String, String)
127      */

128     public abstract String JavaDoc addMtomAttachment(byte[] data, int offset, int length, String JavaDoc mimeType, String JavaDoc elementNamespace, String JavaDoc elementLocalName);
129
130     /**
131      * <p>Read-only property that returns true if JAXB marshaller should enable XOP creation.</p>
132      *
133      * <p>This value must not change during the marshalling process. When this
134      * value is true, the <code>addMtomAttachment(...)</code> method
135      * is invoked when the appropriate binary datatypes are encountered by
136      * the marshal process.</p>
137      *
138      * <p>Marshaller.marshal() must throw IllegalStateException if this value is <code>true</code>
139      * and the XML content to be marshalled violates Step 1 in
140      * <a ref="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>
141      * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages.
142      * <i>"Ensure the Original XML Infoset contains no element information item with a
143      * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include"</i>
144      *
145      * <p>When this method returns true and during the marshal process
146      * at least one call to <code>addMtomAttachment(...)</code> returns
147      * a content-id, the MIME-based package processor must label the
148      * root part with the application/xop+xml media type as described in
149      * Step 5 of
150      * <a ref="http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages">Creating XOP Pacakges</a>.<p>
151      *
152      * @return true when MIME context is a XOP Package.
153      */

154     public boolean isXOPPackage() { return false; }
155
156    /**
157     * <p>Add MIME <code>data</code> as an attachment and return attachment's content-id, cid.</p>
158     *
159     * <p>
160     * This method is called by JAXB marshal process for each element/attribute typed as
161     * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor
162     * implementing this method is responsible for attaching the specified data to a
163     * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment
164     * within the MIME-based package.
165     *
166     * <p>Caller inserts the returned content-id, cid, into the XML content being marshalled.</p>
167     *
168     * @param data
169     * represents the data to be attached. Must be non-null.
170     * @return
171     * must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from
172     * <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>
173     */

174     public abstract String JavaDoc addSwaRefAttachment(DataHandler JavaDoc data);
175 }
176
177
Popular Tags