GMF Code Samples / GMF / EMF

To load an EMF model from an XMI file (also useful for GMF):

XMIResourceImpl resource = new XMIResourceImpl();
File source = new File("src/org/openiaml/model/take/tests/test.iaml");
resource.load( new FileInputStream(source), new HashMap<Object,Object>());
root = (InternetApplication) resource.getContents().get(0);

Note that you will have to run this in a plugin environment; for example, since this is part of a JUnit test case, I need to run the JUnit test case as a plug-in test in Eclipse. This allows EMF to load the package definitions, or else I may get a PackageNotFoundException.

This code sample is also available on SVN.