I have a problem with modifying UML profile in the programmatic way. I am
trying to add new stereotypes to the existing profile. The problem occurs
when I have added stereotypes from the original profile to the UML diagram,
then I modify the profile in the programmatic way. When I open the UML
diagram after profile modification, the earlier connected stereotypes are
absconded. So, I suppose that I define and save the modified profile in
wrong way because I can successfully perform this scenario by using Eclipses
UML editor, i.e. the tree structured view. I define and save profile using
the same methods that are published in the 'Introduction to UML2 profiles'
article.

If you can successfully use the editor to complete your task, you should be
able to do so programatically. The actions from the editor simply call the
API to accomplish its task.
Keep in mind that you need to call define() after modification to your
profile. That will create the proper Ecore representation. You might want
to double check the ecore representation after you call define ( it is kept
under an annotation at the root of the profile ). Also remember to reapply
your profile, stereotypes should then be automatically migrated.
If that still doesn't work, look at the actions and see what functions they
call. Try to duplicate those function calls in your code.

Failing that, please indicate what version of UML you are using, and
possibly send your profile and model so that we can see what is going on.

Regards,

- James.

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5dcl6$e4n$1@build.eclipse.org...
> I have a problem with modifying UML profile in the programmatic way. I am
> trying to add new stereotypes to the existing profile. The problem occurs
> when I have added stereotypes from the original profile to the UML
diagram,
> then I modify the profile in the programmatic way. When I open the UML
> diagram after profile modification, the earlier connected stereotypes are
> absconded. So, I suppose that I define and save the modified profile in
> wrong way because I can successfully perform this scenario by using
Eclipses
> UML editor, i.e. the tree structured view. I define and save profile using
> the same methods that are published in the 'Introduction to UML2 profiles'
> article.
>
>
>
> I hope that someone can help me with this issue.
>
>
>
> Antti
>
>

Thanks, that was a good hint. However, how can I check which methods were
called when I perform a task by using UML editor?

I tested my code snippet further and I believe that I save the profile in a
wrong way. Because when I just open a profile and then save it, I come up
against the same problem. I suppose that the used save method is proper, but
how about a method call?

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5dvdr$mn4$2@build.eclipse.org...
> Hi Antti,
>
> If you can successfully use the editor to complete your task, you should
> be
> able to do so programatically. The actions from the editor simply call
> the
> API to accomplish its task.
> Keep in mind that you need to call define() after modification to your
> profile. That will create the proper Ecore representation. You might
> want
> to double check the ecore representation after you call define ( it is
> kept
> under an annotation at the root of the profile ). Also remember to
> reapply
> your profile, stereotypes should then be automatically migrated.
> If that still doesn't work, look at the actions and see what functions
> they
> call. Try to duplicate those function calls in your code.
>
> Failing that, please indicate what version of UML you are using, and
> possibly send your profile and model so that we can see what is going on.
>
> Regards,
>
> - James.
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5dcl6$e4n$1@build.eclipse.org...
>> I have a problem with modifying UML profile in the programmatic way. I am
>> trying to add new stereotypes to the existing profile. The problem occurs
>> when I have added stereotypes from the original profile to the UML
> diagram,
>> then I modify the profile in the programmatic way. When I open the UML
>> diagram after profile modification, the earlier connected stereotypes are
>> absconded. So, I suppose that I define and save the modified profile in
>> wrong way because I can successfully perform this scenario by using
> Eclipses
>> UML editor, i.e. the tree structured view. I define and save profile
>> using
>> the same methods that are published in the 'Introduction to UML2
>> profiles'
>> article.
>>
>>
>>
>> I hope that someone can help me with this issue.
>>
>>
>>
>> Antti
>>
>>
>
>

You can download all the code for those actions from cvs. Have a look at
org.eclipse.uml2.uml.editor.actions.
Also have a look at the thread entitled "how to save a model with applied
stereotypes and tag values" for ideas on saving applied steroetypes.
Also, you should look at the ecore representation after the define. If that
is intact, the profile should be good.

