The DataHandler class provides a consistent interface to data available in many different sources and formats. It manages simple stream to string conversions and related operations using DataContentHandlers. It provides access to commands that can operate on the data. The commands are found using a
| 67 | */ |
| 68 | |
| 69 | public class DataHandler /*implements Transferable*/ { |
| 70 | |
| 71 | // Use the datasource to indicate whether we were started via the |
| 72 | // DataSource constructor or the object constructor. |
| 73 | private DataSource dataSource = null; |
| 74 | private DataSource objDataSource = null; |
| 75 | |
| 76 | // The Object and mimetype from the constructor (if passed in). |
| 77 | // object remains null if it was instantiated with a |
| 78 | // DataSource. |
| 79 | private Object object = null; |
| 80 | private String objectMimeType = null; |
| 81 | |
| 82 | // Keep track of the CommandMap |
| 83 | private CommandMap currentCommandMap = null; |
| 84 | |
| 85 | // our transfer flavors |
| 86 | private static final ActivationDataFlavor emptyFlavors[] = new ActivationDataFlavor[0]; |
| 87 | private ActivationDataFlavor transferFlavors[] = emptyFlavors; |
| 88 | |
| 89 | // our DataContentHandler |
| 90 | private DataContentHandler dataContentHandler = null; |
| 91 | private DataContentHandler factoryDCH = null; |
| 92 | |
| 93 | // our DataContentHandlerFactory |
| 94 | private static DataContentHandlerFactory factory = null; |
| 95 | private DataContentHandlerFactory oldFactory = null; |
| 96 | // the short representation of the ContentType (sans params) |
| 97 | private String shortType = null; |
| 98 | |
| 99 | /** |
| 100 | * Create a <code>DataHandler</code> instance referencing the |
| 101 | * specified DataSource. The data exists in a byte stream form. |
| 102 | * The DataSource will provide an InputStream to access the data. |
| 103 | * |
| 104 | * @param ds the DataSource |
| 105 | */ |
| 106 | public DataHandler(DataSource ds) { |
| 107 | // save a reference to the incoming DS |
| 108 | dataSource = ds; |
| 109 | oldFactory = factory; // keep track of the factory |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Create a <code>DataHandler</code> instance representing an object |
| 114 | * of this MIME type. This constructor is |
| 115 | * used when the application already has an in-memory representation |
| 116 | * of the data in the form of a Java Object. |
| 117 | * |
| 118 | * @param obj the Java Object |
| 119 | * @param mimeType the MIME type of the object |
| 120 | */ |
| 121 | public DataHandler(Object obj, String mimeType) { |
| 122 | object = obj; |
| 123 | objectMimeType = mimeType; |
| 124 | oldFactory = factory; // keep track of the factory |
| 125 | } |
| 126 |
nothing calls this directly
no outgoing calls
no test coverage detected