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