JavaTM 2 Platform
Standard Edition

java.awt.datatransfer
Class DataFlavor

java.lang.Object
  |
  +--java.awt.datatransfer.DataFlavor

public class DataFlavor
extends Object
implements Externalizable, Cloneable

Each instance represents the opaque concept of a data format as would appear on a clipboard, during drag and drop, or in a file system.

See Also:
Serialized Form

Field Summary
static DataFlavor javaFileListFlavor
          To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used.
static String javaJVMLocalObjectMimeType
          to transfer a reference to an arbitrary Java object reference that has no associated MIME Content-type, across a Transferable interface WITHIN THE SAME JVM, a DataFlavor with this type/subtype is used, with a representationClass equal to the type of the class/interface being passed across the Transferble.
static String javaRemoteObjectMimeType
          In order to pass a live link to a Remote object via a Drag and Drop ACTION_LINK operation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of the DataFlavor represents the type of the Remote interface to be transferred.
static String javaSerializedObjectMimeType
          a MIME Content-Type of application/x-java-serialized-object represents a graph of Java object(s) that have been made persistent.
static DataFlavor plainTextFlavor
          The DataFlavor representing plain text with unicode encoding, where:
static DataFlavor stringFlavor
          The DataFlavor representing a Java Unicode String class, where:
 
Constructor Summary
DataFlavor()
           
DataFlavor(Class representationClass, String humanPresentableName)
          Construct a DataFlavor that represents a Java class
DataFlavor(String mimeType)
          Construct a DataFlavor from a Mime Type string.
DataFlavor(String mimeType, String humanPresentableName)
          Construct a DataFlavor that represents a MimeType
DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader)
          Construct a DataFlavor that represents a MimeType
 
Method Summary
 Object clone()
          Creates and returns a copy of this object.
 boolean equals(DataFlavor dataFlavor)
          Compare this DataFlavor against another DataFlavor object both mimeType and representationClass are considered
 boolean equals(Object o)
          If the object is an instance of DataFlavor, representationClass will be compared while it will not be if the object is a String.
 boolean equals(String s)
          Compare only the mineType against the passed in String and representationClass is not considered in the comparison.
 String getHumanPresentableName()
          Returns the human presentable name for the data foramt that this DataFlavor represents.
 String getMimeType()
          Returns the MIME type string for this DataFlavor
 String getParameter(String paramName)
           
 String getPrimaryType()
           
 Class getRepresentationClass()
          Returns the Class which objects supporting this DataFlavor will return when this DataFlavor is requested.
 String getSubType()
           
 boolean isFlavorJavaFileListType()
           
 boolean isFlavorRemoteObjectType()
           
 boolean isFlavorSerializedObjectType()
           
 boolean isMimeTypeEqual(DataFlavor dataFlavor)
          Compare the mimeType of two DataFlavor objects no parameters are considered
 boolean isMimeTypeEqual(String mimeType)
          Is the string representation of the MIME type passed in equivalent to the MIME type of this DataFlavor? Parameters are not incuded in the comparison.
 boolean isMimeTypeSerializedObject()
          does the DataFlavor represent a serialized object?
 boolean isRepresentationClassInputStream()
          does the DataFlavor represent a java.io.InputStream
 boolean isRepresentationClassRemote()
           
 boolean isRepresentationClassSerializable()
           
protected  String normalizeMimeType(String mimeType)
          Deprecated.  
protected  String normalizeMimeTypeParameter(String parameterName, String parameterValue)
          Deprecated.  
 void readExternal(ObjectInput is)
          restore this DataFlavor from an Serialized state
 void setHumanPresentableName(String humanPresentableName)
          Sets the human presentable name for the data format that this DataFlavor represents.
 String toString()
          Returns a string representation of the object.
protected static Class tryToLoadClass(String className, ClassLoader fallback)
          tried to load a class from: the bootstrap loader, the system loader, the context loader (if one is present) and finally the loader specified
 void writeExternal(ObjectOutput os)
          Serialize this DataFlavor
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stringFlavor

public static final DataFlavor stringFlavor
The DataFlavor representing a Java Unicode String class, where:

representationClass = java.lang.String
mimeType = "application/x-java-serialized-object"


plainTextFlavor

public static final DataFlavor plainTextFlavor
The DataFlavor representing plain text with unicode encoding, where:

