Home » Modeling » UML2 » Stereoytpes are not applied after serialization!
|
Re: Stereoytpes are not applied after serialization! [message #530341 is a reply to message #530318] |
Thu, 29 April 2010 12:33 |
|
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 11:11 |
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 12:33 |
|
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 11:11 |
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
>
|
|
|
Goto Forum:
Current Time: Wed Sep 25 07:28:26 GMT 2024
Powered by FUDForum. Page generated in 0.03757 seconds
|