Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 Tools » Unable to load UML model in stand alone application
Unable to load UML model in stand alone application [message #884601] Mon, 11 June 2012 09:07 Go to next message
Alfredo Motta is currently offline 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 #885046 is a reply to message #884601] Tue, 12 June 2012 06:45 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
HI

It looks like your package registrations are wrong, but since you
haven't provided your ExtendedPO2.uml it's difficult to check.

Juno makes this all much easier by providing

ResourceSet set = new ResourceSetImpl();
UMLResourcesUtil.init(set);

Regards

Ed Willink

On 11/06/2012 14:07, Alfredo Motta wrote:
> 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 #885848 is a reply to message #885046] Wed, 13 June 2012 14:06 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo Motta
Messages: 41
Registered: June 2012
Member
Edward Willink wrote on Tue, 12 June 2012 06:45
HI

It looks like your package registrations are wrong, but since you
haven't provided your ExtendedPO2.uml it's difficult to check.



Thank you, still not clear to me what is the problem ,attached there is the .uml file, hope it helps
Re: Unable to load UML model in stand alone application [message #885851 is a reply to message #885848] Wed, 13 June 2012 14:11 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I finally got fed up with answering this generic question. I looked at
http://wiki.eclipse.org/MDT/UML2/Getting_Started_with_UML2; it has a
major howler in it regarding "save" that makes life very hard for new
users. https://bugs.eclipse.org/bugs/show_bug.cgi?id=382342 raised. Wiki
corrected.

There is an attachment to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382342 that you may
download to give a working example standalone project.

Regards

Ed Willink


On 13/06/2012 19:06, Alfredo Motta wrote:
> Edward Willink wrote on Tue, 12 June 2012 06:45
>> HI
>>
>> It looks like your package registrations are wrong, but since you
>> haven't provided your ExtendedPO2.uml it's difficult to check.
>
> Thank you, still not clear to me what is the problem ,attached there is the .uml file, hope it helps
Re: Unable to load UML model in stand alone application [message #885947 is a reply to message #885851] Wed, 13 June 2012 19:02 Go to previous message
Alfredo Motta is currently offline 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

Previous Topic:NoSuchMethodError while trying to get Resource
Next Topic:Installation Problems
Goto Forum:
  


Current Time: Thu Jul 24 21:39:35 EDT 2014

Powered by FUDForum. Page generated in 0.02555 seconds