Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Registering and loading a profile programatically (standalone)
Registering and loading a profile programatically (standalone) [message #1573732] Mon, 19 January 2015 22:46 Go to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 361
Registered: March 2011
Senior Member
Hi. I'm trying to load a model with a profile in a standalone application.

I've followed the tutorial at http://wiki.eclipse.org/MDT/UML2/Introduction_to_UML2_Profiles#Loading_Models

but that still doesn't clarify how to register a third-party profile.

Some related threads suggest looking at UMLResourcesUtil to see how standard profiles are registered. Following the pattern there, I manage to register the profile (see attached file), and at first it seems to work, but as soon as I try to apply it, I get the following exception:

applying profile: org.eclipse.uml2.uml.internal.impl.ProfileImpl@3e5c7b6b (name: UMLRealTime, visibility: <unset>) (URI: http://www.eclipse.org/papyrus/umlrt)
java.lang.NullPointerException
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:737)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:223)
	at org.eclipse.uml2.uml.util.UMLUtil.getProfile(UMLUtil.java:11298)
	at org.eclipse.uml2.uml.util.UMLUtil.getNamedElement(UMLUtil.java:11494)
	at org.eclipse.uml2.uml.util.UMLUtil.getNamedElement(UMLUtil.java:11444)
	at org.eclipse.uml2.uml.util.UMLUtil.getStereotype(UMLUtil.java:11506)
	at org.eclipse.uml2.uml.util.UMLUtil.getStereotype(UMLUtil.java:11533)
	at org.eclipse.uml2.uml.internal.operations.ElementOperations.getStereotypeApplications(ElementOperations.java:213)
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.getStereotypeApplications(ElementImpl.java:186)
	at org.eclipse.uml2.uml.internal.operations.PackageOperations.applyProfile(PackageOperations.java:672)
	at org.eclipse.uml2.uml.internal.impl.PackageImpl.applyProfile(PackageImpl.java:1083)
	at eposse.experiments.profiletest.ProfileTest.applyProfiles(ProfileTest.java:75)
	at eposse.experiments.profiletest.ProfileTest.main(ProfileTest.java:34)


If I comment out the line applying the profiles, I still get the same exception when invoking "getAppliedStereotypes".

What's the problem what am I doing wrong?

Thanks.


Re: Registering and loading a profile programatically (standalone) [message #1575046 is a reply to message #1573732] Tue, 20 January 2015 15:48 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1176
Registered: July 2009
Location: Canada
Senior Member

Hi, Ernesto,

This is happening because you put only the URI of the profile
*resource* into UML2's profile location map. At line 50 of your
ProfileTest.java, you need to map the profile namespace URI to the URI
of the root Profile *object* in the profile resource.

The consequence of putting the resource URI in this map is that the
UMLUtil::getProfile(...) method passes a URI having no fragment to the
ResourceSet::getEObject(...) API, which results on an NPE on the null
fragment.

HTH,

Christian


On 2015-01-19 22:46:15 +0000, Ernesto Posse said:

> Hi. I'm trying to load a model with a profile in a standalone application.
>
> I've followed the tutorial at
> http://wiki.eclipse.org/MDT/UML2/Introduction_to_UML2_Profiles#Loading_Models
>
>
> but that still doesn't clarify how to register a third-party profile.
>
> Some related threads suggest looking at UMLResourcesUtil to see how
> standard profiles are registered. Following the pattern there, I manage
> to register the profile (see attached file), and at first it seems to
> work, but as soon as I try to apply it, I get the following exception:
>
>
> applying profile:
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@3e5c7b6b (name:
> UMLRealTime, visibility: <unset>) (URI:
> http://www.eclipse.org/papyrus/umlrt)
> java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:737)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:223)
>
> at org.eclipse.uml2.uml.util.UMLUtil.getProfile(UMLUtil.java:11298)
> at org.eclipse.uml2.uml.util.UMLUtil.getNamedElement(UMLUtil.java:11494)
> at org.eclipse.uml2.uml.util.UMLUtil.getNamedElement(UMLUtil.java:11444)
> at org.eclipse.uml2.uml.util.UMLUtil.getStereotype(UMLUtil.java:11506)
> at org.eclipse.uml2.uml.util.UMLUtil.getStereotype(UMLUtil.java:11533)
> at
> org.eclipse.uml2.uml.internal.operations.ElementOperations.getStereotypeApplications(ElementOperations.java:213)
>
> at
> org.eclipse.uml2.uml.internal.impl.ElementImpl.getStereotypeApplications(ElementImpl.java:186)
>
> at
> org.eclipse.uml2.uml.internal.operations.PackageOperations.applyProfile(PackageOperations.java:672)
>
> at
> org.eclipse.uml2.uml.internal.impl.PackageImpl.applyProfile(PackageImpl.java:1083)
>
> at
> eposse.experiments.profiletest.ProfileTest.applyProfiles(ProfileTest.java:75)
>
> at eposse.experiments.profiletest.ProfileTest.main(ProfileTest.java:34)
>
>
> If I comment out the line applying the profiles, I still get the same
> exception when invoking "getAppliedStereotypes".
>
> What's the problem what am I doing wrong?
>
> Thanks.
>
>
>
> <image><image>
Re: Registering and loading a profile programatically (standalone) [message #1575511 is a reply to message #1575046] Tue, 20 January 2015 21:36 Go to previous message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 361
Registered: March 2011
Senior Member
Thanks Christian.

Pointing to the root element of the profile works. However, I still have another problem: stereotypes do not seem to be applied even though the stereotype instances are in the XMI, and in the resource contents. Furthermore, if I explicitly try to apply all applicable stereotypes to the relevant elements, the stereotype instances seem to be created (I see them in the debugger), but when I try to "getAppliedStereotypes" on the elements, after "element.applyStereotype(stereotype)" I obtain an empty list!

See the new version attached.

Am I missing some step to get the stereotype instances attached to the appropriate elements?

Previous Topic:Registering and loading a profile programatically (standalone)
Next Topic:getAppliedStereotypes() does not work when model and profile are in the same file ?
Goto Forum:
  


Current Time: Sun Nov 18 22:22:28 GMT 2018

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

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

Back to the top