Skip to main content



      Home
Home » Modeling » MoDisco » How to load a Java model
How to load a Java model [message #1409886] Tue, 19 August 2014 04:13 Go to next message
Eclipse UserFriend
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 05:46 Go to previous messageGo to next message
Eclipse UserFriend
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,
Re: How to load a Java model [message #1410010 is a reply to message #1409917] Tue, 19 August 2014 10:55 Go to previous message
Eclipse UserFriend
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: Tue May 20 19:11:38 EDT 2025

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

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

Back to the top