Cheers,
- James.

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5o8cd$q7q$1@build.eclipse.org...
> Thanks, that was a good hint. However, how can I check which methods were
> called when I perform a task by using UML editor?
>
>
>
> I tested my code snippet further and I believe that I save the profile in
a
> wrong way. Because when I just open a profile and then save it, I come up
> against the same problem. I suppose that the used save method is proper,
but
> how about a method call?
>
>
>
> Antti
>
>
>
> String name = profile.getName();
>
> URI Uri = URI.createURI("file:/" + profileFolder).appendSegment(name)
>
> .appendFileExtension(UMLResource.PROFILE_FILE_EXTENSION);
>
>
>
> save(profile, Uri);
>
>
>
> protected static void save(org.eclipse.uml2.uml.Package package_, URI uri)
{
>
> Resource resource = RESOURCE_SET.createResource(uri);
>
> resource.getContents().add(package_);
>
>
>
> try {
>
> resource.save(null);
>
> } catch (IOException ioe) {
>
> err(ioe.getMessage());
>
> }
>
> }
>
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:f5dvdr$mn4$2@build.eclipse.org...
> > Hi Antti,
> >
> > If you can successfully use the editor to complete your task, you should
> > be
> > able to do so programatically. The actions from the editor simply call
> > the
> > API to accomplish its task.
> > Keep in mind that you need to call define() after modification to your
> > profile. That will create the proper Ecore representation. You might
> > want
> > to double check the ecore representation after you call define ( it is
> > kept
> > under an annotation at the root of the profile ). Also remember to
> > reapply
> > your profile, stereotypes should then be automatically migrated.
> > If that still doesn't work, look at the actions and see what functions
> > they
> > call. Try to duplicate those function calls in your code.
> >
> > Failing that, please indicate what version of UML you are using, and
> > possibly send your profile and model so that we can see what is going
on.
> >
> > Regards,
> >
> > - James.
> >
> >
> > "Antti" <antti.evesti@vtt.fi> wrote in message
> > news:f5dcl6$e4n$1@build.eclipse.org...
> >> I have a problem with modifying UML profile in the programmatic way. I
am
> >> trying to add new stereotypes to the existing profile. The problem
occurs
> >> when I have added stereotypes from the original profile to the UML
> > diagram,
> >> then I modify the profile in the programmatic way. When I open the UML
> >> diagram after profile modification, the earlier connected stereotypes
are
> >> absconded. So, I suppose that I define and save the modified profile in
> >> wrong way because I can successfully perform this scenario by using
> > Eclipses
> >> UML editor, i.e. the tree structured view. I define and save profile
> >> using
> >> the same methods that are published in the 'Introduction to UML2
> >> profiles'
> >> article.
> >>
> >>
> >>
> >> I hope that someone can help me with this issue.
> >>
> >>
> >>
> >> Antti
> >>
> >>
> >
> >
>
>

But I am still unable to save the profile in a suitable way. I checked my
save method and now it looks exactly same as in the "how to save a model
with applied stereotypes and tag values" thread. Therefore, I made a sample
code snippet, as simple as possible. This sample code comes up against same
problem. At first the code opens profile and immediately after that saves it
by using same URI. When I look my UML model that contains stereotypes from
"modified" profile these stereotypes are drown after code execution.

I compared contents of the profile files by using XML editor and I mentioned
that "xmi-id" tags was changed during program execution is this normal?

