Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Cannot retrieve applied stereotypes of a UML element
Cannot retrieve applied stereotypes of a UML element [message #899199] Tue, 31 July 2012 03:12 Go to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Hello everybody,

I have a sample model with one class with a MARTE stereotype applied to it.
This is also confirmed by the XMI (attached).

When I load the model I can see that the MARTE profile has been correctly loaded.
However I still can't retrieve the stereotype.
This is my code

Model m=ModelDecorator.getModel(model_file);
LOGGER.info("Printing applied profiles");
LOGGER.info(m.getAppliedProfiles());
		
for(Element e: m.allOwnedElements()){
  LOGGER.info("Element " + e + " has these stereotypes");
  LOGGER.info(e.getAppliedStereotypes());
}


and the corresponding output showing that marte is applied to the model, but that I can't retrieve the stereotype for my class (even if in the XMI everything seems ok)

Printing applied profiles
[org.eclipse.uml2.uml.internal.impl.ProfileImpl@7f11bfbc (eProxyURI: pathmap://Papyrus_PROFILES/MARTE.profile.uml#_WStkoAPMEdyuUt-4qHuVvQ)]
Element org.eclipse.uml2.uml.internal.impl.ClassImpl@40e99ce5 (name: RadarClock, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false) has these stereotypes
[]
Element org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl@6db22920 (isStrict: false) has these stereotypes
[]


Any suggestion? Crying or Very Sad
  • Attachment: model.uml
    (Size: 1.10KB, Downloaded 80 times)

[Updated on: Tue, 31 July 2012 03:20]

Report message to a moderator

Re: Cannot retrieve applied stereotypes of a UML element [message #899221 is a reply to message #899199] Tue, 31 July 2012 07:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4155
Registered: July 2009
Senior Member
Hi

"eProxyURI:"

Ensure that you have registered your models so that proxies are resoled.

Regards

Ed Willink

On 31/07/2012 04:12, Alfredo Motta wrote:
> Hello everybody,
>
> I have a sample model with one class with a MARTE stereotype applied to it.
> This is also confirmed by the XMI (attached).
>
> When I load the model I can see that the MARTE profile has been correctly loaded.
> However I still can't retrieve the stereotype.
> This is my code and my output
>
> LOGGER.info("Printing applied profiles");
> LOGGER.info(m.getAppliedProfiles());
>
> for(Element e: m.allOwnedElements()){
> LOGGER.info("Element " + e + " has these stereotypes");
> LOGGER.info(e.getAppliedStereotypes());
> }
>
> and the corresponding output showing that marte is applied to the model, but that I can't retrieve the stereotype for my class
>
> Printing applied profiles
> [org.eclipse.uml2.uml.internal.impl.ProfileImpl@7f11bfbc (eProxyURI: pathmap://Papyrus_PROFILES/MARTE.profile.uml#_WStkoAPMEdyuUt-4qHuVvQ)]
> Element org.eclipse.uml2.uml.internal.impl.ClassImpl@40e99ce5 (name: RadarClock, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false) has these stereotypes
> []
> Element org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl@6db22920 (isStrict: false) has these stereotypes
> []
>
> Any suggestion? :cry:
>
Re: Cannot retrieve applied stereotypes of a UML element [message #899411 is a reply to message #899221] Tue, 31 July 2012 17:52 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Thank you for your reply.
Still, I can't figure out what is the problem.
From your suggestion I just understood that references between objects are not loaded up automatically.

Could you give me some documentation that I can read?
Thank you

Ed Willink wrote on Tue, 31 July 2012 03:01
Hi

"eProxyURI:"

Ensure that you have registered your models so that proxies are resoled.

Regards

Ed Willink


[Updated on: Tue, 31 July 2012 17:53]

Report message to a moderator

Re: Cannot retrieve applied stereotypes of a UML element [message #899438 is a reply to message #899199] Tue, 31 July 2012 19:42 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
If this could help, this is how I loaded up the model

		
URI uri = 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.getPackageRegistry().put(org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.TimePackage.eNS_URI, org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.TimePackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.PROFILE_FILE_EXTENSION, UMLResource.Factory.INSTANCE);

set.createResource(uri);		
Resource r = set.getResource(uri, true);
		
Model m=(Model)EcoreUtil.getObjectByType(r.getContents(), UMLPackage.eINSTANCE.getModel());
return m;
Re: Cannot retrieve applied stereotypes of a UML element [message #899472 is a reply to message #899411] Wed, 01 August 2012 05:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4155
Registered: July 2009
Senior Member
Hi

I learnt these things by spending many 'happy' hours stepping
ResourceSet.getResource and EcoreUtil.resolve.

This enables you to find out why
pathmap://Papyrus_PROFILES/MARTE.profile.uml#_WStkoAPMEdyuUt-4qHuVvQ
fails to resolve, which will be because you haven't provided any URI
mapping from pathmap://Papyrus_PROFILES/ to an accessible location.

Maybe some Papyrus user knows how this should be done.

For the equivalent UML profiles, the standard Eclipse startup of UML
does the initialization automatically.

Regards

Ed Willink

On 31/07/2012 18:52, Alfredo Motta wrote:
> Thank you for your reply.
> Still, I can't figure out what is the problem.
> From your suggestion I just understood that references between objects
> are not loaded up automatically.
> Could you give me some documentation that I can read?
> Thank you
>
> Ed Willink wrote on Tue, 31 July 2012 03:01
>> Hi
>>
>> "eProxyURI:"
>>
>> Ensure that you have registered your models so that proxies are resoled.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 31/07/2012 04:12, Alfredo Motta wrote:
>> > Hello everybody,
>> >
>> > I have a sample model with one class with a MARTE stereotype
>> applied to it.
>> > This is also confirmed by the XMI (attached).
>> >
>> > When I load the model I can see that the MARTE profile has been
>> correctly loaded.
>> > However I still can't retrieve the stereotype.
>> > This is my code and my output
>> >
>> > LOGGER.info("Printing applied profiles");
>> > LOGGER.info(m.getAppliedProfiles());
>> >
>> > for(Element e: m.allOwnedElements()){
>> > LOGGER.info("Element " + e + " has these stereotypes");
>> > LOGGER.info(e.getAppliedStereotypes());
>> > }
>> >
>> > and the corresponding output showing that marte is applied to the
>> model, but that I can't retrieve the stereotype for my class
>> >
>> > Printing applied profiles
>> > [org.eclipse.uml2.uml.internal.impl.ProfileImpl@7f11bfbc
>> (eProxyURI:
>> pathmap://Papyrus_PROFILES/MARTE.profile.uml#_WStkoAPMEdyuUt-4qHuVvQ)]
>> > Element org.eclipse.uml2.uml.internal.impl.ClassImpl@40e99ce5
>> (name: RadarClock, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false) has these
>> stereotypes
>> > []
>> > Element
>> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl@6db22920
>> (isStrict: false) has these stereotypes
>> > []
>> >
>> > Any suggestion? :cry:
>> >
>
>
Re: Cannot retrieve applied stereotypes of a UML element [message #899495 is a reply to message #899438] Wed, 01 August 2012 07:41 Go to previous messageGo to next message
Peter  is currently offline Peter Friend
Messages: 85
Registered: July 2009
Member
Hi Alfredo,
I suppose you load your model from standalone java. When you do so you
have to define all your pathmaps by yourself.

URIConverter.URI_MAP.put(URI.createURI("pathmap://Papyrus_PROFILES/",
uri to profile location);
Greetings
Peter

Am 31.07.2012 21:42, schrieb Alfredo Motta:
> If this could help, this is how I loaded up the model
>
>
> URI uri = 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.getPackageRegistry().put(org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.TimePackage.eNS_URI,
> org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.TimePackage.eINSTANCE);
> set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.PROFILE_FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> set.createResource(uri);
> Resource r = set.getResource(uri, true);
>
> Model m=(Model)EcoreUtil.getObjectByType(r.getContents(),
> UMLPackage.eINSTANCE.getModel());
> return m;
>
Re: Cannot retrieve applied stereotypes of a UML element [message #899658 is a reply to message #899199] Wed, 01 August 2012 17:19 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Thank you Peter, this was really helpful.

This is what I did:
I registered the mapping between the MARTE pathmap and a concrete URI where he could retrieve the file.

set.getURIConverter().getURIMap().put(URI.createURI("pathmap://Papyrus_PROFILES/MARTE.profile.uml"), URI.createFileURI(new File("input/MARTE.profile.uml").getAbsolutePath()));	


This solves the eProxy problem, but I found out this error
Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to org.eclipse.uml2.uml.Profile
	at org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.getAppliedProfile(ProfileApplicationImpl.java:187)


To solve this problem I manually changed in the file of the MARTE profile this
xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"

to this
xmlns:uml="http://www.eclipse.org/uml2/4.0.0/UML"

wondering if there is a better way to do that.

But still my list of stereotypes is empty.

Printing the content of the model resouce
org.eclipse.uml2.uml.internal.impl.ModelImpl@7215fb38 (name: model, visibility: <unset>) (URI: null) (viewpoint: <unset>)
org.eclipse.papyrus.MARTE.MARTE_Foundations.Time.impl.ClockTypeImpl@664310d0 (nature: discrete, isLogical: false)

Printing applied profiles
[org.eclipse.uml2.uml.internal.impl.ProfileImpl@395d601f (name: Time, visibility: <unset>) (URI: null)]

Printing model element stereotypes
Element org.eclipse.uml2.uml.internal.impl.ClassImpl@154e45b3 (name: RadarClock, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false) has the following stereotypes
[] --> this should have the ClockType Stereotype according to the model
Element org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl@75d252d (isStrict: false) has the following stereotypes
[]


Attached the code to snippet to load the model and print the stereotypes. Also the toy model again and the MARTE profile and library
To me it is quite unbelievable how difficult it is to get this toy example working, am I approaching the problem in the wrong way?

[Updated on: Wed, 01 August 2012 17:22]

Report message to a moderator

Re: Cannot retrieve applied stereotypes of a UML element [message #900098 is a reply to message #899658] Fri, 03 August 2012 23:51 Go to previous message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Any thought on that?
Did anyone has a working example where the you load a model with stereotypes in a stand alone application and you actually print them?

Thank you

[Updated on: Fri, 03 August 2012 23:51]

Report message to a moderator

Previous Topic:Retrieve endpoints of Association
Next Topic:UML Model Transformator
Goto Forum:
  


Current Time: Sat Nov 29 07:42:58 GMT 2014

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

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