{"id":402,"date":"2009-02-11T14:12:39","date_gmt":"2009-02-11T19:12:39","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=402"},"modified":"2009-02-19T21:17:54","modified_gmt":"2009-02-20T02:17:54","slug":"java-activation-framework","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=402","title":{"rendered":"Java Activation Framework"},"content":{"rendered":"<p><strong>Classes<\/strong><\/p>\n<ul>\n<li>DataHandler: encapsulates a data object and provide methods to act on data.\n<ul>\n<li>DataContentHandler:<br \/>\n-used by DataHandler to implement Transferable interface.<br \/>\n-uses DataFlavor to represent data type.<br \/>\n-converts data into InputStreams.<br \/>\n-java mail implements many MIME types.\n<\/li>\n<\/ul>\n<\/li>\n<li>DataSource: used to access underlying data.\n<ul>\n<li>FileDataSource\n<\/li>\n<li>URLDataSource\n<\/li>\n<\/ul>\n<\/li>\n<li>CommandMap\n<ul>\n<li>CommandObject\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Initialization<\/strong><br \/>\nFrom a system file:<\/p>\n<pre lang=\"java\">\r\nFile file = new File(file_name);\r\nDataSource ds = new FileDataSource(file);\r\nDataHandler dh = new DataHandler(ds);\r\n<\/pre>\n<p>From an object:<\/p>\n<pre lang=\"java\">\r\n\/**\r\n* Get the viewer to view my query results:\r\n*\/\r\nComponent getQueryViewer(QueryObject qo) throws Exception {\r\nString mime_type = qo.getType();\r\nObject q_result = qo.getResultObject();\r\nDataHandler my_dh = new DataHandler(q_result, mime_type);\r\nreturn (Component)my_dh.getCommand(\"view\").\r\ngetCommandObject(my_dh, null));\r\n}\r\n<\/pre>\n<p><strong>Get Command List<\/strong><\/p>\n<pre lang=\"java\">\r\n\/\/ get the command list for an object\r\nCommandInfo cmdInfo[] = dh.getPreferredCommands();\r\nPopupMenu popup = new PopupMenu(\"Item Menu\");\r\n\/\/ populate the popup with available commands\r\nfor (i = 0; i < cmdInfo.length; i++)\r\npopup.add(cmdInfo[i].getCommandName());\r\n\/\/ add and show popup\r\nadd(popup);\r\npopup.show(x_pos, y_pos);<\/pre>\n<p><strong>Performing a Command<\/strong><\/p>\n<pre lang=\"java\">\r\n\/\/ get the command object\r\nObject cmdBean = cmdInfo[cmd_id].getCommandObject(dh,\r\nthis.getClassLoader());\r\n... \/\/ use serialization\/externalization where appropriate\r\nmy_awt_container.add((Component)cmdBean);\r\n<\/pre>\n<p><strong>Caveats<\/strong><br \/>\n* 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.<br \/>\n* Also keep one javamail.jar with activation.jar or you might get javax.activation.UnsupportedDataTypeException.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. DataSource: used to &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=402\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14],"tags":[],"class_list":["post-402","post","type-post","status-publish","format-standard","hentry","category-java"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-6u","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402"}],"version-history":[{"count":7,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/402\/revisions"}],"predecessor-version":[{"id":582,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/402\/revisions\/582"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}