> Hi Antti,
>
> You can download all the code for those actions from cvs. Have a look at
> org.eclipse.uml2.uml.editor.actions.
> Also have a look at the thread entitled "how to save a model with applied
> stereotypes and tag values" for ideas on saving applied steroetypes.
> Also, you should look at the ecore representation after the define. If
> that
> is intact, the profile should be good.
>
> Cheers,
> - James.
>
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5o8cd$q7q$1@build.eclipse.org...
>> Thanks, that was a good hint. However, how can I check which methods were
>> called when I perform a task by using UML editor?
>>
>>
>>
>> I tested my code snippet further and I believe that I save the profile in
> a
>> wrong way. Because when I just open a profile and then save it, I come up
>> against the same problem. I suppose that the used save method is proper,
> but
>> how about a method call?
>>
>>
>>
>> Antti
>>
>>
>>
>> String name = profile.getName();
>>
>> URI Uri = URI.createURI("file:/" + profileFolder).appendSegment(name)
>>
>> .appendFileExtension(UMLResource.PROFILE_FILE_EXTENSION);
>>
>>
>>
>> save(profile, Uri);
>>
>>
>>
>> protected static void save(org.eclipse.uml2.uml.Package package_, URI
>> uri)
> {
>>
>> Resource resource = RESOURCE_SET.createResource(uri);
>>
>> resource.getContents().add(package_);
>>
>>
>>
>> try {
>>
>> resource.save(null);
>>
>> } catch (IOException ioe) {
>>
>> err(ioe.getMessage());
>>
>> }
>>
>> }
>>
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:f5dvdr$mn4$2@build.eclipse.org...
>> > Hi Antti,
>> >
>> > If you can successfully use the editor to complete your task, you
>> > should
>> > be
>> > able to do so programatically. The actions from the editor simply
>> > call
>> > the
>> > API to accomplish its task.
>> > Keep in mind that you need to call define() after modification to your
>> > profile. That will create the proper Ecore representation. You might
>> > want
>> > to double check the ecore representation after you call define ( it is
>> > kept
>> > under an annotation at the root of the profile ). Also remember to
>> > reapply
>> > your profile, stereotypes should then be automatically migrated.
>> > If that still doesn't work, look at the actions and see what functions
>> > they
>> > call. Try to duplicate those function calls in your code.
>> >
>> > Failing that, please indicate what version of UML you are using, and
>> > possibly send your profile and model so that we can see what is going
> on.
>> >
>> > Regards,
>> >
>> > - James.
>> >
>> >
>> > "Antti" <antti.evesti@vtt.fi> wrote in message
>> > news:f5dcl6$e4n$1@build.eclipse.org...
>> >> I have a problem with modifying UML profile in the programmatic way. I
> am
>> >> trying to add new stereotypes to the existing profile. The problem
> occurs
>> >> when I have added stereotypes from the original profile to the UML
>> > diagram,
>> >> then I modify the profile in the programmatic way. When I open the UML
>> >> diagram after profile modification, the earlier connected stereotypes
> are
>> >> absconded. So, I suppose that I define and save the modified profile
>> >> in
>> >> wrong way because I can successfully perform this scenario by using
>> > Eclipses
>> >> UML editor, i.e. the tree structured view. I define and save profile
>> >> using
>> >> the same methods that are published in the 'Introduction to UML2
>> >> profiles'
>> >> article.
>> >>
>> >>
>> >>
>> >> I hope that someone can help me with this issue.
>> >>
>> >>
>> >>
>> >> Antti
>> >>
>> >>
>> >
>> >
>>
>>
>
>

That save I mentioned in the "how to save a model with applied steroeotypes
...." was to save stereotype applications while saving the model to which
stereotypes were applied. That code is not required to simply save a
profile.

There should be nothing special to do when saving the modified profile.
You should be able to open the profile as you would any other model, add
stereotypes to it, then save the resource back out.

Are you able to programatically load a basic model with one package, add a
class then close and save? If you can do that you should be able to do the
same for the stereotype and profile.
There might be something else in your code causing the removal of the
steroetypes. Are you getting errors or exceptions?

I tried to modify simple UML model with one package and everything goes
fine. I used methods introduced in the 'Getting started with UML2' article.
First I executed registerResourceFactories() and registerPathmaps(uri)
methods, then I loaded the model and added the class to the package found
from the model. I got package by using the getNestedPackage and add class by
using the createOwnedClass method. After all I saved the model by using the
same method that I have used all the time.

So, all of these goes fine, but when I use profile something odd hapens. Of
course I am able to add stereotype to the profile and then view the modified
profile by using Eclipse's editor, but models that tries to use that
modified profile are broken after modification.

and after modification stereotype from the component A is lost and model
looks like this. I emphasize that this happens only when I modify the
profile in a programmatic way.
<Model>OwnComponentModel
<Component> Component A
+<Profile Application>
Req1
base_component='Nonsense String'

I just mentioned that when I add a class to the model in a programmatic way
the result file is different than if I add class by using the editor. So
(hopefully) I made mistake also when I add a class :-) When I use the editor
to adding a class earlier defined classes keep original xmi-ids but when I
made this in the programmatic way all xmi-ids are changed.

Therefore, my question is how this class addition should be done? Again I
suppose that createOwnedClass is the right method, but can I save the model
by usign the same method which was applicable when creating a new model
file?

