cast eclipse.emf.ecore.xmi.impl.XMIResourceImpl to eclipse.e



我有一个简单的代码片段,它抛出:

Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl cannot be cast to org.eclipse.emf.ecore.resource.Resource$Factory

相关代码:

import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.Resource;
public class Graphe {
    public static void main(String[] args) {
        org.eclipse.emf.ecore.resource.Resource.Factory.Registry reg=org.eclipse.emf.ecore.resource.Resource.Factory.Registry.INSTANCE;
        Map<String, Object> myMap=reg.getExtensionToFactoryMap();
        myMap.put("graphes", new XMIResourceImpl());
        ResourceSet resSet=new ResourceSetImpl();
        Resource res=  resSet.getResource(URI.createURI("My.graphes"), true);//exception here
    }
}

第二行是引发异常。My.Graphes 是我用 EMF 创建的插件,并将其导出到 eclipse 主机存储库。任何帮助将不胜感激

遇到的异常是由于getExtensionToFactoryMapFactory作为映射值处理,而不是Resource。它将URI的扩展映射到将创建正确ResourceResource Factory

要处理您的问题,您只需注册XMIResourceFactoryImpl而不是XMIResourceImpl

myMap.put("graphes", new XMIResourceFactoryImpl());

相关内容

  • 没有找到相关文章

最新更新