如何从EMF中的.edit项目创建独立模型?

时间:2019-10-05 17:41:01

标签: eclipse-emf

我想在Eclipse外部运行我的模型(.genmodel)(即作为独立模型)。我对此进行了广泛的搜索。我知道编辑项目可以独立运行。现在,我正在尝试通过一个新的插件项目来实现这一目标。下面是代码。我只是不确定实现此目的的正确方法是什么。任何建议将不胜感激。我是EMF的新手,所以不知道在我编写的主课程中该放在哪里。它应该放在Edit项目下还是作为单独的插件?

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) {}
}

}

0 个答案:

没有答案