Dynamic Browsing and Instantiation Capabilites in EMF
EMF provides a reflective editor, which can view and edit any EMF model file, using only the model meta-data. It provides similar function to the default generated editor, but it can't be easily customized.
In this short write up I have tried to pen down the steps involved for using this reflective editor which is quiet a hidden feature in EMF.
Using the Reflective Editor – an Example
Step 1. Create an Empty EMF Project.
Step 2. Create an Ecore using the Example EMF Model Creation Wizards > Ecore Model
The Ecore editor would open with the package as null. Double Click on the package:null to update the Name and NsURI Property. NsURI should be assigned the resource path where the ecore is found. For e.g. /resource/<Plugin Name>/<Folder Name>/<Ecore Name>.ecore
Step 3. Update the Ecore to represent your model.
Step 4. Once the ecore is updated, right click on the RootObject of your model that you would want to instantiate and select Create Dynamic Instance...
Step 5. Selecting this would open a Wizard for creating a Dynamic Instantiation of your created Model. Provide the <filename>.xmi wherein you would like to serialise your instantiated data.
Step 6. This would open an instance of the Reflective Editor in Eclipse, loading the created <filename>.xmi that contains the instance of your model's rootObject.
In the editor, you would find two root nodes one pointing to the newly created .xmi file and the other pointing the .ecore file.
What this means is the Meta model that was created in the Ecore has been instantiated using this .xmi file. This is because earlier to the root package we assigned the Ns URI property to use this ecore file.