It looks like the method you are using to save your model creates a new
resource before saving. If you are loading an existing model, then you don't
need (and probably don't want) to create a new resource - that's probably
why the identifiers are being changed each time you save your model.

When you say that the stereotype applications are lost, do you mean that
they are not accessible in memory after loading your model or that they are
missing in the serialization once you save your model? Are you sure that the
references to the profile are being successfully resolved when loading your
model? What result to you get when you call getAppliedStereotypes() on the
component in your model?

I think that creating resource was the problem. Below is the save method
that I used earlier and the new update method that works fine. So earlier I
get resource as follows:
Resource resource = RESOURCE_SET.createResource(uri)
But now, I get it as follows:
Resource resource = RESOURCE_SET.getResource(uri, true)

I suppose this is a legal way to implement this task. Thank you very much
for your hints.

If you can successfully use the editor to complete your task, you should be
able to do so programatically. The actions from the editor simply call the
API to accomplish its task.
Keep in mind that you need to call define() after modification to your
profile. That will create the proper Ecore representation. You might want
to double check the ecore representation after you call define ( it is kept
under an annotation at the root of the profile ). Also remember to reapply
your profile, stereotypes should then be automatically migrated.
If that still doesn't work, look at the actions and see what functions they
call. Try to duplicate those function calls in your code.

Failing that, please indicate what version of UML you are using, and
possibly send your profile and model so that we can see what is going on.

Regards,

- James.

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5dcl6$e4n$1@build.eclipse.org...
> I have a problem with modifying UML profile in the programmatic way. I am
> trying to add new stereotypes to the existing profile. The problem occurs
> when I have added stereotypes from the original profile to the UML
diagram,
> then I modify the profile in the programmatic way. When I open the UML
> diagram after profile modification, the earlier connected stereotypes are
> absconded. So, I suppose that I define and save the modified profile in
> wrong way because I can successfully perform this scenario by using
Eclipses
> UML editor, i.e. the tree structured view. I define and save profile using
> the same methods that are published in the 'Introduction to UML2 profiles'
> article.
>
>
>
> I hope that someone can help me with this issue.
>
>
>
> Antti
>
>

Thanks, that was a good hint. However, how can I check which methods were
called when I perform a task by using UML editor?

I tested my code snippet further and I believe that I save the profile in a
wrong way. Because when I just open a profile and then save it, I come up
against the same problem. I suppose that the used save method is proper, but
how about a method call?

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5dvdr$mn4$2@build.eclipse.org...
> Hi Antti,
>
> If you can successfully use the editor to complete your task, you should
> be
> able to do so programatically. The actions from the editor simply call
> the
> API to accomplish its task.
> Keep in mind that you need to call define() after modification to your
> profile. That will create the proper Ecore representation. You might
> want
> to double check the ecore representation after you call define ( it is
> kept
> under an annotation at the root of the profile ). Also remember to
> reapply
> your profile, stereotypes should then be automatically migrated.
> If that still doesn't work, look at the actions and see what functions
> they
> call. Try to duplicate those function calls in your code.
>
> Failing that, please indicate what version of UML you are using, and
> possibly send your profile and model so that we can see what is going on.
>
> Regards,
>
> - James.
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5dcl6$e4n$1@build.eclipse.org...
>> I have a problem with modifying UML profile in the programmatic way. I am
>> trying to add new stereotypes to the existing profile. The problem occurs
>> when I have added stereotypes from the original profile to the UML
> diagram,
>> then I modify the profile in the programmatic way. When I open the UML
>> diagram after profile modification, the earlier connected stereotypes are
>> absconded. So, I suppose that I define and save the modified profile in
>> wrong way because I can successfully perform this scenario by using
> Eclipses
>> UML editor, i.e. the tree structured view. I define and save profile
>> using
>> the same methods that are published in the 'Introduction to UML2
>> profiles'
>> article.
>>
>>
>>
>> I hope that someone can help me with this issue.
>>
>>
>>
>> Antti
>>
>>
>
>

You can download all the code for those actions from cvs. Have a look at
org.eclipse.uml2.uml.editor.actions.
Also have a look at the thread entitled "how to save a model with applied
stereotypes and tag values" for ideas on saving applied steroetypes.
Also, you should look at the ecore representation after the define. If that
is intact, the profile should be good.

Cheers,
- James.

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5o8cd$q7q$1@build.eclipse.org...
> Thanks, that was a good hint. However, how can I check which methods were
> called when I perform a task by using UML editor?
>
>
>
> I tested my code snippet further and I believe that I save the profile in
a
> wrong way. Because when I just open a profile and then save it, I come up
> against the same problem. I suppose that the used save method is proper,
but
> how about a method call?
>
>
>
> Antti
>
>
>
> String name = profile.getName();
>
> URI Uri = URI.createURI("file:/" + profileFolder).appendSegment(name)
>
> .appendFileExtension(UMLResource.PROFILE_FILE_EXTENSION);
>
>
>
> save(profile, Uri);
>
>
>
> protected static void save(org.eclipse.uml2.uml.Package package_, URI uri)
{
>
> Resource resource = RESOURCE_SET.createResource(uri);
>
> resource.getContents().add(package_);
>
>
>
> try {
>
> resource.save(null);
>
> } catch (IOException ioe) {
>
> err(ioe.getMessage());
>
> }
>
> }
>
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:f5dvdr$mn4$2@build.eclipse.org...
> > Hi Antti,
> >
> > If you can successfully use the editor to complete your task, you should
> > be
> > able to do so programatically. The actions from the editor simply call
> > the
> > API to accomplish its task.
> > Keep in mind that you need to call define() after modification to your
> > profile. That will create the proper Ecore representation. You might
> > want
> > to double check the ecore representation after you call define ( it is
> > kept
> > under an annotation at the root of the profile ). Also remember to
> > reapply
> > your profile, stereotypes should then be automatically migrated.
> > If that still doesn't work, look at the actions and see what functions
> > they
> > call. Try to duplicate those function calls in your code.
> >
> > Failing that, please indicate what version of UML you are using, and
> > possibly send your profile and model so that we can see what is going
on.
> >
> > Regards,
> >
> > - James.
> >
> >
> > "Antti" <antti.evesti@vtt.fi> wrote in message
> > news:f5dcl6$e4n$1@build.eclipse.org...
> >> I have a problem with modifying UML profile in the programmatic way. I
am
> >> trying to add new stereotypes to the existing profile. The problem
occurs
> >> when I have added stereotypes from the original profile to the UML
> > diagram,
> >> then I modify the profile in the programmatic way. When I open the UML
> >> diagram after profile modification, the earlier connected stereotypes
are
> >> absconded. So, I suppose that I define and save the modified profile in
> >> wrong way because I can successfully perform this scenario by using
> > Eclipses
> >> UML editor, i.e. the tree structured view. I define and save profile
> >> using
> >> the same methods that are published in the 'Introduction to UML2
> >> profiles'
> >> article.
> >>
> >>
> >>
> >> I hope that someone can help me with this issue.
> >>
> >>
> >>
> >> Antti
> >>
> >>
> >
> >
>
>

But I am still unable to save the profile in a suitable way. I checked my
save method and now it looks exactly same as in the "how to save a model
with applied stereotypes and tag values" thread. Therefore, I made a sample
code snippet, as simple as possible. This sample code comes up against same
problem. At first the code opens profile and immediately after that saves it
by using same URI. When I look my UML model that contains stereotypes from
"modified" profile these stereotypes are drown after code execution.

I compared contents of the profile files by using XML editor and I mentioned
that "xmi-id" tags was changed during program execution is this normal?

> Hi Antti,
>
> You can download all the code for those actions from cvs. Have a look at
> org.eclipse.uml2.uml.editor.actions.
> Also have a look at the thread entitled "how to save a model with applied
> stereotypes and tag values" for ideas on saving applied steroetypes.
> Also, you should look at the ecore representation after the define. If
> that
> is intact, the profile should be good.
>
> Cheers,
> - James.
>
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5o8cd$q7q$1@build.eclipse.org...
>> Thanks, that was a good hint. However, how can I check which methods were
>> called when I perform a task by using UML editor?
>>
>>
>>
>> I tested my code snippet further and I believe that I save the profile in
> a
>> wrong way. Because when I just open a profile and then save it, I come up
>> against the same problem. I suppose that the used save method is proper,
> but
>> how about a method call?
>>
>>
>>
>> Antti
>>
>>
>>
>> String name = profile.getName();
>>
>> URI Uri = URI.createURI("file:/" + profileFolder).appendSegment(name)
>>
>> .appendFileExtension(UMLResource.PROFILE_FILE_EXTENSION);
>>
>>
>>
>> save(profile, Uri);
>>
>>
>>
>> protected static void save(org.eclipse.uml2.uml.Package package_, URI
>> uri)
> {
>>
>> Resource resource = RESOURCE_SET.createResource(uri);
>>
>> resource.getContents().add(package_);
>>
>>
>>
>> try {
>>
>> resource.save(null);
>>
>> } catch (IOException ioe) {
>>
>> err(ioe.getMessage());
>>
>> }
>>
>> }
>>
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:f5dvdr$mn4$2@build.eclipse.org...
>> > Hi Antti,
>> >
>> > If you can successfully use the editor to complete your task, you
>> > should
>> > be
>> > able to do so programatically. The actions from the editor simply
>> > call
>> > the
>> > API to accomplish its task.
>> > Keep in mind that you need to call define() after modification to your
>> > profile. That will create the proper Ecore representation. You might
>> > want
>> > to double check the ecore representation after you call define ( it is
>> > kept
>> > under an annotation at the root of the profile ). Also remember to
>> > reapply
>> > your profile, stereotypes should then be automatically migrated.
>> > If that still doesn't work, look at the actions and see what functions
>> > they
>> > call. Try to duplicate those function calls in your code.
>> >
>> > Failing that, please indicate what version of UML you are using, and
>> > possibly send your profile and model so that we can see what is going
> on.
>> >
>> > Regards,
>> >
>> > - James.
>> >
>> >
>> > "Antti" <antti.evesti@vtt.fi> wrote in message
>> > news:f5dcl6$e4n$1@build.eclipse.org...
>> >> I have a problem with modifying UML profile in the programmatic way. I
> am
>> >> trying to add new stereotypes to the existing profile. The problem
> occurs
>> >> when I have added stereotypes from the original profile to the UML
>> > diagram,
>> >> then I modify the profile in the programmatic way. When I open the UML
>> >> diagram after profile modification, the earlier connected stereotypes
> are
>> >> absconded. So, I suppose that I define and save the modified profile
>> >> in
>> >> wrong way because I can successfully perform this scenario by using
>> > Eclipses
>> >> UML editor, i.e. the tree structured view. I define and save profile
>> >> using
>> >> the same methods that are published in the 'Introduction to UML2
>> >> profiles'
>> >> article.
>> >>
>> >>
>> >>
>> >> I hope that someone can help me with this issue.
>> >>
>> >>
>> >>
>> >> Antti
>> >>
>> >>
>> >
>> >
>>
>>
>
>

That save I mentioned in the "how to save a model with applied steroeotypes
...." was to save stereotype applications while saving the model to which
stereotypes were applied. That code is not required to simply save a
profile.

There should be nothing special to do when saving the modified profile.
You should be able to open the profile as you would any other model, add
stereotypes to it, then save the resource back out.

Are you able to programatically load a basic model with one package, add a
class then close and save? If you can do that you should be able to do the
same for the stereotype and profile.
There might be something else in your code causing the removal of the
steroetypes. Are you getting errors or exceptions?

I tried to modify simple UML model with one package and everything goes
fine. I used methods introduced in the 'Getting started with UML2' article.
First I executed registerResourceFactories() and registerPathmaps(uri)
methods, then I loaded the model and added the class to the package found
from the model. I got package by using the getNestedPackage and add class by
using the createOwnedClass method. After all I saved the model by using the
same method that I have used all the time.

So, all of these goes fine, but when I use profile something odd hapens. Of
course I am able to add stereotype to the profile and then view the modified
profile by using Eclipse's editor, but models that tries to use that
modified profile are broken after modification.

and after modification stereotype from the component A is lost and model
looks like this. I emphasize that this happens only when I modify the
profile in a programmatic way.
<Model>OwnComponentModel
<Component> Component A
+<Profile Application>
Req1
base_component='Nonsense String'

I just mentioned that when I add a class to the model in a programmatic way
the result file is different than if I add class by using the editor. So
(hopefully) I made mistake also when I add a class :-) When I use the editor
to adding a class earlier defined classes keep original xmi-ids but when I
made this in the programmatic way all xmi-ids are changed.

Therefore, my question is how this class addition should be done? Again I
suppose that createOwnedClass is the right method, but can I save the model
by usign the same method which was applicable when creating a new model
file?

It looks like the method you are using to save your model creates a new
resource before saving. If you are loading an existing model, then you don't
need (and probably don't want) to create a new resource - that's probably
why the identifiers are being changed each time you save your model.

When you say that the stereotype applications are lost, do you mean that
they are not accessible in memory after loading your model or that they are
missing in the serialization once you save your model? Are you sure that the
references to the profile are being successfully resolved when loading your
model? What result to you get when you call getAppliedStereotypes() on the
component in your model?

I think that creating resource was the problem. Below is the save method
that I used earlier and the new update method that works fine. So earlier I
get resource as follows:
Resource resource = RESOURCE_SET.createResource(uri)
But now, I get it as follows:
Resource resource = RESOURCE_SET.getResource(uri, true)

I suppose this is a legal way to implement this task. Thank you very much
for your hints.