1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 /*
38 * @(#)DataContentHandler.java 1.17 07/05/14
39 */
40
41 package javax.activation;
42
43 import java.awt.datatransfer.DataFlavor;
44 import java.awt.datatransfer.UnsupportedFlavorException;
45 import java.io.InputStream;
46 import java.io.IOException;
47 import java.io.OutputStream;
48 import javax.activation.DataSource;
49
50 /**
51 * The DataContentHandler interface is implemented by objects that can
52 * be used to extend the capabilities of the DataHandler's implementation
53 * of the Transferable interface. Through <code>DataContentHandlers</code>
54 * the framework can be extended to convert streams in to objects, and
55 * to write objects to streams. <p>
56 *
57 * Applications don't generally call the methods in DataContentHandlers
58 * directly. Instead, an application calls the equivalent methods in
59 * DataHandler. The DataHandler will attempt to find an appropriate
60 * DataContentHandler that corresponds to its MIME type using the
61 * current DataContentHandlerFactory. The DataHandler then calls
62 * through to the methods in the DataContentHandler.
63 */
64
65 public interface DataContentHandler {
66 /**
67 * Returns an array of DataFlavor objects indicating the flavors the
68 * data can be provided in. The array should be ordered according to
69 * preference for providing the data (from most richly descriptive to
70 * least descriptive).
71 *
72 * @return The DataFlavors.
73 */
74 public DataFlavor[] getTransferDataFlavors();
75
76 /**
77 * Returns an object which represents the data to be transferred.
78 * The class of the object returned is defined by the representation class
79 * of the flavor.
80 *
81 * @param df The DataFlavor representing the requested type.
82 * @param ds The DataSource representing the data to be converted.
83 * @return The constructed Object.
84 * @exception UnsupportedFlavorException if the handler doesn't
85 * support the requested flavor
86 * @exception IOException if the data can't be accessed
87 */
88 public Object getTransferData(DataFlavor df, DataSource ds)
89 throws UnsupportedFlavorException, IOException;
90
91 /**
92 * Return an object representing the data in its most preferred form.
93 * Generally this will be the form described by the first DataFlavor
94 * returned by the <code>getTransferDataFlavors</code> method.
95 *
96 * @param ds The DataSource representing the data to be converted.
97 * @return The constructed Object.
98 * @exception IOException if the data can't be accessed
99 */
100 public Object getContent(DataSource ds) throws IOException;
101
102 /**
103 * Convert the object to a byte stream of the specified MIME type
104 * and write it to the output stream.
105 *
106 * @param obj The object to be converted.
107 * @param mimeType The requested MIME type of the resulting byte stream.
108 * @param os The output stream into which to write the converted
109 * byte stream.
110 * @exception IOException errors writing to the stream
111 */
112 public void writeTo(Object obj, String mimeType, OutputStream os)
113 throws IOException;
114 }