Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » How to load a Java model
How to load a Java model [message #1409886] Tue, 19 August 2014 08:13 Go to next message
keynne Belle is currently offline keynne BelleFriend
Messages: 30
Registered: January 2013
Member
Hello.
I just created a java model using a MoDisco Discoverer (Discover java project). I would like to load the corresponding xmi file in a java program so as to parse that java model. How can I load that xmi file using its full path i.e the full path of the java model?
Thanks in advance.
Re: How to load a Java model [message #1409917 is a reply to message #1409886] Tue, 19 August 2014 09:46 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 667
Registered: July 2009
Senior Member
Hello,
When serialized in XMI, the Java model can be loaded as any EMF model using the standard EMF API or the Java metamodel-specific generated API.
Please, refer to the EMF documentation and/or forum in order to do so.
Best regards,


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How to load a Java model [message #1410010 is a reply to message #1409917] Tue, 19 August 2014 14:55 Go to previous message
keynne Belle is currently offline keynne BelleFriend
Messages: 30
Registered: January 2013
Member
Thank you for your reply. It really helped. In fact, I was able to write a code to load an EMF model. But I did not know the concepts of the Java metamodel and their relationships with JDT. As a consequence, I was stuck at the instruction allowing to get the first item of my resource's content, unable to make the right cast. Your explanation combined with the following link http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.modisco.java.doc%2Fmediawiki%2Fjava_metamodel%2Fuser.html clarified the ideas in my head. Here is the code I finally wrote to load my model:
public Model loadJavaModel(String projectPath){
Model javaModel = null;
try{

// register the default resource factory
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
new XMIResourceFactoryImpl());

// create a resource set.
ResourceSet resourceSet = new ResourceSetImpl();

//get the URI of the model file.
URI fileURI = URI.createFileURI(new File(projectPath).getAbsolutePath());

//load the resource for this file
Resource resourceModel = resourceSet.getResource(fileURI, true);

// get the root element of the javamodel's project
javaModel = (Model) resourceModel.getContents().get(0);
}
catch (Exception e) {
System.out.println("An error occurred. The model can not be loaded.");
//e.printStackTrace();
}
return javaModel;

}
Previous Topic:Custom discoverer
Next Topic:Developer Setup
Goto Forum:
  


Current Time: Wed Sep 26 06:43:03 GMT 2018

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

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

Back to the top