Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Stereoytpes are not applied after serialization!
Stereoytpes are not applied after serialization! [message #530318] Thu, 29 April 2010 06:44 Go to next message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Hi all,

i've a problem in applying stereotypes programmatically. At first, i
must say that stereotypes being applied via the "UML Editor" (Element ->
Apply Stereotype) works as expected. That's why i'm pretty sure that the
profile itself is implemented correctly. The profile is realized as a
static profile.

What is the problem:
I try to apply a profile and its stereotype programmatically during a
transformation (handwritten in plain java). Although i'm able to load
and apply the profile as well as the stereotypes, only the applied
profile remains after saving the model. Even the XMI doesn't contain
these additional stereotype entries. But only after serialization! If i
ask (at the end of the transformation) for the profile and the specific
stereotypes, everything is accessbile and present. After serialization,
only the applied profile remains.

Here is the snippet, how the profile is applied by me (don't care for
the prefixes and the uri's. They are correct).


ResourceSet set = new ResourceSetImpl();

final Model model = UMLFactory.eINSTANCE.createModel();
model.setName("Test");

final Profile prof =
(Profile)set.getResource(URI.createURI("platform:plugin/staticProfile/model/my.profile.uml "),
true).getContents().get(0);
model.applyProfile(prof);

org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("TestClass",
false);
final Stereotype s = clazz.getApplicableStereotype("my::Extension");
clazz.applyStereotype(s);

final Resource r = UMLResource.Factory.INSTANCE.createResource(uri);
r.getContents().add(model);
try {
r.save(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

I really didn't understand the problem... what am i doing wrong?

Thanks in advance
Timothy
Re: Stereoytpes are not applied after serialization! [message #530341 is a reply to message #530318] Thu, 29 April 2010 08:33 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 776
Registered: July 2009
Senior Member
Hi, Timothy,

You need to add the root package ('model') to the resource before you do
anything else. Whenever you apply a stereotype to an element, the UML
API tries to find a resource to which it can add the stereotype
instance. Your element needs to be attached to a resource for this to
work. Otherwise, the stereotype instance ends up floating free.

Cheers,

Christian

On 29/04/10 06:44 AM, Timothy Marc wrote:
> Hi all,
>
> i've a problem in applying stereotypes programmatically. At first, i
> must say that stereotypes being applied via the "UML Editor" (Element ->
> Apply Stereotype) works as expected. That's why i'm pretty sure that the
> profile itself is implemented correctly. The profile is realized as a
> static profile.
>
> What is the problem:
> I try to apply a profile and its stereotype programmatically during a
> transformation (handwritten in plain java). Although i'm able to load
> and apply the profile as well as the stereotypes, only the applied
> profile remains after saving the model. Even the XMI doesn't contain
> these additional stereotype entries. But only after serialization! If i
> ask (at the end of the transformation) for the profile and the specific
> stereotypes, everything is accessbile and present. After serialization,
> only the applied profile remains.
>
> Here is the snippet, how the profile is applied by me (don't care for
> the prefixes and the uri's. They are correct).
>
>
> ResourceSet set = new ResourceSetImpl();
>
> final Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("Test");
>
> final Profile prof =
> (Profile)set.getResource(URI.createURI("platform:plugin/staticProfile/model/my.profile.uml "),
> true).getContents().get(0);
> model.applyProfile(prof);
>
> org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("TestClass",
> false);
> final Stereotype s = clazz.getApplicableStereotype("my::Extension");
> clazz.applyStereotype(s);
>
> final Resource r = UMLResource.Factory.INSTANCE.createResource(uri);
> r.getContents().add(model);
> try {
> r.save(null);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> I really didn't understand the problem... what am i doing wrong?
>
> Thanks in advance
> Timothy
Re: Stereoytpes are not applied after serialization! [message #530880 is a reply to message #530341] Sun, 02 May 2010 07:11 Go to previous message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Dear Christian,

thanks, it works.

Timothy

Christian W. Damus schrieb:
> Hi, Timothy,
>
> You need to add the root package ('model') to the resource before you do
> anything else. Whenever you apply a stereotype to an element, the UML
> API tries to find a resource to which it can add the stereotype
> instance. Your element needs to be attached to a resource for this to
> work. Otherwise, the stereotype instance ends up floating free.
>
> Cheers,
>
> Christian
>
> On 29/04/10 06:44 AM, Timothy Marc wrote:
>> Hi all,
>>
>> i've a problem in applying stereotypes programmatically. At first, i
>> must say that stereotypes being applied via the "UML Editor" (Element ->
>> Apply Stereotype) works as expected. That's why i'm pretty sure that the
>> profile itself is implemented correctly. The profile is realized as a
>> static profile.
>>
>> What is the problem:
>> I try to apply a profile and its stereotype programmatically during a
>> transformation (handwritten in plain java). Although i'm able to load
>> and apply the profile as well as the stereotypes, only the applied
>> profile remains after saving the model. Even the XMI doesn't contain
>> these additional stereotype entries. But only after serialization! If i
>> ask (at the end of the transformation) for the profile and the specific
>> stereotypes, everything is accessbile and present. After serialization,
>> only the applied profile remains.
>>
>> Here is the snippet, how the profile is applied by me (don't care for
>> the prefixes and the uri's. They are correct).
>>
>>
>> ResourceSet set = new ResourceSetImpl();
>>
>> final Model model = UMLFactory.eINSTANCE.createModel();
>> model.setName("Test");
>>
>> final Profile prof =
>> (Profile)set.getResource(URI.createURI("platform:plugin/staticProfile/model/my.profile.uml "),
>>
>> true).getContents().get(0);
>> model.applyProfile(prof);
>>
>> org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("TestClass",
>> false);
>> final Stereotype s = clazz.getApplicableStereotype("my::Extension");
>> clazz.applyStereotype(s);
>>
>> final Resource r = UMLResource.Factory.INSTANCE.createResource(uri);
>> r.getContents().add(model);
>> try {
>> r.save(null);
>> } catch (IOException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>>
>> I really didn't understand the problem... what am i doing wrong?
>>
>> Thanks in advance
>> Timothy
>
Re: Stereoytpes are not applied after serialization! [message #628419 is a reply to message #530318] Thu, 29 April 2010 08:33 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 776
Registered: July 2009
Senior Member
Hi, Timothy,

You need to add the root package ('model') to the resource before you do
anything else. Whenever you apply a stereotype to an element, the UML
API tries to find a resource to which it can add the stereotype
instance. Your element needs to be attached to a resource for this to
work. Otherwise, the stereotype instance ends up floating free.

Cheers,

Christian

On 29/04/10 06:44 AM, Timothy Marc wrote:
> Hi all,
>
> i've a problem in applying stereotypes programmatically. At first, i
> must say that stereotypes being applied via the "UML Editor" (Element ->
> Apply Stereotype) works as expected. That's why i'm pretty sure that the
> profile itself is implemented correctly. The profile is realized as a
> static profile.
>
> What is the problem:
> I try to apply a profile and its stereotype programmatically during a
> transformation (handwritten in plain java). Although i'm able to load
> and apply the profile as well as the stereotypes, only the applied
> profile remains after saving the model. Even the XMI doesn't contain
> these additional stereotype entries. But only after serialization! If i
> ask (at the end of the transformation) for the profile and the specific
> stereotypes, everything is accessbile and present. After serialization,
> only the applied profile remains.
>
> Here is the snippet, how the profile is applied by me (don't care for
> the prefixes and the uri's. They are correct).
>
>
> ResourceSet set = new ResourceSetImpl();
>
> final Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("Test");
>
> final Profile prof =
> (Profile)set.getResource(URI.createURI("platform:plugin/staticProfile/model/my.profile.uml "),
> true).getContents().get(0);
> model.applyProfile(prof);
>
> org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("TestClass",
> false);
> final Stereotype s = clazz.getApplicableStereotype("my::Extension");
> clazz.applyStereotype(s);
>
> final Resource r = UMLResource.Factory.INSTANCE.createResource(uri);
> r.getContents().add(model);
> try {
> r.save(null);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> I really didn't understand the problem... what am i doing wrong?
>
> Thanks in advance
> Timothy
Re: Stereoytpes are not applied after serialization! [message #628426 is a reply to message #530341] Sun, 02 May 2010 07:11 Go to previous message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Dear Christian,

thanks, it works.

Timothy

Christian W. Damus schrieb:
> Hi, Timothy,
>
> You need to add the root package ('model') to the resource before you do
> anything else. Whenever you apply a stereotype to an element, the UML
> API tries to find a resource to which it can add the stereotype
> instance. Your element needs to be attached to a resource for this to
> work. Otherwise, the stereotype instance ends up floating free.
>
> Cheers,
>
> Christian
>
> On 29/04/10 06:44 AM, Timothy Marc wrote:
>> Hi all,
>>
>> i've a problem in applying stereotypes programmatically. At first, i
>> must say that stereotypes being applied via the "UML Editor" (Element ->
>> Apply Stereotype) works as expected. That's why i'm pretty sure that the
>> profile itself is implemented correctly. The profile is realized as a
>> static profile.
>>
>> What is the problem:
>> I try to apply a profile and its stereotype programmatically during a
>> transformation (handwritten in plain java). Although i'm able to load
>> and apply the profile as well as the stereotypes, only the applied
>> profile remains after saving the model. Even the XMI doesn't contain
>> these additional stereotype entries. But only after serialization! If i
>> ask (at the end of the transformation) for the profile and the specific
>> stereotypes, everything is accessbile and present. After serialization,
>> only the applied profile remains.
>>
>> Here is the snippet, how the profile is applied by me (don't care for
>> the prefixes and the uri's. They are correct).
>>
>>
>> ResourceSet set = new ResourceSetImpl();
>>
>> final Model model = UMLFactory.eINSTANCE.createModel();
>> model.setName("Test");
>>
>> final Profile prof =
>> (Profile)set.getResource(URI.createURI("platform:plugin/staticProfile/model/my.profile.uml "),
>>
>> true).getContents().get(0);
>> model.applyProfile(prof);
>>
>> org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("TestClass",
>> false);
>> final Stereotype s = clazz.getApplicableStereotype("my::Extension");
>> clazz.applyStereotype(s);
>>
>> final Resource r = UMLResource.Factory.INSTANCE.createResource(uri);
>> r.getContents().add(model);
>> try {
>> r.save(null);
>> } catch (IOException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>>
>> I really didn't understand the problem... what am i doing wrong?
>>
>> Thanks in advance
>> Timothy
>
Previous Topic:[Announce] New co-lead of MDT-UML2
Next Topic:Static Profiles and predefined type system
Goto Forum:
  


Current Time: Thu Aug 28 23:34:22 EDT 2014

Powered by FUDForum. Page generated in 0.02138 seconds