Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----javax.activation.DataHandler
DataHandler and the Transferable Interface
DataHandler implements the Transferable interface so that data can be used in AWT data transfer operations, such as cut and paste and drag and drop. The implementation of the Transferable interface relies on the availability of an installed DataContentHandler object corresponding to the MIME type of the data respresented in the specific instance of the DataHandler.
DataHandler and CommandMaps
The DataHandler keeps track of the current CommandMap that it uses to
service requests for commands (getCommand
,
getAllCommands
, getPreferredCommands
). When
it makes a call to one of the Command methods, the DataHandler
checks to determine that a CommandMap has been explictly set via its
setCommandMap
method. If it has, it
uses that CommandMap. If a CommandMap was not set, DataHandler
calls the getDefaultCommandMap
method in CommandMap and uses the value it returns. See
CommandMap for more information.
DataHandler and URLs
The current DataHandler implementation creates a private instance of URLDataSource when it is constructed with a URL.
Constructor Summary | |
DataHandler(DataSource ds)
DataHandler instance with the
specified DataSource.
|
|
DataHandler(java.lang.Object obj,
java.lang.String mimeType)
|
|
DataHandler(java.net.URL url)
|
Method Summary | |
CommandInfo[] | getAllCommands()
DataHandler .
|
java.lang.Object | getBean(CommandInfo cmdinfo)
|
CommandInfo | getCommand(java.lang.String cmdName)
|
java.lang.Object | getContent()
|
java.lang.String | getContentType()
|
DataSource | getDataSource()
|
java.io.InputStream | getInputStream()
|
java.lang.String | getName()
|
java.io.OutputStream | getOutputStream()
|
CommandInfo[] | getPreferredCommands()
getPreferredCommands method
in the commandMap installed in this instance of DataHandler.
|
java.lang.Object | getTransferData(java.awt.datatransfer.DataFlavor flavor)
|
java.awt.datatransfer.DataFlavor[] | getTransferDataFlavors()
|
boolean | isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
This method iterates through the DataFlavors available from this object, which was the result of a call to this.getTransferDataFlavors. |
void | setCommandMap(CommandMap commandMap)
|
static void | setDataContentHandlerFactory(DataContentHandlerFactory newFactory)
|
void | writeTo(java.io.OutputStream os)
OutputStream .If the DataHandler was created with a DataSource, writeTo retrieves the InputStream and writes the bytes from the InputStream to the OutputStream passed in. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DataHandler(DataSource ds)
DataHandler
instance with the
specified DataSource.
ds
- the DataSource
public DataHandler(java.lang.Object obj, java.lang.String mimeType)
obj
- the Java Object
mimeType
- the MIME type of the object
public DataHandler(java.net.URL url)
URLDataSource
instance to
represent the URL.
url
- a URL object
Method Detail |
public DataSource getDataSource()
For DataHandlers that have been instantiated with a DataSource, this method returns the DataSource that was used to create the DataHandler object. In other cases the DataHandler constructs a DataSource from the data used to construct the DataHandler. DataSources created for DataHandlers not instantiated with a DataSource are cached for performance reasons.
public java.lang.String getName()
DataSource.getName
method, otherwise it
returns null.public java.lang.String getContentType()
public java.io.InputStream getInputStream() throws java.io.IOException
For DataHandlers instantiated with a DataSource. the DataHandler
calls the DataSource.getInputStream
method
The result returned to the caller.
For DataHandlers instantiated with an Object,
the DataHandler first attempts to find a DataContentHandler
for the Object. If the DataHandler can not find a DataContentHandler
for this MIME type, it throws an UnsupportedDataTypeException.
If it is successful, it creates a pipe
between the returned InputStream and DataContentHandler's
writeTo
method, which is called with the
object's data. It creates a thread that allows this operation
to complete asynchonously. However, because a thread is created
to copy the data, IOExceptions that may occur during the
copy can not be propagated back to the caller. The result
is an empty stream.
public void writeTo(java.io.OutputStream os) throws java.io.IOException
OutputStream
.If the DataHandler was created with a DataSource, writeTo retrieves the InputStream and writes the bytes from the InputStream to the OutputStream passed in.
If the DataHandler was created with an object, writeTo
retrieves the DataContentHandler for the object's type.
If the DataContentHandler was found, it calls the
writeTo
method on the DataContentHandler
.
os
- the OutputStream to write to
public java.io.OutputStream getOutputStream() throws java.io.IOException
public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Returns an array of DataFlavor objects indicating the flavors the data can be provided in. The array is usually ordered according to preference for providing the data,from most richly descriptive to least descriptive.
The DataHandler attempts to find a DataContentHandler that corresponds to the MIME type of the data. If one is located, the DataHandler calls the DataContentHandler's getTransferDataFlavors method. If a DataContentHandler can not be located, and if the DataHandler was created with a DataSource (or URL); one DataFlavor is returned that represents the natural type and format of the data (generally this.getContentType/InputStream). If the DataHandler was created with an object and a MIME type; getTransferDataFlavors returns one DataFlavor that represents the this.getContentType/InputStream.
public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
This method iterates through the DataFlavors available from this object, which was the result of a call to this.getTransferDataFlavors.
flavor
- the requested flavor for the data
public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException
For DataHandler's created with DataSources or URLs:
The DataHandler attempts to locate a DataContentHandler for this MIME type. If one is found, the passed in DataFlavor and the type of the date are passed to it's getTransferData method. If the DataHandler fails to locate a DataContentHandler the default behavior is to see if the DataFlavor requested matches the natural type and representation class of of the data and return it. Otherwise null is returned.
For DataHandler's created with Objects:
The DataHandler attempts to locate a DataContentHandler for this MIME type. If one is found, the passed in DataFlavor and the type of the date are passed to it's getTransferData method. If the DataHandler fails to locate a DataContentHandler the default behavior is to see if the DataFlavor requested matches the natural type and representation class of of the data and return it. Otherwise it throws an UnsupportedFlavorException.
flavor
- the requested flavor for the data
public void setCommandMap(CommandMap commandMap)
null
causes the CommandMap to revert to the
CommandMap returned by the CommandMap.getDefaultCommandMap
method.
commandMap
- the CommandMap to use in this DataHandler
public CommandInfo[] getPreferredCommands()
getPreferredCommands
method
in the commandMap installed in this instance of DataHandler.
This method returns an array that represents a subset of
available commands. In cases where multiple commands for the
MIME type represented by this DataHandler are present, the
installed CommandMap chooses the appropriate commands.public CommandInfo[] getAllCommands()
DataHandler
. The
MIME Type for the underlying data represented by this DataHandler
is used to call through to the getAllCommands
method of the
currently installed CommandMap.public CommandInfo getCommand(java.lang.String cmdName)
getCommand
method of the
currently installed CommandMap.public java.lang.Object getContent() throws java.io.IOException
If the DataHandler was instantiated with an object, return the object.
If the DataHandler was instantiated with a DataSource,
this method uses a DataContentHandler to return the content
object for the data represented by this DataHandler. If no
DataContentHandler
can be found for the
the type of this data, the DataHandler throws an
UnsupportedDataTypeException
exception.
public java.lang.Object getBean(CommandInfo cmdinfo)
This method calls the cmdInfo's getCommandObject
method with the ClassLoader
used to load
this object.
public static void setDataContentHandlerFactory(DataContentHandlerFactory newFactory)
DataHandler
might potentially look for DataContentHandlers.
The DataContentHandler factory can only be set once.
If the DataContentHandlerFactory has already been set, this method throws an Error. The design pattern is same a java.net.URLConnection.setContentHandler.
factory
- the DataContentHandlerFactory
Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |