javax.activation
Class DataHandler

java.lang.Object
  extended by javax.activation.DataHandler
All Implemented Interfaces:
java.awt.datatransfer.Transferable

public class DataHandler
extends java.lang.Object
implements java.awt.datatransfer.Transferable

Handler for data available in multiple sources and formats.


Constructor Summary
DataHandler(DataSource ds)
          Constructor in which the data is read from a data source.
DataHandler(java.lang.Object obj, java.lang.String mimeType)
          Constructor using a reified object representation.
DataHandler(java.net.URL url)
          Constructor in which the data is read from a URL.
 
Method Summary
 CommandInfo[] getAllCommands()
          Returns the complete list of commands for this type of data.
 java.lang.Object getBean(CommandInfo cmdInfo)
          Returns the instantiated bean using the specified command.
 CommandInfo getCommand(java.lang.String cmdName)
          Returns the specified command.
 java.lang.Object getContent()
          Returns the data as a reified object.
 java.lang.String getContentType()
          Returns the MIME type of the data (with parameters).
 DataSource getDataSource()
          Returns the data source from which data is read.
 java.io.InputStream getInputStream()
          Returns an input stream from which the data can be read.
 java.lang.String getName()
          Returns the name of the data object if created with a DataSource.
 java.io.OutputStream getOutputStream()
          Returns an output stream that can be used to overwrite the underlying data, if the DataSource constructor was used.
 CommandInfo[] getPreferredCommands()
          Returns the preferred commands for this type of data.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
          Returns an object representing the data to be transferred.
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
          Returns the data flavors in which this data is available.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
          Indicates whether the specified data flavor is supported for this data.
 void setCommandMap(CommandMap commandMap)
          Sets the command map to be used by this data handler.
static void setDataContentHandlerFactory(DataContentHandlerFactory newFactory)
          Sets the data content handler factory.
 void writeTo(java.io.OutputStream os)
          Writes the data as a byte stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataHandler

public DataHandler(DataSource ds)
Constructor in which the data is read from a data source.

Parameters:
ds - the data source

DataHandler

public DataHandler(java.lang.Object obj,
                   java.lang.String mimeType)
Constructor using a reified object representation.

Parameters:
obj - the object representation of the data
mimeType - the MIME type of the object

DataHandler

public DataHandler(java.net.URL url)
Constructor in which the data is read from a URL.

Parameters:
url - the URL
Method Detail

getDataSource

public DataSource getDataSource()
Returns the data source from which data is read.


getName

public java.lang.String getName()
Returns the name of the data object if created with a DataSource.


getContentType

public java.lang.String getContentType()
Returns the MIME type of the data (with parameters).


getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an input stream from which the data can be read.

Throws:
java.io.IOException

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException
Writes the data as a byte stream.

Parameters:
os - the stream to write to
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns an output stream that can be used to overwrite the underlying data, if the DataSource constructor was used.

Throws:
java.io.IOException

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Returns the data flavors in which this data is available.

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Indicates whether the specified data flavor is supported for this data.

Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Returns an object representing the data to be transferred.

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Parameters:
flavor - the requested data flavor
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

setCommandMap

public void setCommandMap(CommandMap commandMap)
Sets the command map to be used by this data handler. Setting to null uses the default command map.

Parameters:
commandMap - the command map to use

getPreferredCommands

public CommandInfo[] getPreferredCommands()
Returns the preferred commands for this type of data.


getAllCommands

public CommandInfo[] getAllCommands()
Returns the complete list of commands for this type of data.


getCommand

public CommandInfo getCommand(java.lang.String cmdName)
Returns the specified command.

Parameters:
cmdName - the command name

getContent

public java.lang.Object getContent()
                            throws java.io.IOException
Returns the data as a reified object.

Throws:
java.io.IOException

getBean

public java.lang.Object getBean(CommandInfo cmdInfo)
Returns the instantiated bean using the specified command.

Parameters:
cmdInfo - the command to instantiate the bean with

setDataContentHandlerFactory

public static void setDataContentHandlerFactory(DataContentHandlerFactory newFactory)
Sets the data content handler factory. If the factory has already been set, throws an Error.

Parameters:
newFactory - the factory to set