| How to create standalone model from .edit project in EMF? [message #1815588] |
Sun, 06 October 2019 10:44  |
Eclipse User |
|
|
|
I want to run my model (.genmodel) outside Eclipse (i.e. as a standalone model). I have done an extensive search on this. I know Edit projects can run standalone. For now I am trying to achieve this through a new plugin project. Below is the code. I am just not sure what is the correct method to achieve this. Any suggestions will be much appreciated. I am new to EMF, so don't know where to put in the main class i have written. Should it go under the Edit project or as a separate plugin?
import java.util.Collections;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
//import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
//import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import asdl.asdlPackage;
public class UsingEMFModel {
/** Create Resource Manager**/
public static void startResourceManager() {
/** Register factory**/
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
/** Register package**/
asdlPackage.eINSTANCE.eClass();
}
/**Create ResourceSet**/
public static ResourceSet createResourceSet() {
ResourceSet rs= new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new EcoreResourceFactoryImpl());
rs.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(false));
return rs;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
/**Initiate Resource Manager**/
UsingEMFModel.startResourceManager();
ResourceSet rs=UsingEMFModel.createResourceSet();
/**Get URI for model**/
URI fileURI= URI.createPlatformPluginURI("platform:/resource/TestFullIntegration/DepartureIntegration/model/landingIntegration.ecore", false);
/**Load resource for the file**/
Resource resource=rs.getResource(fileURI,true);
try {
resource.save(System.out, Collections.EMPTY_MAP);
}
catch(IOException e) {}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.09039 seconds