2014-02-12 58 views
2

我正在關注加載動態元模型的文章http://www.ibm.com/developerworks/library/os-eclipse-dynamicemf/動態加載EMF模型時出錯

我加載使用此

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); 

模型實例化的文檔,但,從來就得到了XMI文件已經存在於目錄此錯誤消息

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) 

我能做什麼?

謝謝

回答

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是你的模型。