2

我正在关注文章http://www.ibm.com/developerworks/library/os-eclipse-dynamicemf/以动态加载元模型。

我使用这个加载模型实例文档

ResourceSet load_resourceSet = new ResourceSetImpl();
// ResourceSet load_resourceSet2 = new ResourceSetImpl();

/*
 * Register XMI Factory impl ementation using DEFAULT_EXTENSION
 */
load_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", //$NON-NLS-1$
            new XMIResourceFactoryImpl());

/*
 * Add bookStoreEPackage to package registry
 */
load_resourceSet.getPackageRegistry().put("http:///com.ibm.dynamic.example.bookstore.ecore",
        bookStoreEPackage);

//  load_resourceSet2.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", //$NON-NLS-1$
    // new XMIResourceFactoryImpl());

/*
 * Load the resources using the URI
 */
Resource modelo_esquerda = load_resourceSet
                .getResource(URI.createURI("./BookStore.xmi"), true);

但是,我收到了这个错误信息

Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'BookStore' is not found or is abstract. (.\BookStore.xmi, 9, 34)

XMI 文件已存在于目录中。

我可以做什么?

谢谢

4

1 回答 1

2

您可以尝试以下方法,它对我来说效果很好:

XMIResourceImpl resource = new XMIResourceImpl();
File source = new File(xmlName.xml);
resource.load(new FileInputStream(source), new HashMap<Object,Object>());
Data data = (Data) resource.getContents().get(0);

Data你的模型在哪里。

于 2014-10-31T10:14:51.953 回答