jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4267 3dee4217d3dc
child 16705 1caaa379eded
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
     2
 * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.datatransfer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.awt.datatransfer.DataTransferer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A {@code DataFlavor} provides meta information about data. {@code DataFlavor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * is typically used to access data on the clipboard, or during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a drag and drop operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * An instance of {@code DataFlavor} encapsulates a content type as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * defined in <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A content type is typically referred to as a MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * A content type consists of a media type (referred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * to as the primary type), a subtype, and optional parameters. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * for details on the syntax of a MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The JRE data transfer implementation interprets the parameter &quot;class&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * of a MIME type as <B>a representation class</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The representation class reflects the class of the object being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * transferred. In other words, the representation class is the type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * object returned by {@link Transferable#getTransferData}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * For example, the MIME type of {@link #imageFlavor} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * {@code "image/x-java-image;class=java.awt.Image"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the primary type is {@code image}, the subtype is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * {@code x-java-image}, and the representation class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * {@code java.awt.Image}. When {@code getTransferData} is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * with a {@code DataFlavor} of {@code imageFlavor}, an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * {@code java.awt.Image} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * It's important to note that {@code DataFlavor} does no error checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * against the representation class. It is up to consumers of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * {@code DataFlavor}, such as {@code Transferable}, to honor the representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Note, if you do not specify a representation class when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * creating a {@code DataFlavor}, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * representation class is used. See appropriate documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * {@code DataFlavor}'s constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Also, {@code DataFlavor} instances with the &quot;text&quot; primary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * MIME type may have a &quot;charset&quot; parameter. Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * {@link #selectBestTextFlavor} for details on &quot;text&quot; MIME types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * and the &quot;charset&quot; parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Equality of {@code DataFlavors} is determined by the primary type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * subtype, and representation class. Refer to {@link #equals(DataFlavor)} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * details. When determining equality, any optional parameters are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * For example, the following produces two {@code DataFlavors} that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * are considered identical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *   DataFlavor flavor1 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; foo=bar&quot;);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   DataFlavor flavor2 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; x=y&quot;);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *   // The following returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *   flavor1.equals(flavor2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * As mentioned, {@code flavor1} and {@code flavor2} are considered identical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * As such, asking a {@code Transferable} for either {@code DataFlavor} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * the same results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * For more information on the using data transfer with Swing see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * the <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * How to Use Drag and Drop and Data Transfer</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * section in <em>Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @author      Blake Sullivan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @author      Laurence P. G. Cable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @author      Jeff Dunn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
public class DataFlavor implements Externalizable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final long serialVersionUID = 8367026044764648243L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final Class ioInputStreamClass = java.io.InputStream.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Tries to load a class from: the bootstrap loader, the system loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the context loader (if one is present) and finally the loader specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param className the name of the class to be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param fallback the fallback loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return the class loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @exception ClassNotFoundException if class is not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected final static Class<?> tryToLoadClass(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                   ClassLoader fallback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        ClassLoader systemClassLoader = (ClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        ClassLoader cl = Thread.currentThread().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                            getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        return (cl != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                            ? cl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                            : ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return Class.forName(className, true, systemClassLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } catch (ClassNotFoundException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (fallback != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                return Class.forName(className, true, fallback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                throw new ClassNotFoundException(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * private initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    static private DataFlavor createConstant(Class rc, String prn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return new DataFlavor(rc, prn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * private initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    static private DataFlavor createConstant(String mt, String prn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return new DataFlavor(mt, prn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * The <code>DataFlavor</code> representing a Java Unicode String class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *     representationClass = java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *     mimeType           = "application/x-java-serialized-object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public static final DataFlavor stringFlavor = createConstant(java.lang.String.class, "Unicode String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The <code>DataFlavor</code> representing a Java Image class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *     representationClass = java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *     mimeType            = "image/x-java-image"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static final DataFlavor imageFlavor = createConstant("image/x-java-image; class=java.awt.Image", "Image");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * The <code>DataFlavor</code> representing plain text with Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * encoding, where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *     representationClass = InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *     mimeType            = "text/plain; charset=unicode"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * This <code>DataFlavor</code> has been <b>deprecated</b> because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * (1) Its representation is an InputStream, an 8-bit based representation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * while Unicode is a 16-bit character set; and (2) The charset "unicode"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * is not well-defined. "unicode" implies a particular platform's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * implementation of Unicode, not a cross-platform implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @deprecated as of 1.3. Use <code>DataFlavor.getReaderForText(Transferable)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *             instead of <code>Transferable.getTransferData(DataFlavor.plainTextFlavor)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static final DataFlavor plainTextFlavor = createConstant("text/plain; charset=unicode; class=java.io.InputStream", "Plain Text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * A MIME Content-Type of application/x-java-serialized-object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * a graph of Java object(s) that have been made persistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * The representation class associated with this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * identifies the Java type of an object returned as a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * from an invocation <code>java.awt.datatransfer.getTransferData</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public static final String javaSerializedObjectMimeType = "application/x-java-serialized-object";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * To transfer a list of files to/from Java (and the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * platform) a <code>DataFlavor</code> of this type/subtype and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * representation class of <code>java.util.List</code> is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Each element of the list is required/guaranteed to be of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <code>java.io.File</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public static final DataFlavor javaFileListFlavor = createConstant("application/x-java-file-list;class=java.util.List", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * To transfer a reference to an arbitrary Java object reference that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * has no associated MIME Content-type, across a <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * interface WITHIN THE SAME JVM, a <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * with this type/subtype is used, with a <code>representationClass</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * equal to the type of the class/interface being passed across the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <code>Transferable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * The object reference returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <code>Transferable.getTransferData</code> for a <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * with this MIME Content-Type is required to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * an instance of the representation Class of the <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static final String javaJVMLocalObjectMimeType = "application/x-java-jvm-local-objectref";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * In order to pass a live link to a Remote object via a Drag and Drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <code>ACTION_LINK</code> operation a Mime Content Type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * application/x-java-remote-object should be used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * where the representation class of the <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * represents the type of the <code>Remote</code> interface to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * transferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public static final String javaRemoteObjectMimeType = "application/x-java-remote-object";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Constructs a new <code>DataFlavor</code>.  This constructor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * provided only for the purpose of supporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>Externalizable</code> interface.  It is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * intended for public (client) use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public DataFlavor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Constructs a fully specified <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @exception NullPointerException if either <code>primaryType</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *            <code>subType</code> or <code>representationClass</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class representationClass, String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (primaryType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            throw new NullPointerException("primaryType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (subType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            throw new NullPointerException("subType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            throw new NullPointerException("representationClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (params == null) params = new MimeTypeParameterList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        params.set("class", representationClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (humanPresentableName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            humanPresentableName = (String)params.get("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (humanPresentableName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                humanPresentableName = primaryType + "/" + subType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            mimeType = new MimeType(primaryType, subType, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            throw new IllegalArgumentException("MimeType Parse Exception: " + mtpe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        this.representationClass  = representationClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        this.humanPresentableName = humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        mimeType.removeParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Constructs a <code>DataFlavor</code> that represents a Java class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * The returned <code>DataFlavor</code> will have the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *    representationClass = representationClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *    mimeType            = application/x-java-serialized-object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param representationClass the class used to transfer data in this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param humanPresentableName the human-readable string used to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *                 this flavor; if this parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *                 then the value of the the MIME Content Type is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @exception NullPointerException if <code>representationClass</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public DataFlavor(Class<?> representationClass, String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        this("application", "x-java-serialized-object", null, representationClass, humanPresentableName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            throw new NullPointerException("representationClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Constructs a <code>DataFlavor</code> that represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <code>MimeType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * The returned <code>DataFlavor</code> will have the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * If the <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * "application/x-java-serialized-object; class=&lt;representation class&gt;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the result is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Otherwise:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *     representationClass = InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *     mimeType            = mimeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @param mimeType the string used to identify the MIME type for this flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *                 if the the <code>mimeType</code> does not specify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *                 "class=" parameter, or if the class is not successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *                 loaded, then an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *                 is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @param humanPresentableName the human-readable string used to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *                 this flavor; if this parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *                 then the value of the the MIME Content Type is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @exception IllegalArgumentException if <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *                 invalid or if the class is not successfully loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @exception NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public DataFlavor(String mimeType, String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            initialize(mimeType, humanPresentableName, this.getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw new IllegalArgumentException("failed to parse:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        } catch (ClassNotFoundException cnfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            throw new IllegalArgumentException("can't find specified class: " + cnfe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Constructs a <code>DataFlavor</code> that represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <code>MimeType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * The returned <code>DataFlavor</code> will have the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * If the mimeType is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * "application/x-java-serialized-object; class=&lt;representation class&gt;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * the result is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Otherwise:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *     representationClass = InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *     mimeType            = mimeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @param mimeType the string used to identify the MIME type for this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param humanPresentableName the human-readable string used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *          identify this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @param classLoader the class loader to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @exception ClassNotFoundException if the class is not loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @exception IllegalArgumentException if <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *                 invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @exception NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            initialize(mimeType, humanPresentableName, classLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            throw new IllegalArgumentException("failed to parse:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Constructs a <code>DataFlavor</code> from a <code>mimeType</code> string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * The string can specify a "class=<fully specified Java class name>"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * parameter to create a <code>DataFlavor</code> with the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * representation class. If the string does not contain "class=" parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <code>java.io.InputStream</code> is used as default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param mimeType the string used to identify the MIME type for this flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *                 if the class specified by "class=" parameter is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *                 successfully loaded, then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *                 <code>ClassNotFoundException</code> is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @exception ClassNotFoundException if the class is not loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @exception IllegalArgumentException if <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *                 invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @exception NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public DataFlavor(String mimeType) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            initialize(mimeType, null, this.getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            throw new IllegalArgumentException("failed to parse:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    * Common initialization code called from various constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    * @param mimeType the MIME Content Type (must have a class= param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    * @param humanPresentableName the human Presentable Name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    *                 <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    * @param classLoader the fallback class loader to resolve against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    * @throws MimeTypeParseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    * @throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    * @throws  NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    * @see tryToLoadClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        this.mimeType = new MimeType(mimeType); // throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        String rcn = getParameter("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (rcn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if ("application/x-java-serialized-object".equals(this.mimeType.getBaseType()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                throw new IllegalArgumentException("no representation class specified for:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                representationClass = java.io.InputStream.class; // default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        } else { // got a class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            representationClass = DataFlavor.tryToLoadClass(rcn, classLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        this.mimeType.setParameter("class", representationClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (humanPresentableName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            humanPresentableName = this.mimeType.getParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (humanPresentableName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                humanPresentableName = this.mimeType.getPrimaryType() + "/" + this.mimeType.getSubType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        this.humanPresentableName = humanPresentableName; // set it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        this.mimeType.removeParameter("humanPresentableName"); // just in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * String representation of this <code>DataFlavor</code> and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * parameters. The resulting <code>String</code> contains the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * the <code>DataFlavor</code> class, this flavor's MIME type, and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * representation class. If this flavor has a primary MIME type of "text",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * supports the charset parameter, and has an encoded representation, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * flavor's charset is also included. See <code>selectBestTextFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * for a list of text flavors which support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @return  string representation of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        String string = getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        string += "["+paramString()+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    private String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        String params = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        params += "mimetype=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            params += "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            params += mimeType.getBaseType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        params += ";representationclass=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
           params += "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
           params += representationClass.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (DataTransferer.isFlavorCharsetTextType(this) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            (isRepresentationClassInputStream() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
             isRepresentationClassByteBuffer() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
             DataTransferer.byteArrayClass.equals(representationClass)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            params += ";charset=" + DataTransferer.getTextCharset(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * Returns a <code>DataFlavor</code> representing plain text with Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * encoding, where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *     representationClass = java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *     mimeType            = "text/plain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *                            charset=&lt;platform default Unicode encoding&gt;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Sun's implementation for Microsoft Windows uses the encoding <code>utf-16le</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Sun's implementation for Solaris and Linux uses the encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <code>iso-10646-ucs-2</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @return a <code>DataFlavor</code> representing plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *    with Unicode encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public static final DataFlavor getTextPlainUnicodeFlavor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        String encoding = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        DataTransferer transferer = DataTransferer.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (transferer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            encoding = transferer.getDefaultUnicodeEncoding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return new DataFlavor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            "text/plain;charset="+encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            +";class=java.io.InputStream", "Plain Text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Selects the best text <code>DataFlavor</code> from an array of <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * DataFlavor</code>s. Only <code>DataFlavor.stringFlavor</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * equivalent flavors, and flavors that have a primary MIME type of "text",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * are considered for selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Flavors are first sorted by their MIME types in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * <li>"text/sgml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <li>"text/xml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <li>"text/html"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <li>"text/rtf"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * <li>"text/enriched"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <li>"text/richtext"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <li>"text/uri-list"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * <li>"text/tab-separated-values"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <li>"text/t140"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <li>"text/rfc822-headers"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * <li>"text/parityfec"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * <li>"text/directory"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <li>"text/css"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <li>"text/calendar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * <li>"application/x-java-serialized-object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <li>"text/plain"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * <li>"text/&lt;other&gt;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p>For example, "text/sgml" will be selected over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * "text/html", and <code>DataFlavor.stringFlavor</code> will be chosen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * over <code>DataFlavor.plainTextFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * If two or more flavors share the best MIME type in the array, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * MIME type will be checked to see if it supports the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * The following MIME types support, or are treated as though they support,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * the charset parameter:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * <li>"text/sgml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <li>"text/xml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * <li>"text/html"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <li>"text/enriched"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * <li>"text/richtext"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <li>"text/uri-list"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <li>"text/directory"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * <li>"text/css"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * <li>"text/calendar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <li>"application/x-java-serialized-object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <li>"text/plain"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * The following MIME types do not support, or are treated as though they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * do not support, the charset parameter:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <li>"text/rtf"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * <li>"text/tab-separated-values"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <li>"text/t140"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <li>"text/rfc822-headers"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <li>"text/parityfec"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * For "text/&lt;other&gt;" MIME types, the first time the JRE needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * determine whether the MIME type supports the charset parameter, it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * check whether the parameter is explicitly listed in an arbitrarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * chosen <code>DataFlavor</code> which uses that MIME type. If so, the JRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * will assume from that point on that the MIME type supports the charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * parameter and will not check again. If the parameter is not explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * listed, the JRE will assume from that point on that the MIME type does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * not support the charset parameter and will not check again. Because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * this check is performed on an arbitrarily chosen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * <code>DataFlavor</code>, developers must ensure that all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <code>DataFlavor</code>s with a "text/&lt;other&gt;" MIME type specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * the charset parameter if it is supported by that MIME type. Developers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * should never rely on the JRE to substitute the platform's default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * charset for a "text/&lt;other&gt;" DataFlavor. Failure to adhere to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * restriction will lead to undefined behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * If the best MIME type in the array does not support the charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * parameter, the flavors which share that MIME type will then be sorted by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * their representation classes in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <code>[B</code>, &lt;all others&gt;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * If two or more flavors share the best representation class, or if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * flavor has one of the three specified representations, then one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * flavors will be chosen non-deterministically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * If the best MIME type in the array does support the charset parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * the flavors which share that MIME type will then be sorted by their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * representation classes in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <code>java.nio.CharBuffer</code>, <code>[C</code>, &lt;all others&gt;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * If two or more flavors share the best representation class, and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * representation is one of the four explicitly listed, then one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * flavors will be chosen non-deterministically. If, however, no flavor has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * one of the four specified representations, the flavors will then be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * sorted by their charsets. Unicode charsets, such as "UTF-16", "UTF-8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * "UTF-16BE", "UTF-16LE", and their aliases, are considered best. After
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * them, the platform default charset and its aliases are selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * "US-ASCII" and its aliases are worst. All other charsets are chosen in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * alphabetical order, but only charsets supported by this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * of the Java platform will be considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * If two or more flavors share the best charset, the flavors will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * again be sorted by their representation classes in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * <code>[B</code>, &lt;all others&gt;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * If two or more flavors share the best representation class, or if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * flavor has one of the three specified representations, then one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * flavors will be chosen non-deterministically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @param availableFlavors an array of available <code>DataFlavor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return the best (highest fidelity) flavor according to the rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *         specified above, or <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *         if <code>availableFlavors</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *         has zero length, or contains no text flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public static final DataFlavor selectBestTextFlavor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                                       DataFlavor[] availableFlavors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (availableFlavors == null || availableFlavors.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (textFlavorComparator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            textFlavorComparator = new TextFlavorComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        DataFlavor bestFlavor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            (DataFlavor)Collections.max(Arrays.asList(availableFlavors),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                        textFlavorComparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        if (!bestFlavor.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return bestFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private static Comparator textFlavorComparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    static class TextFlavorComparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        extends DataTransferer.DataFlavorComparator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         * Compares two <code>DataFlavor</code> objects. Returns a negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
         * integer, zero, or a positive integer as the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         * <code>DataFlavor</code> is worse than, equal to, or better than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
         * second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         * <code>DataFlavor</code>s are ordered according to the rules outlined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
         * for <code>selectBestTextFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         * @param obj1 the first <code>DataFlavor</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
         * @param obj2 the second <code>DataFlavor</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
         * @return a negative integer, zero, or a positive integer as the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         *         argument is worse, equal to, or better than the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         * @throws ClassCastException if either of the arguments is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
         *         instance of <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
         * @throws NullPointerException if either of the arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
         *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
         * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        public int compare(Object obj1, Object obj2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            DataFlavor flavor1 = (DataFlavor)obj1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            DataFlavor flavor2 = (DataFlavor)obj2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            if (flavor1.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                if (flavor2.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    return super.compare(obj1, obj2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            } else if (flavor2.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Gets a Reader for a text flavor, decoded, if necessary, for the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * charset (encoding). The supported representation classes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * <code>java.nio.CharBuffer</code>, <code>[C</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * and <code>[B</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Because text flavors which do not support the charset parameter are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * encoded in a non-standard format, this method should not be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * such flavors. However, in order to maintain backward-compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * if this method is called for such a flavor, this method will treat the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * flavor as though it supports the charset parameter and attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * decode it accordingly. See <code>selectBestTextFlavor</code> for a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * of text flavors which do not support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @param transferable the <code>Transferable</code> whose data will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *        requested in this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @return a <code>Reader</code> to read the <code>Transferable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *         data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @exception IllegalArgumentException if the representation class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *            is not one of the seven listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @exception IllegalArgumentException if the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *            has <code>null</code> data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @exception NullPointerException if the <code>Transferable</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *            <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @exception UnsupportedEncodingException if this flavor's representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *            is <code>java.io.InputStream</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *            <code>java.nio.ByteBuffer</code>, or <code>[B</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *            this flavor's encoding is not supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *            implementation of the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @exception UnsupportedFlavorException if the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *            does not support this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @exception IOException if the data cannot be read because of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *            I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public Reader getReaderForText(Transferable transferable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        throws UnsupportedFlavorException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        Object transferObject = transferable.getTransferData(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        if (transferObject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                ("getTransferData() returned null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (transferObject instanceof Reader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            return (Reader)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        } else if (transferObject instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            return new StringReader((String)transferObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        } else if (transferObject instanceof CharBuffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            CharBuffer buffer = (CharBuffer)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            int size = buffer.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            char[] chars = new char[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            buffer.get(chars, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            return new CharArrayReader(chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        } else if (transferObject instanceof char[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            return new CharArrayReader((char[])transferObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        InputStream stream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        if (transferObject instanceof InputStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            stream = (InputStream)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        } else if (transferObject instanceof ByteBuffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            ByteBuffer buffer = (ByteBuffer)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            int size = buffer.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            byte[] bytes = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            buffer.get(bytes, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            stream = new ByteArrayInputStream(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        } else if (transferObject instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            stream = new ByteArrayInputStream((byte[])transferObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        if (stream == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            throw new IllegalArgumentException("transfer data is not Reader, String, CharBuffer, char array, InputStream, ByteBuffer, or byte array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        String encoding = getParameter("charset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        return (encoding == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            ? new InputStreamReader(stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            : new InputStreamReader(stream, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Returns the MIME type string for this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @return the MIME type string for this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    public String getMimeType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        return (mimeType != null) ? mimeType.toString() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * Returns the <code>Class</code> which objects supporting this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * <code>DataFlavor</code> will return when this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * is requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * @return the <code>Class</code> which objects supporting this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * <code>DataFlavor</code> will return when this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * is requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    public Class<?> getRepresentationClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        return representationClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * Returns the human presentable name for the data format that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <code>DataFlavor</code> represents.  This name would be localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * for different countries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @return the human presentable name for the data format that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *    <code>DataFlavor</code> represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public String getHumanPresentableName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        return humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * Returns the primary MIME type for this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @return the primary MIME type of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public String getPrimaryType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        return (mimeType != null) ? mimeType.getPrimaryType() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Returns the sub MIME type of this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @return the Sub MIME type of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    public String getSubType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        return (mimeType != null) ? mimeType.getSubType() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * Returns the human presentable name for this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * if <code>paramName</code> equals "humanPresentableName".  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * returns the MIME type value associated with <code>paramName</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @param paramName the parameter name requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @return the value of the name parameter, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     *  if there is no associated value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    public String getParameter(String paramName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        if (paramName.equals("humanPresentableName")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            return humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            return (mimeType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                ? mimeType.getParameter(paramName) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * Sets the human presentable name for the data format that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * <code>DataFlavor</code> represents. This name would be localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * for different countries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @param humanPresentableName the new human presentable name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    public void setHumanPresentableName(String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        this.humanPresentableName = humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * The equals comparison for the {@code DataFlavor} class is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * as follows: Two <code>DataFlavor</code>s are considered equal if and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * only if their MIME primary type and subtype and representation class are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * equal. Additionally, if the primary type is "text", the subtype denotes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * a text flavor which supports the charset parameter, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * representation class is not <code>java.io.Reader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * <code>java.lang.String</code>, <code>java.nio.CharBuffer</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * <code>[C</code>, the <code>charset</code> parameter must also be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * If a charset is not explicitly specified for one or both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * <code>DataFlavor</code>s, the platform default encoding is assumed. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * <code>selectBestTextFlavor</code> for a list of text flavors which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @param o the <code>Object</code> to compare with <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @return <code>true</code> if <code>that</code> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *         <code>DataFlavor</code>; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return ((o instanceof DataFlavor) && equals((DataFlavor)o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * This method has the same behavior as {@link #equals(Object)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * The only difference being that it takes a {@code DataFlavor} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * as a parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @param that the <code>DataFlavor</code> to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *        <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @return <code>true</code> if <code>that</code> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     *         <code>DataFlavor</code>; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    public boolean equals(DataFlavor that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        if (that == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        if (this == that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            if (that.getRepresentationClass() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            if (!representationClass.equals(that.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            if (that.mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            if (!mimeType.match(that.mimeType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            if ("text".equals(getPrimaryType()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                DataTransferer.doesSubtypeSupportCharset(this) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                representationClass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                !(isRepresentationClassReader() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                  String.class.equals(representationClass) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                  isRepresentationClassCharBuffer() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                  DataTransferer.charArrayClass.equals(representationClass)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                String thisCharset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    DataTransferer.canonicalName(getParameter("charset"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                String thatCharset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    DataTransferer.canonicalName(that.getParameter("charset"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                if (thisCharset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    if (thatCharset != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    if (!thisCharset.equals(thatCharset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * Compares only the <code>mimeType</code> against the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * <code>String</code> and <code>representationClass</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * not considered in the comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * If <code>representationClass</code> needs to be compared, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * <code>equals(new DataFlavor(s))</code> may be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @deprecated As inconsistent with <code>hashCode()</code> contract,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *             use <code>isMimeTypeEqual(String)</code> instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @param s the {@code mimeType} to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @return true if the String (MimeType) is equal; false otherwise or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     *         {@code s} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public boolean equals(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        if (s == null || mimeType == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        return isMimeTypeEqual(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * Returns hash code for this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * For two equal <code>DataFlavor</code>s, hash codes are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * For the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * that matches <code>DataFlavor.equals(String)</code>, it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * guaranteed that <code>DataFlavor</code>'s hash code is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * to the hash code of the <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @return a hash code for this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        if (representationClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            total += representationClass.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            String primaryType = mimeType.getPrimaryType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            if (primaryType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                total += primaryType.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            // Do not add subType.hashCode() to the total. equals uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            // MimeType.match which reports a match if one or both of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            // subTypes is '*', regardless of the other subType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            if ("text".equals(primaryType) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                DataTransferer.doesSubtypeSupportCharset(this) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                representationClass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                !(isRepresentationClassReader() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                  String.class.equals(representationClass) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                  isRepresentationClassCharBuffer() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                  DataTransferer.charArrayClass.equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                  (representationClass)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                String charset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                    DataTransferer.canonicalName(getParameter("charset"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                if (charset != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                    total += charset.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * Identical to {@link #equals(DataFlavor)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * @param that the <code>DataFlavor</code> to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *        <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * @return <code>true</code> if <code>that</code> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     *         <code>DataFlavor</code>; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    public boolean match(DataFlavor that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        return equals(that);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * Returns whether the string representation of the MIME type passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * is equivalent to the MIME type of this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * Parameters are not included in the comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @param mimeType the string representation of the MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * @return true if the string representation of the MIME type passed in is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     *         equivalent to the MIME type of this <code>DataFlavor</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *         false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @throws NullPointerException if mimeType is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public boolean isMimeTypeEqual(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // JCK Test DataFlavor0117: if 'mimeType' is null, throw NPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        if (this.mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            return this.mimeType.match(new MimeType(mimeType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * Compares the <code>mimeType</code> of two <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * objects. No parameters are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @param dataFlavor the <code>DataFlavor</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * @return true if the <code>MimeType</code>s are equal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *  otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    public final boolean isMimeTypeEqual(DataFlavor dataFlavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        return isMimeTypeEqual(dataFlavor.mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * Compares the <code>mimeType</code> of two <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * objects.  No parameters are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * @return true if the <code>MimeType</code>s are equal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *  otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    private boolean isMimeTypeEqual(MimeType mtype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if (this.mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            return (mtype == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        return mimeType.match(mtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    * Does the <code>DataFlavor</code> represent a serialized object?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    public boolean isMimeTypeSerializedObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        return isMimeTypeEqual(javaSerializedObjectMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    public final Class<?> getDefaultRepresentationClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        return ioInputStreamClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    public final String getDefaultRepresentationClassAsString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        return getDefaultRepresentationClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    * Does the <code>DataFlavor</code> represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    * <code>java.io.InputStream</code>?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    public boolean isRepresentationClassInputStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        return ioInputStreamClass.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * Returns whether the representation class for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * <code>DataFlavor</code> is <code>java.io.Reader</code> or a subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * thereof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    public boolean isRepresentationClassReader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        return java.io.Reader.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * Returns whether the representation class for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * <code>DataFlavor</code> is <code>java.nio.CharBuffer</code> or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * subclass thereof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    public boolean isRepresentationClassCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        return java.nio.CharBuffer.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * Returns whether the representation class for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * <code>DataFlavor</code> is <code>java.nio.ByteBuffer</code> or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * subclass thereof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    public boolean isRepresentationClassByteBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        return java.nio.ByteBuffer.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    * Returns true if the representation class can be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    * @return true if the representation class can be serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    public boolean isRepresentationClassSerializable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        return java.io.Serializable.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    * Returns true if the representation class is <code>Remote</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    * @return true if the representation class is <code>Remote</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    public boolean isRepresentationClassRemote() {
4267
3dee4217d3dc 6890458: Datatransfer API should not require RMI to be present
alanb
parents: 2
diff changeset
  1187
        return DataTransferer.isRemote(representationClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    * Returns true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    * a serialized object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    * @return true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    *   a Serialized Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public boolean isFlavorSerializedObjectType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        return isRepresentationClassSerializable() && isMimeTypeEqual(javaSerializedObjectMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * Returns true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * a remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * @return true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *  a Remote Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    public boolean isFlavorRemoteObjectType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        return isRepresentationClassRemote()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            && isRepresentationClassSerializable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            && isMimeTypeEqual(javaRemoteObjectMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    * Returns true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    * a list of file objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    * @return true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    *   a List of File objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
   public boolean isFlavorJavaFileListType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if (mimeType == null || representationClass == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        return java.util.List.class.isAssignableFrom(representationClass) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
               mimeType.match(javaFileListFlavor.mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Returns whether this <code>DataFlavor</code> is a valid text flavor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * this implementation of the Java platform. Only flavors equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * <code>DataFlavor.stringFlavor</code> and <code>DataFlavor</code>s with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * a primary MIME type of "text" can be valid text flavors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * If this flavor supports the charset parameter, it must be equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * <code>DataFlavor.stringFlavor</code>, or its representation must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * <code>java.nio.CharBuffer</code>, <code>[C</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * <code>[B</code>. If the representation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * <code>[B</code>, then this flavor's <code>charset</code> parameter must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * be supported by this implementation of the Java platform. If a charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * is not specified, then the platform default charset, which is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * supported, is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * If this flavor does not support the charset parameter, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * representation must be <code>java.io.InputStream</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * <code>java.nio.ByteBuffer</code>, or <code>[B</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * See <code>selectBestTextFlavor</code> for a list of text flavors which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * @return <code>true</code> if this <code>DataFlavor</code> is a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *         text flavor as described above; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    public boolean isFlavorTextType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        return (DataTransferer.isFlavorCharsetTextType(this) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                DataTransferer.isFlavorNoncharsetTextType(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    * Serializes this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
   public synchronized void writeExternal(ObjectOutput os) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
       if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
           mimeType.setParameter("humanPresentableName", humanPresentableName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
           os.writeObject(mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
           mimeType.removeParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
       } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
           os.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
       os.writeObject(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    * Restores this <code>DataFlavor</code> from a Serialized state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
   public synchronized void readExternal(ObjectInput is) throws IOException , ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
       String rcn = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        mimeType = (MimeType)is.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            humanPresentableName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                mimeType.getParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            mimeType.removeParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            rcn = mimeType.getParameter("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            if (rcn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                throw new IOException("no class parameter specified in: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                                      mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            representationClass = (Class)is.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        } catch (OptionalDataException ode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            if (!ode.eof || ode.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                throw ode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            // Ensure backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            // Old versions didn't write the representation class to the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            if (rcn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                representationClass =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    * Returns a clone of this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    * @return a clone of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    public Object clone() throws CloneNotSupportedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        Object newObj = super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            ((DataFlavor)newObj).mimeType = (MimeType)mimeType.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        return newObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    } // clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    * Called on <code>DataFlavor</code> for every MIME Type parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    * to allow <code>DataFlavor</code> subclasses to handle special
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    * parameters like the text/plain <code>charset</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    * parameters, whose values are case insensitive.  (MIME type parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    * values are supposed to be case sensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    * This method is called for each parameter name/value pair and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    * return the normalized representation of the <code>parameterValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    * This method is never invoked by this implementation from 1.1 onwards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        return parameterValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    * Called for each MIME type string to give <code>DataFlavor</code> subtypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    * the opportunity to change how the normalization of MIME types is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    * accomplished.  One possible use would be to add default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    * parameter/value pairs in cases where none are present in the MIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    * type string passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    * This method is never invoked by this implementation from 1.1 onwards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    protected String normalizeMimeType(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        return mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    /* placeholder for caching any platform-specific data for flavor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    transient int       atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    /* Mime Type of DataFlavor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    MimeType            mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    private String      humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    /** Java class of objects this DataFlavor represents **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    private Class       representationClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
} // class DataFlavor