1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.activation;
  6. import java.awt.datatransfer.DataFlavor;
  7. import java.awt.datatransfer.UnsupportedFlavorException;
  8. import java.io.InputStream;
  9. import java.io.IOException;
  10. import java.io.OutputStream;
  11. import javax.activation.DataSource;
  12. /**
  13. * The DataContentHandler interface is implemented by objects that can
  14. * be used to extend the capabilities of the DataHandler's implementation
  15. * of the Transferable interface. Through <code>DataContentHandlers</code>
  16. * the framework can be extended to convert streams in to objects, and
  17. * to write objects to streams. <p>
  18. *
  19. * Applications don't generally call the methods in DataContentHandlers
  20. * directly. Instead, an application calls the equivalent methods in
  21. * DataHandler. The DataHandler will attempt to find an appropriate
  22. * DataContentHandler that corresponds to its MIME type using the
  23. * current DataContentHandlerFactory. The DataHandler then calls
  24. * through to the methods in the DataContentHandler.
  25. */
  26. public interface DataContentHandler {
  27. /**
  28. * Returns an array of DataFlavor objects indicating the flavors the
  29. * data can be provided in. The array should be ordered according to
  30. * preference for providing the data (from most richly descriptive to
  31. * least descriptive).
  32. *
  33. * @return The DataFlavors.
  34. */
  35. public DataFlavor[] getTransferDataFlavors();
  36. /**
  37. * Returns an object which represents the data to be transferred.
  38. * The class of the object returned is defined by the representation class
  39. * of the flavor.
  40. *
  41. * @param df The DataFlavor representing the requested type.
  42. * @param ds The DataSource representing the data to be converted.
  43. * @return The constructed Object.
  44. */
  45. public Object getTransferData(DataFlavor df, DataSource ds)
  46. throws UnsupportedFlavorException, IOException;
  47. /**
  48. * Return an object representing the data in its most preferred form.
  49. * Generally this will be the form described by the first DataFlavor
  50. * returned by the <code>getTransferDataFlavors</code> method.
  51. *
  52. * @param ds The DataSource representing the data to be converted.
  53. * @return The constructed Object.
  54. */
  55. public Object getContent(DataSource ds) throws IOException;
  56. /**
  57. * Convert the object to a byte stream of the specified MIME type
  58. * and write it to the output stream.
  59. *
  60. * @param obj The object to be converted.
  61. * @param mimeType The requested MIME type of the resulting byte stream.
  62. * @param os The output stream into which to write the converted
  63. * byte stream.
  64. */
  65. public void writeTo(Object obj, String mimeType, OutputStream os)
  66. throws IOException;
  67. }