representationClass = InputStream
mimeType = "text/plain; charset=unicode"


javaSerializedObjectMimeType

public static final String javaSerializedObjectMimeType
a MIME Content-Type of application/x-java-serialized-object represents a graph of Java object(s) that have been made persistent. The representation class associated with this DataFlavor identifies the Java type of an object returned as a reference from an invocation java.awt.datatransfer.getTransferData().

javaFileListFlavor

public static final DataFlavor javaFileListFlavor
To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used. Each element of the list is required/guaranteed to be of type java.io.File.

javaJVMLocalObjectMimeType

public static final String javaJVMLocalObjectMimeType
to transfer a reference to an arbitrary Java object reference that has no associated MIME Content-type, across a Transferable interface WITHIN THE SAME JVM, a DataFlavor with this type/subtype is used, with a representationClass equal to the type of the class/interface being passed across the Transferble. The object reference returned from Transferable.getTransferData() for a DataFlavor with this MIME Content-Type is required to be an instanceof the representation Class of the DataFlavor.

javaRemoteObjectMimeType

public static final String javaRemoteObjectMimeType
In order to pass a live link to a Remote object via a Drag and Drop ACTION_LINK operation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of the DataFlavor represents the type of the Remote interface to be transferred.
Constructor Detail

DataFlavor

public DataFlavor(Class representationClass,
                  String humanPresentableName)
Construct a DataFlavor that represents a Java class

The returned DataFlavor will have the following characteristics

representationClass = representationClass
mimeType = application/x-java-serialized-object

Parameters:
representationClass - the class used to transfer data in this flavor
humanPresentableName - the human-readable string used to identify this flavor. If this parameter is null then the value of the the MIME Content Type is used.

DataFlavor

public DataFlavor(String mimeType,
                  String humanPresentableName)
Construct a DataFlavor that represents a MimeType

The returned DataFlavor will have the following characteristics:

