|[ Team LiB ]|
14.3 Data Transfer Architecture
Before we consider any more advanced data transfer examples, it is important that you understand the Java 1.1 java.awt.datatransfer infrastructure that the javax.swing.TransferHandler mechanism relies upon. The java.awt.datatransfer.DataFlavor class is perhaps the most central class; it represents the type of data to be transferred. Every data flavor consists of a human-readable name, a Class object that specifies the Java data type of the transferred data, and a MIME type that specifies the encoding used during data transfer. The DataFlavor class predefines a couple of commonly used flavors for transferring strings and lists of File objects. It also predefines several MIME types used with those flavors. For example, DataFlavor.stringFlavor can transfer Java String objects as Unicode text. It has a representation class of java.lang.String and a MIME type of:
The java.awt.datatransfer.Transferable interface is another important piece of the data transfer picture. This interface specifies three methods that should be implemented by any object that wants to make data available for transfer: getTransferDataFlavors( ), which returns an array of all the DataFlavor types it can use to transfer its data; isDataFlavorSupported( ), which checks whether the Transferable object supports a given flavor; and the most important method, getTransferData( ), which actually returns the data in a format appropriate for the requested DataFlavor.
The data transfer architecture relies on object serialization as one of its means of transferring data between applications, which makes the architecture quite general and flexible. It was designed to allow arbitrary data to be transferred between independent Java virtual machines. Java data transfer can also work between Java applications and native-platform applications. Note, however, that your native operating system doesn't know how to work with serialized Java objects, so if you want to enable data transfer with native applications, you should restrict yourself to using predefined flavors that have well-known mappings to native types, such as DataFlavor.stringFlavor and DataFlavor.javaFileListFlavor.
|[ Team LiB ]|