src/share/classes/java/awt/datatransfer/DataFlavor.java

Print this page




  90  * MIME type may have a "charset" parameter. Refer to
  91  * <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a> and
  92  * {@link #selectBestTextFlavor} for details on &quot;text&quot; MIME types
  93  * and the &quot;charset&quot; parameter.
  94  * <p>
  95  * Equality of {@code DataFlavors} is determined by the primary type,
  96  * subtype, and representation class. Refer to {@link #equals(DataFlavor)} for
  97  * details. When determining equality, any optional parameters are ignored.
  98  * For example, the following produces two {@code DataFlavors} that
  99  * are considered identical:
 100  * <pre>
 101  *   DataFlavor flavor1 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; foo=bar&quot;);
 102  *   DataFlavor flavor2 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; x=y&quot;);
 103  *   // The following returns true.
 104  *   flavor1.equals(flavor2);
 105  * </pre>
 106  * As mentioned, {@code flavor1} and {@code flavor2} are considered identical.
 107  * As such, asking a {@code Transferable} for either {@code DataFlavor} returns
 108  * the same results.
 109  * <p>
 110  * For more information on the using data transfer with Swing see
 111  * the <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
 112  * How to Use Drag and Drop and Data Transfer</a>,
 113  * section in <em>Java Tutorial</em>.
 114  *
 115  * @author      Blake Sullivan
 116  * @author      Laurence P. G. Cable
 117  * @author      Jeff Dunn
 118  */
 119 public class DataFlavor implements Externalizable, Cloneable {
 120 
 121     private static final long serialVersionUID = 8367026044764648243L;
 122     private static final Class<InputStream> ioInputStreamClass = InputStream.class;
 123 
 124     /**
 125      * Tries to load a class from: the bootstrap loader, the system loader,
 126      * the context loader (if one is present) and finally the loader specified.
 127      *
 128      * @param className the name of the class to be loaded
 129      * @param fallback the fallback loader
 130      * @return the class loaded


 388      *                 then the value of the the MIME Content Type is used
 389      * @exception NullPointerException if <code>representationClass</code> is null
 390      */
 391     public DataFlavor(Class<?> representationClass, String humanPresentableName) {
 392         this("application", "x-java-serialized-object", null, representationClass, humanPresentableName);
 393         if (representationClass == null) {
 394             throw new NullPointerException("representationClass");
 395         }
 396     }
 397 
 398     /**
 399      * Constructs a <code>DataFlavor</code> that represents a
 400      * <code>MimeType</code>.
 401      * <p>
 402      * The returned <code>DataFlavor</code> will have the following
 403      * characteristics:
 404      * <p>
 405      * If the <code>mimeType</code> is
 406      * "application/x-java-serialized-object; class=&lt;representation class&gt;",
 407      * the result is the same as calling
 408      * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.
 409      * <p>
 410      * Otherwise:
 411      * <pre>
 412      *     representationClass = InputStream
 413      *     mimeType            = mimeType
 414      * </pre>
 415      * @param mimeType the string used to identify the MIME type for this flavor;
 416      *                 if the the <code>mimeType</code> does not specify a
 417      *                 "class=" parameter, or if the class is not successfully
 418      *                 loaded, then an <code>IllegalArgumentException</code>
 419      *                 is thrown
 420      * @param humanPresentableName the human-readable string used to identify
 421      *                 this flavor; if this parameter is <code>null</code>
 422      *                 then the value of the the MIME Content Type is used
 423      * @exception IllegalArgumentException if <code>mimeType</code> is
 424      *                 invalid or if the class is not successfully loaded
 425      * @exception NullPointerException if <code>mimeType</code> is null
 426      */
 427     public DataFlavor(String mimeType, String humanPresentableName) {
 428         super();
 429         if (mimeType == null) {
 430             throw new NullPointerException("mimeType");
 431         }
 432         try {
 433             initialize(mimeType, humanPresentableName, this.getClass().getClassLoader());
 434         } catch (MimeTypeParseException mtpe) {
 435             throw new IllegalArgumentException("failed to parse:" + mimeType);
 436         } catch (ClassNotFoundException cnfe) {
 437             throw new IllegalArgumentException("can't find specified class: " + cnfe.getMessage());
 438         }
 439     }
 440 
 441     /**
 442      * Constructs a <code>DataFlavor</code> that represents a
 443      * <code>MimeType</code>.
 444      * <p>
 445      * The returned <code>DataFlavor</code> will have the following
 446      * characteristics:
 447      * <p>
 448      * If the mimeType is
 449      * "application/x-java-serialized-object; class=&lt;representation class&gt;",
 450      * the result is the same as calling
 451      * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.
 452      * <p>
 453      * Otherwise:
 454      * <pre>
 455      *     representationClass = InputStream
 456      *     mimeType            = mimeType
 457      * </pre>
 458      * @param mimeType the string used to identify the MIME type for this flavor
 459      * @param humanPresentableName the human-readable string used to
 460      *          identify this flavor
 461      * @param classLoader the class loader to use
 462      * @exception ClassNotFoundException if the class is not loaded
 463      * @exception IllegalArgumentException if <code>mimeType</code> is
 464      *                 invalid
 465      * @exception NullPointerException if <code>mimeType</code> is null
 466      */
 467     public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException {
 468         super();
 469         if (mimeType == null) {
 470             throw new NullPointerException("mimeType");
 471         }




  90  * MIME type may have a &quot;charset&quot; parameter. Refer to
  91  * <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a> and
  92  * {@link #selectBestTextFlavor} for details on &quot;text&quot; MIME types
  93  * and the &quot;charset&quot; parameter.
  94  * <p>
  95  * Equality of {@code DataFlavors} is determined by the primary type,
  96  * subtype, and representation class. Refer to {@link #equals(DataFlavor)} for
  97  * details. When determining equality, any optional parameters are ignored.
  98  * For example, the following produces two {@code DataFlavors} that
  99  * are considered identical:
 100  * <pre>
 101  *   DataFlavor flavor1 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; foo=bar&quot;);
 102  *   DataFlavor flavor2 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; x=y&quot;);
 103  *   // The following returns true.
 104  *   flavor1.equals(flavor2);
 105  * </pre>
 106  * As mentioned, {@code flavor1} and {@code flavor2} are considered identical.
 107  * As such, asking a {@code Transferable} for either {@code DataFlavor} returns
 108  * the same results.
 109  * <p>
 110  * For more information on using data transfer with Swing see
 111  * the <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
 112  * How to Use Drag and Drop and Data Transfer</a>,
 113  * section in <em>Java Tutorial</em>.
 114  *
 115  * @author      Blake Sullivan
 116  * @author      Laurence P. G. Cable
 117  * @author      Jeff Dunn
 118  */
 119 public class DataFlavor implements Externalizable, Cloneable {
 120 
 121     private static final long serialVersionUID = 8367026044764648243L;
 122     private static final Class<InputStream> ioInputStreamClass = InputStream.class;
 123 
 124     /**
 125      * Tries to load a class from: the bootstrap loader, the system loader,
 126      * the context loader (if one is present) and finally the loader specified.
 127      *
 128      * @param className the name of the class to be loaded
 129      * @param fallback the fallback loader
 130      * @return the class loaded


 388      *                 then the value of the the MIME Content Type is used
 389      * @exception NullPointerException if <code>representationClass</code> is null
 390      */
 391     public DataFlavor(Class<?> representationClass, String humanPresentableName) {
 392         this("application", "x-java-serialized-object", null, representationClass, humanPresentableName);
 393         if (representationClass == null) {
 394             throw new NullPointerException("representationClass");
 395         }
 396     }
 397 
 398     /**
 399      * Constructs a <code>DataFlavor</code> that represents a
 400      * <code>MimeType</code>.
 401      * <p>
 402      * The returned <code>DataFlavor</code> will have the following
 403      * characteristics:
 404      * <p>
 405      * If the <code>mimeType</code> is
 406      * "application/x-java-serialized-object; class=&lt;representation class&gt;",
 407      * the result is the same as calling
 408      * <code>new DataFlavor(Class.forName(&lt;representation class&gt;)</code>.
 409      * <p>
 410      * Otherwise:
 411      * <pre>
 412      *     representationClass = InputStream
 413      *     mimeType            = mimeType
 414      * </pre>
 415      * @param mimeType the string used to identify the MIME type for this flavor;
 416      *                 if the <code>mimeType</code> does not specify a
 417      *                 "class=" parameter, or if the class is not successfully
 418      *                 loaded, then an <code>IllegalArgumentException</code>
 419      *                 is thrown
 420      * @param humanPresentableName the human-readable string used to identify
 421      *                 this flavor; if this parameter is <code>null</code>
 422      *                 then the value of the the MIME Content Type is used
 423      * @exception IllegalArgumentException if <code>mimeType</code> is
 424      *                 invalid or if the class is not successfully loaded
 425      * @exception NullPointerException if <code>mimeType</code> is null
 426      */
 427     public DataFlavor(String mimeType, String humanPresentableName) {
 428         super();
 429         if (mimeType == null) {
 430             throw new NullPointerException("mimeType");
 431         }
 432         try {
 433             initialize(mimeType, humanPresentableName, this.getClass().getClassLoader());
 434         } catch (MimeTypeParseException mtpe) {
 435             throw new IllegalArgumentException("failed to parse:" + mimeType);
 436         } catch (ClassNotFoundException cnfe) {
 437             throw new IllegalArgumentException("can't find specified class: " + cnfe.getMessage());
 438         }
 439     }
 440 
 441     /**
 442      * Constructs a <code>DataFlavor</code> that represents a
 443      * <code>MimeType</code>.
 444      * <p>
 445      * The returned <code>DataFlavor</code> will have the following
 446      * characteristics:
 447      * <p>
 448      * If the mimeType is
 449      * "application/x-java-serialized-object; class=&lt;representation class&gt;",
 450      * the result is the same as calling
 451      * <code>new DataFlavor(Class.forName(&lt;representation class&gt;)</code>.
 452      * <p>
 453      * Otherwise:
 454      * <pre>
 455      *     representationClass = InputStream
 456      *     mimeType            = mimeType
 457      * </pre>
 458      * @param mimeType the string used to identify the MIME type for this flavor
 459      * @param humanPresentableName the human-readable string used to
 460      *          identify this flavor
 461      * @param classLoader the class loader to use
 462      * @exception ClassNotFoundException if the class is not loaded
 463      * @exception IllegalArgumentException if <code>mimeType</code> is
 464      *                 invalid
 465      * @exception NullPointerException if <code>mimeType</code> is null
 466      */
 467     public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException {
 468         super();
 469         if (mimeType == null) {
 470             throw new NullPointerException("mimeType");
 471         }