systemflavormap.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 430 行 · 第 1/2 页
JAVA
430 行
/* 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 modifyit under the terms of the GNU General Public License as published bythe 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, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.awt.datatransfer;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.WeakHashMap;/** * This class maps between native platform type names and DataFlavors. * * XXX - The current implementation does no mapping at all. * * @author Mark Wielaard (mark@klomp.org) * * @since 1.2 */public final class SystemFlavorMap implements FlavorMap, FlavorTable{ /** * The map which maps the thread's <code>ClassLoaders</code> to * <code>SystemFlavorMaps</code>. */ private static final Map systemFlavorMaps = new WeakHashMap(); /** * Constant which is used to prefix encode Java MIME types. */ private static final String GNU_JAVA_MIME_PREFIX = "gnu.java:"; /** * This map maps native <code>String</code>s to lists of * <code>DataFlavor</code>s */ private HashMap nativeToFlavorMap = new HashMap(); /** * This map maps <code>DataFlavor</code>s to lists of native * <code>String</code>s */ private HashMap flavorToNativeMap = new HashMap(); /** * Private constructor. */ private SystemFlavorMap () { } /** * Maps the specified <code>DataFlavor</code> objects to the native * data type name. The returned <code>Map</code> 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. * * @param flavors An array of data flavors to map * or null for all data flavors. * * @return A <code>Map</code> of native data types to data flavors. */ public Map getNativesForFlavors (DataFlavor[] flavors) { return new HashMap(); } /** * Maps the specified native type names to <code>DataFlavor</code>'s. * The returned <code>Map</code> has keys that are strings and values * that are <code>DataFlavor</code>'s. The returned map may be * modified. This can be useful for implementing nested mappings. * * @param natives An array of native types to map * or null for all native types. * * @return A <code>Map</code> of data flavors to native type names. */ public Map getFlavorsForNatives (String[] natives) { return new HashMap(); } /** * Returns the (System)FlavorMap for the current thread's * ClassLoader. */ public static FlavorMap getDefaultFlavorMap () { ClassLoader classLoader = Thread.currentThread() .getContextClassLoader(); //if ContextClassLoader not set, use system default if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } synchronized(systemFlavorMaps) { FlavorMap map = (FlavorMap) systemFlavorMaps.get(classLoader); if (map == null) { map = new SystemFlavorMap(); systemFlavorMaps.put(classLoader, map); } return map; } } /** * Encodes a MIME type for use as a <code>String</code> native. The format * of an encoded representation of a MIME type is implementation-dependent. * The only restrictions are: * <ul> * <li>The encoded representation is <code>null</code> if and only if the * MIME type <code>String</code> is <code>null</code>.</li> * <li>The encoded representations for two non-<code>null</code> MIME type * <code>String</code>s are equal if and only if these <code>String</code>s * are equal according to <code>String.equals(Object)</code>.</li> * </ul> * <p> * The present implementation of this method returns the specified MIME * type <code>String</code> prefixed with <code>gnu.java:</code>. * * @param mime the MIME type to encode * @return the encoded <code>String</code>, or <code>null</code> if * mimeType is <code>null</code> */ public static String encodeJavaMIMEType (String mime) { if (mime != null) return GNU_JAVA_MIME_PREFIX + mime; else return null; } /** * Encodes a <code>DataFlavor</code> for use as a <code>String</code> * native. The format of an encoded <code>DataFlavor</code> is * implementation-dependent. The only restrictions are: * <ul> * <li>The encoded representation is <code>null</code> if and only if the * specified <code>DataFlavor</code> is <code>null</code> or its MIME type * <code>String</code> is <code>null</code>.</li> * <li>The encoded representations for two non-<code>null</code> * <code>DataFlavor</code>s with non-<code>null</code> MIME type * <code>String</code>s are equal if and only if the MIME type * <code>String</code>s of these <code>DataFlavor</code>s are equal * according to <code>String.equals(Object)</code>.</li> * </ul> * <p> * The present implementation of this method returns the MIME type * <code>String</code> of the specified <code>DataFlavor</code> prefixed * with <code>gnu.java:</code>. * * @param df the <code>DataFlavor</code> to encode * @return the encoded <code>String</code>, or <code>null</code> if * flav is <code>null</code> or has a <code>null</code> MIME type */ public static String encodeDataFlavor (DataFlavor df) { if (df != null) { return encodeJavaMIMEType(df.getMimeType()); } else return null; } /** * Returns true if the native type name can be represented as * a java mime type. Returns <code>false</code> if parameter is * <code>null</code>. */ public static boolean isJavaMIMEType (String name) { return (name != null && name.startsWith(GNU_JAVA_MIME_PREFIX));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?