If the mimeType is "application/x-java-serialized-object; class=<representation class>", the result is the same as calling new DataFlavor(Class:forName(<representation class>) as above

otherwise:

representationClass = InputStream
mimeType = mimeType

Parameters:
mimeType - the string used to identify the MIME type for this flavor. If the the mimeType does not specify a "class=" parameter, or if the class is not successfully loaded, then an IllegalArgumentException is thrown.
humanPresentableName - the human-readable string used to identify this flavor. If this parameter is null then the value of the the MIME Content Type is used.

DataFlavor

public DataFlavor(String mimeType,
                  String humanPresentableName,
                  ClassLoader classLoader)
           throws ClassNotFoundException
Construct a DataFlavor that represents a MimeType

The returned DataFlavor will have the following characteristics:

If the mimeType is "application/x-java-serialized-object; class=<representation class>", the result is the same as calling new DataFlavor(Class:forName(<representation class>) as above

otherwise:

representationClass = InputStream
mimeType = mimeType

Parameters:
mimeType - the string used to identify the MIME type for this flavor
humanPresentableName - the human-readible string used to identify this flavor

DataFlavor

public DataFlavor(String mimeType)
           throws ClassNotFoundException
Construct a DataFlavor from a Mime Type string. The string must specify a "class=" parameter in order to succeed in constructing a DataFlavor.
Parameters:
mimeType - the string used to identify the MIME type for this flavor. If the the mimeType does not specify a "class=" parameter, or if the class is not successfully loaded, then an IllegalArgumentException is thrown.

DataFlavor

public DataFlavor()
Method Detail

tryToLoadClass

protected static final Class tryToLoadClass(String className,
                                            ClassLoader fallback)
                                     throws ClassNotFoundException
tried to load a class from: the bootstrap loader, the system loader, the context loader (if one is present) and finally the loader specified
Parameters:
fallback - the fallback loader

toString

public String toString()
Description copied from class: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommendedthat all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
Overrides:
toString in class Object
Tags copied from class: Object
Returns:
a string representation of the object.

getMimeType

public String getMimeType()
Returns the MIME type string for this DataFlavor

getRepresentationClass

public Class getRepresentationClass()
Returns the Class which objects supporting this DataFlavor will return when this DataFlavor is requested.

getHumanPresentableName

public String getHumanPresentableName()
Returns the human presentable name for the data foramt that this DataFlavor represents. This name would be localized for different countries

getPrimaryType

public String getPrimaryType()
Returns:
the primary MIME type of this DataFlavor

getSubType

public String getSubType()
Returns:
the Sub MIME type of this DataFlavor

getParameter

public String getParameter(String paramName)
Returns:
the value of the name parameter

setHumanPresentableName

public void setHumanPresentableName(String humanPresentableName)
Sets the human presentable name for the data format that this DataFlavor represents. This name would be localized for different countries

equals

public boolean equals(Object o)
If the object is an instance of DataFlavor, representationClass will be compared while it will not be if the object is a String.
Overrides:
equals in class Object
Returns:
if the objects are equal

equals

public boolean equals(DataFlavor dataFlavor)
Compare this DataFlavor against another DataFlavor object both mimeType and representationClass are considered
Returns:
if the DataFlavors represent the same type.

equals

public boolean equals(String s)
Compare only the mineType against the passed in String and representationClass is not considered in the comparison. If representationClass needs to be compared, then equals(new DataFlavor(s)) may be used.
Returns:
if the String (MimeType) is equal

isMimeTypeEqual

public boolean isMimeTypeEqual(String mimeType)
Is the string representation of the MIME type passed in equivalent to the MIME type of this DataFlavor? Parameters are not incuded in the comparison. This may involve adding default attributes for some MIME types (like adding charset=US-ASCII to text/plain MIME types that have no charset parameter specified)

isMimeTypeEqual

public final boolean isMimeTypeEqual(DataFlavor dataFlavor)
Compare the mimeType of two DataFlavor objects no parameters are considered
Returns:
if the MimeTypes are equal

isMimeTypeSerializedObject

public boolean isMimeTypeSerializedObject()
does the DataFlavor represent a serialized object?

isRepresentationClassInputStream

public boolean isRepresentationClassInputStream()
does the DataFlavor represent a java.io.InputStream

isRepresentationClassSerializable

public boolean isRepresentationClassSerializable()
Returns:
true if the representation class can be serialized

isRepresentationClassRemote

public boolean isRepresentationClassRemote()
Returns:
true if the representation class is Remote

isFlavorSerializedObjectType

public boolean isFlavorSerializedObjectType()
Returns:
if the DataFlavor specified represents a Serialized Object

isFlavorRemoteObjectType

public boolean isFlavorRemoteObjectType()
Returns:
if the DataFlavor specified represents a Remote Object

isFlavorJavaFileListType

public boolean isFlavorJavaFileListType()
Returns:
if flavor specified represents a List of File objects

writeExternal

public void writeExternal(ObjectOutput os)
                   throws IOException
Serialize this DataFlavor
Specified by:
writeExternal in interface Externalizable
Tags copied from interface: Externalizable
Throws:
IOException - Includes any I/O exceptions that may occur

readExternal

public void readExternal(ObjectInput is)
                  throws IOException,
                         ClassNotFoundException
restore this DataFlavor from an Serialized state
Specified by:
readExternal in interface Externalizable
Tags copied from interface: Externalizable
Throws:
ClassNotFoundException - If the class for an object being restored cannot be found.

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from class: Object
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:
 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be true, this is not an absolute requirement. Copying an object will typically entail creating a new instance of its class, but it also may require copying of internal data structures as well. No constructors are called.

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.

The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time. The clone method is implemented by the class Object as a convenient, general utility for subclasses that implement the interface Cloneable, possibly also overriding the clone method, in which case the overriding definition can refer to this utility definition by the call:

 super.clone()
Overrides:
clone in class Object
Returns:
a clone of this DataFlavor

normalizeMimeTypeParameter

protected String normalizeMimeTypeParameter(String parameterName,
                                            String parameterValue)
Deprecated.  

Called on DataFlavor for every MIME Type parameter to allow DataFlavor subclasses to handle special parameters like the text/plain charset parameters, whose values are case insensitive. (MIME type parameter values are supposed to be case sensitive.

This method is called for each parameter name/value pair and should return the normalized representation of the parameterValue This method is never invoked by this implementation from 1.1 onwards


normalizeMimeType

protected String normalizeMimeType(String mimeType)
Deprecated.  

Called for each MIME type string to give DataFlavor subtypes the opportunity to change how the normalization of MIME types is accomplished. One possible use would be to add default parameter/value pairs in cases where none are present in the MIME type string passed in This method is never invoked by this implementation from 1.1 onwards

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.