Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » load a meta model and model from xmi files
load a meta model and model from xmi files [message #1811143] Tue, 27 August 2019 13:26 Go to next message
Afe Fer is currently offline Afe FerFriend
Messages: 8
Registered: August 2019
Junior Member
Hi all,

I would like to manipulate the elements of a model with Java code.

I have a meta model file (MyMetaModel.emf) and a model file (let it be myFile.model)

I managed to load the meta model using the code :
private static EPackageImpl loadEmfModel(String filePath) throws IOException, FileNotFoundException {
XMIResourceImpl resource = new XMIResourceImpl();
File source = new File(filePath);
resource.load( new FileInputStream(source), new HashMap<Object,Object>());
EPackageImpl root = (EPackageImpl) resource.getContents().get(0);
root.getEFactoryInstance();
System.out.println("EPackage" +root.getName() + " has "+root.getEClassifiers().size() + "EClassifiers");
return root;
}
which returns an Epackage.

But then I need to load the model and I use this code :
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put("model", new XMIResourceFactoryImpl() );
ResourceSet aResourceSet = new ResourceSetImpl();
URI fileUri = URI.createFileURI("Models/myFile.model");
Resource myRessource = aResourceSet.getResource(fileUri, true);
Object aDartInstance = myRessource.getContents().get(0);

But each time I try to run I have a :Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.anUIRInMyFile.model' not found. (file:///C:/Users/user/eclipse-workspace/EMFXTool/Models/myFile.model, 8, 17) exception

My questions are :
Why do I have this error?
How can I tell the loader of the model to look for the metamodel in the EMF file MyMetaModel.emf?

Thanks in avance
Re: load a meta model and model from xmi files [message #1811157 is a reply to message #1811143] Tue, 27 August 2019 19:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Invoke Generate Test Code for your *.genmodel and then look at the generated XyzExample.java that's generated for your model; use that approach.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: load a meta model and model from xmi files [message #1811202 is a reply to message #1811157] Wed, 28 August 2019 15:23 Go to previous message
Afe Fer is currently offline Afe FerFriend
Messages: 8
Registered: August 2019
Junior Member
Hi,

Thanks for your answer.

I will do that and come back to you soon.

Cheers
Previous Topic:cross Resources Error
Next Topic:Do I need to generate the code of the meta model to explore/edit existing models
Goto Forum:
  


Current Time: Thu Apr 18 23:01:39 GMT 2024

Powered by FUDForum. Page generated in 0.01999 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top