Classes
- DataHandler: encapsulates a data object and provide methods to act on data.
- DataContentHandler:
-used by DataHandler to implement Transferable interface.
-uses DataFlavor to represent data type.
-converts data into InputStreams.
-java mail implements many MIME types.
- DataContentHandler:
- DataSource: used to access underlying data.
- FileDataSource
- URLDataSource
- CommandMap
- CommandObject
Initialization
From a system file:
File file = new File(file_name); DataSource ds = new FileDataSource(file); DataHandler dh = new DataHandler(ds);
From an object:
/** * Get the viewer to view my query results: */ Component getQueryViewer(QueryObject qo) throws Exception { String mime_type = qo.getType(); Object q_result = qo.getResultObject(); DataHandler my_dh = new DataHandler(q_result, mime_type); return (Component)my_dh.getCommand("view"). getCommandObject(my_dh, null)); }
Get Command List
// get the command list for an object CommandInfo cmdInfo[] = dh.getPreferredCommands(); PopupMenu popup = new PopupMenu("Item Menu"); // populate the popup with available commands for (i = 0; i < cmdInfo.length; i++) popup.add(cmdInfo[i].getCommandName()); // add and show popup add(popup); popup.show(x_pos, y_pos);
Performing a Command
// get the command object Object cmdBean = cmdInfo[cmd_id].getCommandObject(dh, this.getClassLoader()); ... // use serialization/externalization where appropriate my_awt_container.add((Component)cmdBean);
Caveats
* Make sure there is only one activation.jar in the whole class path. Otherwise, you might get the ClassCastException. For example, put activation.jar in Tomcat “shared/lib” directory and remove it from war’s “WEB-INF/lib” directory.
* Also keep one javamail.jar with activation.jar or you might get javax.activation.UnsupportedDataTypeException.