| Unable to load UML model in stand alone application [message #884601] |
Mon, 11 June 2012 09:07  |
Alfredo Motta Messages: 41 Registered: June 2012 |
Member |
|
|
Hello everybody,
I am really new to the Eclipse UML 2 project and I am trying to load a UML model in my standalone application. To do so I have created a new java project and I have included the following jars
org.eclipse.emf.common_2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar
org.eclipse.uml2.common_1.6.0.v201105021727.jar
org.eclipse.uml2.uml_3.2.100.v201108110105.jar
Then I have this code trying to load the UML model from the getting started guide saved under C:/ExtendedPO2.uml
public class Main {
public static void main(String[] args){
String location="c:/ExtendedPO2.uml";
Model m=load(URI.createFileURI(location));
System.out.println(m.getQualifiedName());
}
protected static Model load(URI pathToModel)
{
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
UMLPackage.eINSTANCE.eClass();
set.createResource(pathToModel);
Resource r = null;
r = set.getResource(pathToModel, true);
Model m = (Model) EcoreUtil.getObjectByType(r.getContents(),
UMLPackage.Literals.MODEL);
return m;
}
}
Unfortunately the loaded model is null and I am not able to print the qualified name.
Can someone please help me understanding what's going on?
Thank you for your help
|
|
|
|
|
|
| Re: Unable to load UML model in stand alone application [message #885947 is a reply to message #885851] |
Wed, 13 June 2012 19:02  |
Alfredo Motta Messages: 41 Registered: June 2012 |
Member |
|
|
Ok thank you.
I am not sure on how this was related to my loading problem, as you said probably it was a namespace problem. However this is the code that I have now in place together with the sample .uml file. This one works
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
public class Main {
private URI typesUri = null;
public static void main(String[] args){
Model m=new Main().getModel("C:/mylocalpathto/ExtendedPO2.uml");
System.out.println(m.getName());
}
public Model getModel(String pathToModel) {
typesUri = URI.createFileURI(pathToModel);
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.createResource(typesUri);
Resource r = set.getResource(typesUri, true);
Model m = (Model) EcoreUtil.getObjectByType(r.getContents(), UMLPackage.Literals.MODEL);
return m;
}
}
and these are the libraries I am using
org.eclipse.emf.common_2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar
org.eclipse.emf.mapping.ecore2xml_2.7.0.v20120130-0943.jar
org.eclipse.uml2.common_1.6.0.v201105021727.jar
org.eclipse.uml2.uml_3.2.100.v201108110105.jar
[Updated on: Wed, 13 June 2012 19:03] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03562 seconds