java.awt.datatransfer

Class SystemFlavorMap

Implemented Interfaces:
FlavorMap, FlavorTable

public final class SystemFlavorMap
extends Object
implements FlavorMap, FlavorTable

This class maps between native platform type names and DataFlavors. XXX - The current implementation does no mapping at all.
Since:
1.2

Method Summary

Map
DataFlavor> getFlavorsForNatives(String[] natives)
Maps the specified native type names to DataFlavor's.
Map
String> getNativesForFlavors(DataFlavor[] flavors)
Maps the specified DataFlavor objects to the native data type name.
void
addFlavorForUnencodedNative(String nativeStr, DataFlavor flavor)
Adds a mapping from a single String native to a single DataFlavor.
void
addUnencodedNativeForFlavor(DataFlavor flavor, String nativeStr)
Adds a mapping from the specified DataFlavor (and all DataFlavors equal to the specified DataFlavor) to the specified String native.
static DataFlavor
decodeDataFlavor(String name)
Returns the data flavor given the native type name or null when no such data flavor exists.
static String
decodeJavaMIMEType(String name)
Decodes a String native for use as a Java MIME type.
static String
encodeDataFlavor(DataFlavor df)
Encodes a DataFlavor for use as a String native.
static String
encodeJavaMIMEType(String mime)
Encodes a MIME type for use as a String native.
static FlavorMap
getDefaultFlavorMap()
Returns the (System)FlavorMap for the current thread's ClassLoader.
List
getFlavorsForNative(String nat)
Returns a List of DataFlavors to which the specified String native can be translated by the data transfer subsystem.
List
getNativesForFlavor(DataFlavor flav)
Returns a list of String natives corresponding to the given flavor.
static boolean
isJavaMIMEType(String name)
Returns true if the native type name can be represented as a java mime type.
void
setFlavorsForNative(String nativeStr, DataFlavor[] flavors)
Discards the current mappings for the specified String native, and creates new mappings to the specified DataFlavors.
void
setNativesForFlavor(DataFlavor flavor, String[] natives)
Discards the current mappings for the specified DataFlavor and all DataFlavors equal to the specified DataFlavor, and creates new mappings to the specified String natives.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

DataFlavor> getFlavorsForNatives

public MapDataFlavor> getFlavorsForNatives(String[] natives)
Maps the specified native type names to DataFlavor's. The returned Map has keys that are strings and values that are DataFlavor's. The returned map may be modified. This can be useful for implementing nested mappings.
Specified by:
DataFlavor> getFlavorsForNatives in interface FlavorMap
Parameters:
natives - An array of native types to map or null for all native types.
Returns:
A Map of data flavors to native type names.

String> getNativesForFlavors

public MapString> getNativesForFlavors(DataFlavor[] flavors)
Maps the specified DataFlavor objects to the native data type name. The returned Map has keys that are the data flavors and values that are strings. The returned map may be modified. This can be useful for implementing nested mappings.
Specified by:
String> getNativesForFlavors in interface FlavorMap
Parameters:
flavors - An array of data flavors to map or null for all data flavors.
Returns:
A Map of native data types to data flavors.

addFlavorForUnencodedNative

public void addFlavorForUnencodedNative(String nativeStr,
                                        DataFlavor flavor)
Adds a mapping from a single String native to a single DataFlavor. Unlike getFlavorsForNative, the mapping will only be established in one direction, and the native will not be encoded. To establish a two-way mapping, call addUnencodedNativeForFlavor as well. The new mapping will be of lower priority than any existing mapping. This method has no effect if a mapping from the specified String native to the specified or equal DataFlavor already exists.
Parameters:
nativeStr - the String native key for the mapping
flavor - the DataFlavor value for the mapping
Throws:
NullPointerException - if nat or flav is null
Since:
1.4

addUnencodedNativeForFlavor

public void addUnencodedNativeForFlavor(DataFlavor flavor,
                                        String nativeStr)
Adds a mapping from the specified DataFlavor (and all DataFlavors equal to the specified DataFlavor) to the specified String native. Unlike getNativesForFlavor, the mapping will only be established in one direction, and the native will not be encoded. To establish a two-way mapping, call addFlavorForUnencodedNative as well. The new mapping will be of lower priority than any existing mapping. This method has no effect if a mapping from the specified or equal DataFlavor to the specified String native already exists.
Parameters:
flavor - the DataFlavor key for the mapping
nativeStr - the String native value for the mapping
Throws:
NullPointerException - if flav or nat is null
Since:
1.4

decodeDataFlavor

public static DataFlavor decodeDataFlavor(String name)
            throws ClassNotFoundException
