{"id":131,"date":"2014-01-10T10:48:14","date_gmt":"2014-01-10T08:48:14","guid":{"rendered":"http:\/\/www.descher.at\/descher-vu\/?p=131"},"modified":"2014-05-22T14:47:46","modified_gmt":"2014-05-22T12:47:46","slug":"programmatically-load-an-application-e4xmi","status":"publish","type":"post","link":"http:\/\/www.descher.at\/descher-vu\/2014\/01\/programmatically-load-an-application-e4xmi\/","title":{"rendered":"Programmatically load an Application.e4xmi"},"content":{"rendered":"<p>In case you were wondering or struggling, just like me, how one could possibly load an Application.e4xmi file out of a standalone Java application, here goes some code for you \ud83d\ude42<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport org.eclipse.e4.ui.internal.workbench.E4XMIResourceFactory;\r\n import org.eclipse.e4.ui.model.application.MApplication;\r\n import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;\r\n import org.eclipse.emf.common.util.URI;\r\n import org.eclipse.emf.ecore.resource.Resource;\r\n import org.eclipse.emf.ecore.resource.ResourceSet;\r\n import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;\r\n\r\npublic class LoadAppModel {\r\n\r\nprivate static ResourceSet resourceSet = new ResourceSetImpl();\r\n\r\npublic static void main(String&#x5B;] args) {\r\n ApplicationPackageImpl.init();\r\n URI uri = URI\r\n .createURI(&quot;file:\/\/\/Users\/marco\/git\/pharmacy_at\/at.medevit.ecrit.pharmacy_at.application\/Application.e4xmi&quot;);\r\n\r\nresourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()\r\n .put(&quot;e4xmi&quot;, new E4XMIResourceFactory());\r\n\r\nResource res = resourceSet.getResource(uri, true);\r\n MApplication app = (MApplication) res.getContents().get(0);\r\n System.out.println(app.getElementId());\r\n }\r\n }\r\n\r\nres.unload();\r\n<\/pre>\n<p>Be sure to include all the required bundles, especially in the OSGI context.<\/p>\n<p><strong>Update<\/strong> I just came up to a nasty problem: If you repeatedly iterate your application model, while modifying it, you need to be sure to unload the model each time you are done, otherwise lazy loading will not pick up the changes, as the model is already loaded.<\/p>\n<p>To depict this I added the unload method to the code sample.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case you were wondering or struggling, just like me, how one could possibly load an Application.e4xmi file out of a standalone Java application, here goes some code for you \ud83d\ude42 import org.eclipse.e4.ui.internal.workbench.E4XMIResourceFactory; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; public class LoadAppModel { private static ResourceSet resourceSet = new &hellip; <a href=\"http:\/\/www.descher.at\/descher-vu\/2014\/01\/programmatically-load-an-application-e4xmi\/\" class=\"more-link\"><span class=\"screen-reader-text\">Programmatically load an Application.e4xmi<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts\/131"}],"collection":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":8,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":199,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts\/131\/revisions\/199"}],"wp:attachment":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}