Returns the data flavor given the native type name or null when no such data flavor exists.

decodeJavaMIMEType

public static String decodeJavaMIMEType(String name)
Decodes a String native for use as a Java MIME type.
Parameters:
name - the String to decode
Returns:
the decoded Java MIME type, or null if nat is not an encoded String native

encodeDataFlavor

public static String encodeDataFlavor(DataFlavor df)
Encodes a DataFlavor for use as a String native. The format of an encoded DataFlavor is implementation-dependent. The only restrictions are:
  • The encoded representation is null if and only if the specified DataFlavor is null or its MIME type String is null.
  • The encoded representations for two non-null DataFlavors with non-null MIME type Strings are equal if and only if the MIME type Strings of these DataFlavors are equal according to String.equals(Object).

The present implementation of this method returns the MIME type String of the specified DataFlavor prefixed with gnu.java:.

Parameters:
df - the DataFlavor to encode
Returns:
the encoded String, or null if flav is null or has a null MIME type

encodeJavaMIMEType

public static String encodeJavaMIMEType(String mime)
Encodes a MIME type for use as a String native. The format of an encoded representation of a MIME type is implementation-dependent. The only restrictions are:
  • The encoded representation is null if and only if the MIME type String is null.
  • The encoded representations for two non-null MIME type Strings are equal if and only if these Strings are equal according to String.equals(Object).

The present implementation of this method returns the specified MIME type String prefixed with gnu.java:.

Parameters:
mime - the MIME type to encode
Returns:
the encoded String, or null if mimeType is null

getDefaultFlavorMap

public static FlavorMap getDefaultFlavorMap()
Returns the (System)FlavorMap for the current thread's ClassLoader.

getFlavorsForNative

public List getFlavorsForNative(String nat)
Returns a List of DataFlavors to which the specified String native can be translated by the data transfer subsystem. The List will be sorted from best DataFlavor to worst. That is, the first DataFlavor will best reflect data in the specified native to a Java application.

If the specified native is previously unknown to the data transfer subsystem, and that native has been properly encoded, then invoking this method will establish a mapping in both directions between the specified native and a DataFlavor whose MIME type is a decoded version of the native.

Specified by:
getFlavorsForNative in interface FlavorTable

getNativesForFlavor

public List getNativesForFlavor(DataFlavor flav)
Returns a list of String natives corresponding to the given flavor. The list should be sorted from best to worst. The list must be modifiable without affecting this table.
Specified by:
getNativesForFlavor in interface FlavorTable
Parameters:
Returns:
the sorted list of natives

isJavaMIMEType

public static boolean isJavaMIMEType(String name)
Returns true if the native type name can be represented as a java mime type. Returns false if parameter is null.

setFlavorsForNative

public void setFlavorsForNative(String nativeStr,
                                DataFlavor[] flavors)
Discards the current mappings for the specified String native, and creates new mappings to the specified DataFlavors. Unlike getFlavorsForNative, the mappings will only be established in one direction, and the natives need not be encoded. To establish two-way mappings, call setNativesForFlavor as well. The first DataFlavor in the array will represent the highest priority mapping. Subsequent DataFlavors will represent mappings of decreasing priority.

If the array contains several elements that reference equal DataFlavors, this method will establish new mappings for the first of those elements and ignore the rest of them.

It is recommended that client code not reset mappings established by the data transfer subsystem. This method should only be used for application-level mappings.

Parameters:
nativeStr - the String native key for the mappings
flavors - the DataFlavor values for the mappings
Throws:
NullPointerException - if nat or flavors is null or if flavors contains null elements
Since:
1.4

setNativesForFlavor

public void setNativesForFlavor(DataFlavor flavor,
                                String[] natives)
Discards the current mappings for the specified DataFlavor and all DataFlavors equal to the specified DataFlavor, and creates new mappings to the specified String natives. Unlike getNativesForFlavor, the mappings will only be established in one direction, and the natives will not be encoded. To establish two-way mappings, call setFlavorsForNative as well. The first native in the array will represent the highest priority mapping. Subsequent natives will represent mappings of decreasing priority.

If the array contains several elements that reference equal String natives, this method will establish new mappings for the first of those elements and ignore the rest of them.

It is recommended that client code not reset mappings established by the data transfer subsystem. This method should only be used for application-level mappings.

Parameters:
flavor - the DataFlavor key for the mappings
natives - the String native values for the mappings
Throws:
NullPointerException - if flav or natives is null or if natives contains null elements
Since:
1.4

SystemFlavorMap.java -- Maps between native flavor names and MIME types. Copyright (C) 2001, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.