Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Modifying existing profile
Modifying existing profile [message #473218] Thu, 21 June 2007 08:25 Go to next message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

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
Re: Modifying existing profile [message #473225 is a reply to message #473218] Thu, 21 June 2007 13:45 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
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
>
>
Re: Modifying existing profile [message #473279 is a reply to message #473225] Mon, 25 June 2007 11:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

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
>>
>>
>
>
Re: Modifying existing profile [message #473283 is a reply to message #473279] Mon, 25 June 2007 16:04 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
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
> >>
> >>
> >
> >
>
>
Re: Modifying existing profile [message #473305 is a reply to message #473283] Tue, 26 June 2007 11:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

James thanks for your answers.



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?



My code looks as follows:

Main-class:

import org.eclipse.emf.common.util.URI;

import org.eclipse.uml2.uml.Profile;



public class DebugClass extends UMLAssistanceClass{

private Profile profile = null;

private String name = "C:\\Documents and
Settings\\aeantti\\Desktop\\" +

"PoistaKunAddToimii\\Poisto.profile.uml";

private URI uri = URI.createURI("file:/" + name);



public DebugClass() {

open();

store();

}



private void open() {

profile = loadProfile(uri);

}



private void store() {

save2(profile, uri);

}

}



loadProfile and save2 methods from UMLAssistanceClass



protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();



protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {

org.eclipse.uml2.uml.Profile profile_ = null;



try {

Resource resource = RESOURCE_SET.getResource(uri,
true);



profile_ = (org.eclipse.uml2.uml.Profile)
EcoreUtil.getObjectByType(resource.getContents(),
UMLPackage.Literals.PACKAGE);



} catch (WrappedException we) {

err(we.getMessage());

System.exit(1);

}



return profile_;

}







protected static void save2(org.eclipse.uml2.uml.Package package_, URI uri)
{

Resource resource = RESOURCE_SET.createResource(uri);

EList contents = resource.getContents();

contents.add(package_);



for (Iterator allContents = UMLUtil.getAllContents(package_,
true,

false); allContents.hasNext();) {

EObject eObject = (EObject) allContents.next();



if (eObject instanceof Element) {

contents.addAll(((Element)eObject).getStereotypeApplications ());

}

}

try {

resource.save(null);

System.out.println("SAVE2 is used");



} catch (IOException ioe) {

err(ioe.getMessage());

}

}







Antti





"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5op21$p45$2@build.eclipse.org...



> 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
>> >>
>> >>
>> >
>> >
>>
>>
>
>
Re: Modifying existing profile [message #473307 is a reply to message #473305] Tue, 26 June 2007 13:59 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi 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?

- James.


"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5qtp0$ood$1@build.eclipse.org...
> James thanks for your answers.
>
>
>
> 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?
>
>
>
> My code looks as follows:
>
> Main-class:
>
> import org.eclipse.emf.common.util.URI;
>
> import org.eclipse.uml2.uml.Profile;
>
>
>
> public class DebugClass extends UMLAssistanceClass{
>
> private Profile profile = null;
>
> private String name = "C:\\Documents and
> Settings\\aeantti\\Desktop\\" +
>
> "PoistaKunAddToimii\\Poisto.profile.uml";
>
> private URI uri = URI.createURI("file:/" + name);
>
>
>
> public DebugClass() {
>
> open();
>
> store();
>
> }
>
>
>
> private void open() {
>
> profile = loadProfile(uri);
>
> }
>
>
>
> private void store() {
>
> save2(profile, uri);
>
> }
>
> }
>
>
>
> loadProfile and save2 methods from UMLAssistanceClass
>
>
>
> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>
>
>
> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>
> org.eclipse.uml2.uml.Profile profile_ = null;
>
>
>
> try {
>
> Resource resource = RESOURCE_SET.getResource(uri,
> true);
>
>
>
> profile_ = (org.eclipse.uml2.uml.Profile)
> EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.PACKAGE);
>
>
>
> } catch (WrappedException we) {
>
> err(we.getMessage());
>
> System.exit(1);
>
> }
>
>
>
> return profile_;
>
> }
>
>
>
>
>
>
>
> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
uri)
> {
>
> Resource resource = RESOURCE_SET.createResource(uri);
>
> EList contents = resource.getContents();
>
> contents.add(package_);
>
>
>
> for (Iterator allContents = UMLUtil.getAllContents(package_,
> true,
>
> false); allContents.hasNext();) {
>
> EObject eObject = (EObject) allContents.next();
>
>
>
> if (eObject instanceof Element) {
>
>
contents.addAll(((Element)eObject).getStereotypeApplications ());
>
> }
>
> }
>
> try {
>
> resource.save(null);
>
> System.out.println("SAVE2 is used");
>
>
>
> } catch (IOException ioe) {
>
> err(ioe.getMessage());
>
> }
>
> }
>
>
>
>
>
>
>
> Antti
>
>
>
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:f5op21$p45$2@build.eclipse.org...
>
>
>
> > 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
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
Re: Modifying existing profile [message #473312 is a reply to message #473307] Tue, 26 June 2007 16:51 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
.... If you are not removing the stereotypes explicitly, could it be that you
are adding them to some other container? That might cause EMF to remove
them from the initial container.

- James.



"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5r63k$d13$2@build.eclipse.org...
> Hi 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?
>
> - James.
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5qtp0$ood$1@build.eclipse.org...
> > James thanks for your answers.
> >
> >
> >
> > 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?
> >
> >
> >
> > My code looks as follows:
> >
> > Main-class:
> >
> > import org.eclipse.emf.common.util.URI;
> >
> > import org.eclipse.uml2.uml.Profile;
> >
> >
> >
> > public class DebugClass extends UMLAssistanceClass{
> >
> > private Profile profile = null;
> >
> > private String name = "C:\\Documents and
> > Settings\\aeantti\\Desktop\\" +
> >
> > "PoistaKunAddToimii\\Poisto.profile.uml";
> >
> > private URI uri = URI.createURI("file:/" + name);
> >
> >
> >
> > public DebugClass() {
> >
> > open();
> >
> > store();
> >
> > }
> >
> >
> >
> > private void open() {
> >
> > profile = loadProfile(uri);
> >
> > }
> >
> >
> >
> > private void store() {
> >
> > save2(profile, uri);
> >
> > }
> >
> > }
> >
> >
> >
> > loadProfile and save2 methods from UMLAssistanceClass
> >
> >
> >
> > protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
> >
> >
> >
> > protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
> >
> > org.eclipse.uml2.uml.Profile profile_ = null;
> >
> >
> >
> > try {
> >
> > Resource resource = RESOURCE_SET.getResource(uri,
> > true);
> >
> >
> >
> > profile_ = (org.eclipse.uml2.uml.Profile)
> > EcoreUtil.getObjectByType(resource.getContents(),
> > UMLPackage.Literals.PACKAGE);
> >
> >
> >
> > } catch (WrappedException we) {
> >
> > err(we.getMessage());
> >
> > System.exit(1);
> >
> > }
> >
> >
> >
> > return profile_;
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> > protected static void save2(org.eclipse.uml2.uml.Package package_, URI
> uri)
> > {
> >
> > Resource resource = RESOURCE_SET.createResource(uri);
> >
> > EList contents = resource.getContents();
> >
> > contents.add(package_);
> >
> >
> >
> > for (Iterator allContents = UMLUtil.getAllContents(package_,
> > true,
> >
> > false); allContents.hasNext();) {
> >
> > EObject eObject = (EObject) allContents.next();
> >
> >
> >
> > if (eObject instanceof Element) {
> >
> >
> contents.addAll(((Element)eObject).getStereotypeApplications ());
> >
> > }
> >
> > }
> >
> > try {
> >
> > resource.save(null);
> >
> > System.out.println("SAVE2 is used");
> >
> >
> >
> > } catch (IOException ioe) {
> >
> > err(ioe.getMessage());
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> > Antti
> >
> >
> >
> >
> >
> > "James Bruck" <jbruck@ca.ibm.com> wrote in message
> > news:f5op21$p45$2@build.eclipse.org...
> >
> >
> >
> > > 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
> > >> >>
> > >> >>
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>
Re: Modifying existing profile [message #473323 is a reply to message #473307] Wed, 27 June 2007 13:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

Hi James,

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.

Before modification model that uses profile looks somethin like this.
<Model> OwnComponentModel
<<req1>> <Component> Component A
+<Profile Application> ProfileName

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'


Antti


"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5r63k$d13$2@build.eclipse.org...
> Hi 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?
>
> - James.
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5qtp0$ood$1@build.eclipse.org...
>> James thanks for your answers.
>>
>>
>>
>> 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?
>>
>>
>>
>> My code looks as follows:
>>
>> Main-class:
>>
>> import org.eclipse.emf.common.util.URI;
>>
>> import org.eclipse.uml2.uml.Profile;
>>
>>
>>
>> public class DebugClass extends UMLAssistanceClass{
>>
>> private Profile profile = null;
>>
>> private String name = "C:\\Documents and
>> Settings\\aeantti\\Desktop\\" +
>>
>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>
>> private URI uri = URI.createURI("file:/" + name);
>>
>>
>>
>> public DebugClass() {
>>
>> open();
>>
>> store();
>>
>> }
>>
>>
>>
>> private void open() {
>>
>> profile = loadProfile(uri);
>>
>> }
>>
>>
>>
>> private void store() {
>>
>> save2(profile, uri);
>>
>> }
>>
>> }
>>
>>
>>
>> loadProfile and save2 methods from UMLAssistanceClass
>>
>>
>>
>> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>>
>>
>>
>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>
>> org.eclipse.uml2.uml.Profile profile_ = null;
>>
>>
>>
>> try {
>>
>> Resource resource = RESOURCE_SET.getResource(uri,
>> true);
>>
>>
>>
>> profile_ = (org.eclipse.uml2.uml.Profile)
>> EcoreUtil.getObjectByType(resource.getContents(),
>> UMLPackage.Literals.PACKAGE);
>>
>>
>>
>> } catch (WrappedException we) {
>>
>> err(we.getMessage());
>>
>> System.exit(1);
>>
>> }
>>
>>
>>
>> return profile_;
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
> uri)
>> {
>>
>> Resource resource = RESOURCE_SET.createResource(uri);
>>
>> EList contents = resource.getContents();
>>
>> contents.add(package_);
>>
>>
>>
>> for (Iterator allContents = UMLUtil.getAllContents(package_,
>> true,
>>
>> false); allContents.hasNext();) {
>>
>> EObject eObject = (EObject) allContents.next();
>>
>>
>>
>> if (eObject instanceof Element) {
>>
>>
> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>
>> }
>>
>> }
>>
>> try {
>>
>> resource.save(null);
>>
>> System.out.println("SAVE2 is used");
>>
>>
>>
>> } catch (IOException ioe) {
>>
>> err(ioe.getMessage());
>>
>> }
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> Antti
>>
>>
>>
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:f5op21$p45$2@build.eclipse.org...
>>
>>
>>
>> > 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
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>
Re: Modifying existing profile [message #473445 is a reply to message #473323] Thu, 28 June 2007 09:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

Hi James,

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?

Regards,
Antti

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5tn5h$env$1@build.eclipse.org...
> Hi James,
>
> 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.
>
> Before modification model that uses profile looks somethin like this.
> <Model> OwnComponentModel
> <<req1>> <Component> Component A
> +<Profile Application> ProfileName
>
> 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'
>
>
> Antti
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:f5r63k$d13$2@build.eclipse.org...
>> Hi 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?
>>
>> - James.
>>
>>
>> "Antti" <antti.evesti@vtt.fi> wrote in message
>> news:f5qtp0$ood$1@build.eclipse.org...
>>> James thanks for your answers.
>>>
>>>
>>>
>>> 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?
>>>
>>>
>>>
>>> My code looks as follows:
>>>
>>> Main-class:
>>>
>>> import org.eclipse.emf.common.util.URI;
>>>
>>> import org.eclipse.uml2.uml.Profile;
>>>
>>>
>>>
>>> public class DebugClass extends UMLAssistanceClass{
>>>
>>> private Profile profile = null;
>>>
>>> private String name = "C:\\Documents and
>>> Settings\\aeantti\\Desktop\\" +
>>>
>>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>>
>>> private URI uri = URI.createURI("file:/" + name);
>>>
>>>
>>>
>>> public DebugClass() {
>>>
>>> open();
>>>
>>> store();
>>>
>>> }
>>>
>>>
>>>
>>> private void open() {
>>>
>>> profile = loadProfile(uri);
>>>
>>> }
>>>
>>>
>>>
>>> private void store() {
>>>
>>> save2(profile, uri);
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>
>>> loadProfile and save2 methods from UMLAssistanceClass
>>>
>>>
>>>
>>> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>>>
>>>
>>>
>>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>>
>>> org.eclipse.uml2.uml.Profile profile_ = null;
>>>
>>>
>>>
>>> try {
>>>
>>> Resource resource = RESOURCE_SET.getResource(uri,
>>> true);
>>>
>>>
>>>
>>> profile_ = (org.eclipse.uml2.uml.Profile)
>>> EcoreUtil.getObjectByType(resource.getContents(),
>>> UMLPackage.Literals.PACKAGE);
>>>
>>>
>>>
>>> } catch (WrappedException we) {
>>>
>>> err(we.getMessage());
>>>
>>> System.exit(1);
>>>
>>> }
>>>
>>>
>>>
>>> return profile_;
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
>> uri)
>>> {
>>>
>>> Resource resource = RESOURCE_SET.createResource(uri);
>>>
>>> EList contents = resource.getContents();
>>>
>>> contents.add(package_);
>>>
>>>
>>>
>>> for (Iterator allContents = UMLUtil.getAllContents(package_,
>>> true,
>>>
>>> false); allContents.hasNext();) {
>>>
>>> EObject eObject = (EObject) allContents.next();
>>>
>>>
>>>
>>> if (eObject instanceof Element) {
>>>
>>>
>> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>>
>>> }
>>>
>>> }
>>>
>>> try {
>>>
>>> resource.save(null);
>>>
>>> System.out.println("SAVE2 is used");
>>>
>>>
>>>
>>> } catch (IOException ioe) {
>>>
>>> err(ioe.getMessage());
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Antti
>>>
>>>
>>>
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:f5op21$p45$2@build.eclipse.org...
>>>
>>>
>>>
>>> > 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
>>> >> >>
>>> >> >>
>>> >> >
>>> >> >
>>> >>
>>> >>
>>> >
>>> >
>>>
>>>
>>
>>
>
>
Re: Modifying existing profile [message #473766 is a reply to message #473445] Thu, 05 July 2007 14:18 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Antii,

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?

Kenn

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5vu2u$a7$1@build.eclipse.org...
> Hi James,
>
> 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?
>
> Regards,
> Antti
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5tn5h$env$1@build.eclipse.org...
>> Hi James,
>>
>> 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.
>>
>> Before modification model that uses profile looks somethin like this.
>> <Model> OwnComponentModel
>> <<req1>> <Component> Component A
>> +<Profile Application> ProfileName
>>
>> 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'
>>
>>
>> Antti
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:f5r63k$d13$2@build.eclipse.org...
>>> Hi 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?
>>>
>>> - James.
>>>
>>>
>>> "Antti" <antti.evesti@vtt.fi> wrote in message
>>> news:f5qtp0$ood$1@build.eclipse.org...
>>>> James thanks for your answers.
>>>>
>>>>
>>>>
>>>> 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?
>>>>
>>>>
>>>>
>>>> My code looks as follows:
>>>>
>>>> Main-class:
>>>>
>>>> import org.eclipse.emf.common.util.URI;
>>>>
>>>> import org.eclipse.uml2.uml.Profile;
>>>>
>>>>
>>>>
>>>> public class DebugClass extends UMLAssistanceClass{
>>>>
>>>> private Profile profile = null;
>>>>
>>>> private String name = "C:\\Documents and
>>>> Settings\\aeantti\\Desktop\\" +
>>>>
>>>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>>>
>>>> private URI uri = URI.createURI("file:/" + name);
>>>>
>>>>
>>>>
>>>> public DebugClass() {
>>>>
>>>> open();
>>>>
>>>> store();
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> private void open() {
>>>>
>>>> profile = loadProfile(uri);
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> private void store() {
>>>>
>>>> save2(profile, uri);
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> loadProfile and save2 methods from UMLAssistanceClass
>>>>
>>>>
>>>>
>>>> protected static final ResourceSet RESOURCE_SET = new
>>>> ResourceSetImpl();
>>>>
>>>>
>>>>
>>>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>>>
>>>> org.eclipse.uml2.uml.Profile profile_ = null;
>>>>
>>>>
>>>>
>>>> try {
>>>>
>>>> Resource resource = RESOURCE_SET.getResource(uri,
>>>> true);
>>>>
>>>>
>>>>
>>>> profile_ = (org.eclipse.uml2.uml.Profile)
>>>> EcoreUtil.getObjectByType(resource.getContents(),
>>>> UMLPackage.Literals.PACKAGE);
>>>>
>>>>
>>>>
>>>> } catch (WrappedException we) {
>>>>
>>>> err(we.getMessage());
>>>>
>>>> System.exit(1);
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> return profile_;
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
>>> uri)
>>>> {
>>>>
>>>> Resource resource = RESOURCE_SET.createResource(uri);
>>>>
>>>> EList contents = resource.getContents();
>>>>
>>>> contents.add(package_);
>>>>
>>>>
>>>>
>>>> for (Iterator allContents = UMLUtil.getAllContents(package_,
>>>> true,
>>>>
>>>> false); allContents.hasNext();) {
>>>>
>>>> EObject eObject = (EObject) allContents.next();
>>>>
>>>>
>>>>
>>>> if (eObject instanceof Element) {
>>>>
>>>>
>>> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> try {
>>>>
>>>> resource.save(null);
>>>>
>>>> System.out.println("SAVE2 is used");
>>>>
>>>>
>>>>
>>>> } catch (IOException ioe) {
>>>>
>>>> err(ioe.getMessage());
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Antti
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>> news:f5op21$p45$2@build.eclipse.org...
>>>>
>>>>
>>>>
>>>> > 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
>>>> >> >>
>>>> >> >>
>>>> >> >
>>>> >> >
>>>> >>
>>>> >>
>>>> >
>>>> >
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Re: Modifying existing profile [message #473940 is a reply to message #473766] Tue, 10 July 2007 12:55 Go to previous message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

Hi Kenn,

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.

Antti

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());

}

}


protected static void update(org.eclipse.uml2.uml.Package p, URI uri) {

Resource resource = RESOURCE_SET.getResource(uri, true);

resource.getContents().add(p);

try {

System.out.println("Update");

resource.save(OPTION_SAVE_ONLY_IF_CHANGED);

} catch(IOException ioe) {

}

}


"Kenn Hussey" <khussey@ca.ibm.com> wrote in message
news:f6iuj1$3sd$1@build.eclipse.org...
> Antii,
>
> 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?
>
> Kenn
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5vu2u$a7$1@build.eclipse.org...
>> Hi James,
>>
>> 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?
>>
>> Regards,
>> Antti
>>
>> "Antti" <antti.evesti@vtt.fi> wrote in message
>> news:f5tn5h$env$1@build.eclipse.org...
>>> Hi James,
>>>
>>> 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.
>>>
>>> Before modification model that uses profile looks somethin like this.
>>> <Model> OwnComponentModel
>>> <<req1>> <Component> Component A
>>> +<Profile Application> ProfileName
>>>
>>> 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'
>>>
>>>
>>> Antti
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:f5r63k$d13$2@build.eclipse.org...
>>>> Hi 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?
>>>>
>>>> - James.
>>>>
>>>>
>>>> "Antti" <antti.evesti@vtt.fi> wrote in message
>>>> news:f5qtp0$ood$1@build.eclipse.org...
>>>>> James thanks for your answers.
>>>>>
>>>>>
>>>>>
>>>>> 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?
>>>>>
>>>>>
>>>>>
>>>>> My code looks as follows:
>>>>>
>>>>> Main-class:
>>>>>
>>>>> import org.eclipse.emf.common.util.URI;
>>>>>
>>>>> import org.eclipse.uml2.uml.Profile;
>>>>>
>>>>>
>>>>>
>>>>> public class DebugClass extends UMLAssistanceClass{
>>>>>
>>>>> private Profile profile = null;
>>>>>
>>>>> private String name = "C:\\Documents and
>>>>> Settings\\aeantti\\Desktop\\" +
>>>>>
>>>>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>>>>
>>>>> private URI uri = URI.createURI("file:/" + name);
>>>>>
>>>>>
>>>>>
>>>>> public DebugClass() {
>>>>>
>>>>> open();
>>>>>
>>>>> store();
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> private void open() {
>>>>>
>>>>> profile = loadProfile(uri);
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> private void store() {
>>>>>
>>>>> save2(profile, uri);
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> loadProfile and save2 methods from UMLAssistanceClass
>>>>>
>>>>>
>>>>>
>>>>> protected static final ResourceSet RESOURCE_SET = new
>>>>> ResourceSetImpl();
>>>>>
>>>>>
>>>>>
>>>>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>>>>
>>>>> org.eclipse.uml2.uml.Profile profile_ = null;
>>>>>
>>>>>
>>>>>
>>>>> try {
>>>>>
>>>>> Resource resource =
>>>>> RESOURCE_SET.getResource(uri,
>>>>> true);
>>>>>
>>>>>
>>>>>
>>>>> profile_ = (org.eclipse.uml2.uml.Profile)
>>>>> EcoreUtil.getObjectByType(resource.getContents(),
>>>>> UMLPackage.Literals.PACKAGE);
>>>>>
>>>>>
>>>>>
>>>>> } catch (WrappedException we) {
>>>>>
>>>>> err(we.getMessage());
>>>>>
>>>>> System.exit(1);
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> return profile_;
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
>>>> uri)
>>>>> {
>>>>>
>>>>> Resource resource = RESOURCE_SET.createResource(uri);
>>>>>
>>>>> EList contents = resource.getContents();
>>>>>
>>>>> contents.add(package_);
>>>>>
>>>>>
>>>>>
>>>>> for (Iterator allContents =
>>>>> UMLUtil.getAllContents(package_,
>>>>> true,
>>>>>
>>>>> false); allContents.hasNext();) {
>>>>>
>>>>> EObject eObject = (EObject) allContents.next();
>>>>>
>>>>>
>>>>>
>>>>> if (eObject instanceof Element) {
>>>>>
>>>>>
>>>> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> try {
>>>>>
>>>>> resource.save(null);
>>>>>
>>>>> System.out.println("SAVE2 is used");
>>>>>
>>>>>
>>>>>
>>>>> } catch (IOException ioe) {
>>>>>
>>>>> err(ioe.getMessage());
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Antti
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>>> news:f5op21$p45$2@build.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>> > 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
>>>>> >> >>
>>>>> >> >>
>>>>> >> >
>>>>> >> >
>>>>> >>
>>>>> >>
>>>>> >
>>>>> >
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Re: Modifying existing profile [message #621866 is a reply to message #473218] Thu, 21 June 2007 13:45 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
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
>
>
Re: Modifying existing profile [message #622554 is a reply to message #473225] Mon, 25 June 2007 11:19 Go to previous message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

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
>>
>>
>
>
Re: Modifying existing profile [message #622558 is a reply to message #473279] Mon, 25 June 2007 16:04 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
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
> >>
> >>
> >
> >
>
>
Re: Modifying existing profile [message #622570 is a reply to message #473283] Tue, 26 June 2007 11:37 Go to previous message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

James thanks for your answers.



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?



My code looks as follows:

Main-class:

import org.eclipse.emf.common.util.URI;

import org.eclipse.uml2.uml.Profile;



public class DebugClass extends UMLAssistanceClass{

private Profile profile = null;

private String name = "C:\\Documents and
Settings\\aeantti\\Desktop\\" +

"PoistaKunAddToimii\\Poisto.profile.uml";

private URI uri = URI.createURI("file:/" + name);



public DebugClass() {

open();

store();

}



private void open() {

profile = loadProfile(uri);

}



private void store() {

save2(profile, uri);

}

}



loadProfile and save2 methods from UMLAssistanceClass



protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();



protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {

org.eclipse.uml2.uml.Profile profile_ = null;



try {

Resource resource = RESOURCE_SET.getResource(uri,
true);



profile_ = (org.eclipse.uml2.uml.Profile)
EcoreUtil.getObjectByType(resource.getContents(),
UMLPackage.Literals.PACKAGE);



} catch (WrappedException we) {

err(we.getMessage());

System.exit(1);

}



return profile_;

}







protected static void save2(org.eclipse.uml2.uml.Package package_, URI uri)
{

Resource resource = RESOURCE_SET.createResource(uri);

EList contents = resource.getContents();

contents.add(package_);



for (Iterator allContents = UMLUtil.getAllContents(package_,
true,

false); allContents.hasNext();) {

EObject eObject = (EObject) allContents.next();



if (eObject instanceof Element) {

contents.addAll(((Element)eObject).getStereotypeApplications ());

}

}

try {

resource.save(null);

System.out.println("SAVE2 is used");



} catch (IOException ioe) {

err(ioe.getMessage());

}

}







Antti





"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5op21$p45$2@build.eclipse.org...



> 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
>> >>
>> >>
>> >
>> >
>>
>>
>
>
Re: Modifying existing profile [message #622572 is a reply to message #473305] Tue, 26 June 2007 13:59 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi 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?

- James.


"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5qtp0$ood$1@build.eclipse.org...
> James thanks for your answers.
>
>
>
> 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?
>
>
>
> My code looks as follows:
>
> Main-class:
>
> import org.eclipse.emf.common.util.URI;
>
> import org.eclipse.uml2.uml.Profile;
>
>
>
> public class DebugClass extends UMLAssistanceClass{
>
> private Profile profile = null;
>
> private String name = "C:\\Documents and
> Settings\\aeantti\\Desktop\\" +
>
> "PoistaKunAddToimii\\Poisto.profile.uml";
>
> private URI uri = URI.createURI("file:/" + name);
>
>
>
> public DebugClass() {
>
> open();
>
> store();
>
> }
>
>
>
> private void open() {
>
> profile = loadProfile(uri);
>
> }
>
>
>
> private void store() {
>
> save2(profile, uri);
>
> }
>
> }
>
>
>
> loadProfile and save2 methods from UMLAssistanceClass
>
>
>
> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>
>
>
> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>
> org.eclipse.uml2.uml.Profile profile_ = null;
>
>
>
> try {
>
> Resource resource = RESOURCE_SET.getResource(uri,
> true);
>
>
>
> profile_ = (org.eclipse.uml2.uml.Profile)
> EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.PACKAGE);
>
>
>
> } catch (WrappedException we) {
>
> err(we.getMessage());
>
> System.exit(1);
>
> }
>
>
>
> return profile_;
>
> }
>
>
>
>
>
>
>
> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
uri)
> {
>
> Resource resource = RESOURCE_SET.createResource(uri);
>
> EList contents = resource.getContents();
>
> contents.add(package_);
>
>
>
> for (Iterator allContents = UMLUtil.getAllContents(package_,
> true,
>
> false); allContents.hasNext();) {
>
> EObject eObject = (EObject) allContents.next();
>
>
>
> if (eObject instanceof Element) {
>
>
contents.addAll(((Element)eObject).getStereotypeApplications ());
>
> }
>
> }
>
> try {
>
> resource.save(null);
>
> System.out.println("SAVE2 is used");
>
>
>
> } catch (IOException ioe) {
>
> err(ioe.getMessage());
>
> }
>
> }
>
>
>
>
>
>
>
> Antti
>
>
>
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:f5op21$p45$2@build.eclipse.org...
>
>
>
> > 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
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
Re: Modifying existing profile [message #622576 is a reply to message #473307] Tue, 26 June 2007 16:51 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
.... If you are not removing the stereotypes explicitly, could it be that you
are adding them to some other container? That might cause EMF to remove
them from the initial container.

- James.



"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5r63k$d13$2@build.eclipse.org...
> Hi 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?
>
> - James.
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5qtp0$ood$1@build.eclipse.org...
> > James thanks for your answers.
> >
> >
> >
> > 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?
> >
> >
> >
> > My code looks as follows:
> >
> > Main-class:
> >
> > import org.eclipse.emf.common.util.URI;
> >
> > import org.eclipse.uml2.uml.Profile;
> >
> >
> >
> > public class DebugClass extends UMLAssistanceClass{
> >
> > private Profile profile = null;
> >
> > private String name = "C:\\Documents and
> > Settings\\aeantti\\Desktop\\" +
> >
> > "PoistaKunAddToimii\\Poisto.profile.uml";
> >
> > private URI uri = URI.createURI("file:/" + name);
> >
> >
> >
> > public DebugClass() {
> >
> > open();
> >
> > store();
> >
> > }
> >
> >
> >
> > private void open() {
> >
> > profile = loadProfile(uri);
> >
> > }
> >
> >
> >
> > private void store() {
> >
> > save2(profile, uri);
> >
> > }
> >
> > }
> >
> >
> >
> > loadProfile and save2 methods from UMLAssistanceClass
> >
> >
> >
> > protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
> >
> >
> >
> > protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
> >
> > org.eclipse.uml2.uml.Profile profile_ = null;
> >
> >
> >
> > try {
> >
> > Resource resource = RESOURCE_SET.getResource(uri,
> > true);
> >
> >
> >
> > profile_ = (org.eclipse.uml2.uml.Profile)
> > EcoreUtil.getObjectByType(resource.getContents(),
> > UMLPackage.Literals.PACKAGE);
> >
> >
> >
> > } catch (WrappedException we) {
> >
> > err(we.getMessage());
> >
> > System.exit(1);
> >
> > }
> >
> >
> >
> > return profile_;
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> > protected static void save2(org.eclipse.uml2.uml.Package package_, URI
> uri)
> > {
> >
> > Resource resource = RESOURCE_SET.createResource(uri);
> >
> > EList contents = resource.getContents();
> >
> > contents.add(package_);
> >
> >
> >
> > for (Iterator allContents = UMLUtil.getAllContents(package_,
> > true,
> >
> > false); allContents.hasNext();) {
> >
> > EObject eObject = (EObject) allContents.next();
> >
> >
> >
> > if (eObject instanceof Element) {
> >
> >
> contents.addAll(((Element)eObject).getStereotypeApplications ());
> >
> > }
> >
> > }
> >
> > try {
> >
> > resource.save(null);
> >
> > System.out.println("SAVE2 is used");
> >
> >
> >
> > } catch (IOException ioe) {
> >
> > err(ioe.getMessage());
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> > Antti
> >
> >
> >
> >
> >
> > "James Bruck" <jbruck@ca.ibm.com> wrote in message
> > news:f5op21$p45$2@build.eclipse.org...
> >
> >
> >
> > > 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
> > >> >>
> > >> >>
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>
Re: Modifying existing profile [message #622584 is a reply to message #473307] Wed, 27 June 2007 13:02 Go to previous message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

Hi James,

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.

Before modification model that uses profile looks somethin like this.
<Model> OwnComponentModel
<<req1>> <Component> Component A
+<Profile Application> ProfileName

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'


Antti


"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:f5r63k$d13$2@build.eclipse.org...
> Hi 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?
>
> - James.
>
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5qtp0$ood$1@build.eclipse.org...
>> James thanks for your answers.
>>
>>
>>
>> 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?
>>
>>
>>
>> My code looks as follows:
>>
>> Main-class:
>>
>> import org.eclipse.emf.common.util.URI;
>>
>> import org.eclipse.uml2.uml.Profile;
>>
>>
>>
>> public class DebugClass extends UMLAssistanceClass{
>>
>> private Profile profile = null;
>>
>> private String name = "C:\\Documents and
>> Settings\\aeantti\\Desktop\\" +
>>
>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>
>> private URI uri = URI.createURI("file:/" + name);
>>
>>
>>
>> public DebugClass() {
>>
>> open();
>>
>> store();
>>
>> }
>>
>>
>>
>> private void open() {
>>
>> profile = loadProfile(uri);
>>
>> }
>>
>>
>>
>> private void store() {
>>
>> save2(profile, uri);
>>
>> }
>>
>> }
>>
>>
>>
>> loadProfile and save2 methods from UMLAssistanceClass
>>
>>
>>
>> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>>
>>
>>
>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>
>> org.eclipse.uml2.uml.Profile profile_ = null;
>>
>>
>>
>> try {
>>
>> Resource resource = RESOURCE_SET.getResource(uri,
>> true);
>>
>>
>>
>> profile_ = (org.eclipse.uml2.uml.Profile)
>> EcoreUtil.getObjectByType(resource.getContents(),
>> UMLPackage.Literals.PACKAGE);
>>
>>
>>
>> } catch (WrappedException we) {
>>
>> err(we.getMessage());
>>
>> System.exit(1);
>>
>> }
>>
>>
>>
>> return profile_;
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
> uri)
>> {
>>
>> Resource resource = RESOURCE_SET.createResource(uri);
>>
>> EList contents = resource.getContents();
>>
>> contents.add(package_);
>>
>>
>>
>> for (Iterator allContents = UMLUtil.getAllContents(package_,
>> true,
>>
>> false); allContents.hasNext();) {
>>
>> EObject eObject = (EObject) allContents.next();
>>
>>
>>
>> if (eObject instanceof Element) {
>>
>>
> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>
>> }
>>
>> }
>>
>> try {
>>
>> resource.save(null);
>>
>> System.out.println("SAVE2 is used");
>>
>>
>>
>> } catch (IOException ioe) {
>>
>> err(ioe.getMessage());
>>
>> }
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> Antti
>>
>>
>>
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:f5op21$p45$2@build.eclipse.org...
>>
>>
>>
>> > 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
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>
Re: Modifying existing profile [message #622658 is a reply to message #473323] Thu, 28 June 2007 09:13 Go to previous message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

Hi James,

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?

Regards,
Antti

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5tn5h$env$1@build.eclipse.org...
> Hi James,
>
> 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.
>
> Before modification model that uses profile looks somethin like this.
> <Model> OwnComponentModel
> <<req1>> <Component> Component A
> +<Profile Application> ProfileName
>
> 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'
>
>
> Antti
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:f5r63k$d13$2@build.eclipse.org...
>> Hi 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?
>>
>> - James.
>>
>>
>> "Antti" <antti.evesti@vtt.fi> wrote in message
>> news:f5qtp0$ood$1@build.eclipse.org...
>>> James thanks for your answers.
>>>
>>>
>>>
>>> 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?
>>>
>>>
>>>
>>> My code looks as follows:
>>>
>>> Main-class:
>>>
>>> import org.eclipse.emf.common.util.URI;
>>>
>>> import org.eclipse.uml2.uml.Profile;
>>>
>>>
>>>
>>> public class DebugClass extends UMLAssistanceClass{
>>>
>>> private Profile profile = null;
>>>
>>> private String name = "C:\\Documents and
>>> Settings\\aeantti\\Desktop\\" +
>>>
>>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>>
>>> private URI uri = URI.createURI("file:/" + name);
>>>
>>>
>>>
>>> public DebugClass() {
>>>
>>> open();
>>>
>>> store();
>>>
>>> }
>>>
>>>
>>>
>>> private void open() {
>>>
>>> profile = loadProfile(uri);
>>>
>>> }
>>>
>>>
>>>
>>> private void store() {
>>>
>>> save2(profile, uri);
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>
>>> loadProfile and save2 methods from UMLAssistanceClass
>>>
>>>
>>>
>>> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>>>
>>>
>>>
>>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>>
>>> org.eclipse.uml2.uml.Profile profile_ = null;
>>>
>>>
>>>
>>> try {
>>>
>>> Resource resource = RESOURCE_SET.getResource(uri,
>>> true);
>>>
>>>
>>>
>>> profile_ = (org.eclipse.uml2.uml.Profile)
>>> EcoreUtil.getObjectByType(resource.getContents(),
>>> UMLPackage.Literals.PACKAGE);
>>>
>>>
>>>
>>> } catch (WrappedException we) {
>>>
>>> err(we.getMessage());
>>>
>>> System.exit(1);
>>>
>>> }
>>>
>>>
>>>
>>> return profile_;
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
>> uri)
>>> {
>>>
>>> Resource resource = RESOURCE_SET.createResource(uri);
>>>
>>> EList contents = resource.getContents();
>>>
>>> contents.add(package_);
>>>
>>>
>>>
>>> for (Iterator allContents = UMLUtil.getAllContents(package_,
>>> true,
>>>
>>> false); allContents.hasNext();) {
>>>
>>> EObject eObject = (EObject) allContents.next();
>>>
>>>
>>>
>>> if (eObject instanceof Element) {
>>>
>>>
>> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>>
>>> }
>>>
>>> }
>>>
>>> try {
>>>
>>> resource.save(null);
>>>
>>> System.out.println("SAVE2 is used");
>>>
>>>
>>>
>>> } catch (IOException ioe) {
>>>
>>> err(ioe.getMessage());
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Antti
>>>
>>>
>>>
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:f5op21$p45$2@build.eclipse.org...
>>>
>>>
>>>
>>> > 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
>>> >> >>
>>> >> >>
>>> >> >
>>> >> >
>>> >>
>>> >>
>>> >
>>> >
>>>
>>>
>>
>>
>
>
Re: Modifying existing profile [message #622825 is a reply to message #473445] Thu, 05 July 2007 14:18 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Antii,

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?

Kenn

"Antti" <antti.evesti@vtt.fi> wrote in message
news:f5vu2u$a7$1@build.eclipse.org...
> Hi James,
>
> 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?
>
> Regards,
> Antti
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5tn5h$env$1@build.eclipse.org...
>> Hi James,
>>
>> 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.
>>
>> Before modification model that uses profile looks somethin like this.
>> <Model> OwnComponentModel
>> <<req1>> <Component> Component A
>> +<Profile Application> ProfileName
>>
>> 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'
>>
>>
>> Antti
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:f5r63k$d13$2@build.eclipse.org...
>>> Hi 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?
>>>
>>> - James.
>>>
>>>
>>> "Antti" <antti.evesti@vtt.fi> wrote in message
>>> news:f5qtp0$ood$1@build.eclipse.org...
>>>> James thanks for your answers.
>>>>
>>>>
>>>>
>>>> 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?
>>>>
>>>>
>>>>
>>>> My code looks as follows:
>>>>
>>>> Main-class:
>>>>
>>>> import org.eclipse.emf.common.util.URI;
>>>>
>>>> import org.eclipse.uml2.uml.Profile;
>>>>
>>>>
>>>>
>>>> public class DebugClass extends UMLAssistanceClass{
>>>>
>>>> private Profile profile = null;
>>>>
>>>> private String name = "C:\\Documents and
>>>> Settings\\aeantti\\Desktop\\" +
>>>>
>>>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>>>
>>>> private URI uri = URI.createURI("file:/" + name);
>>>>
>>>>
>>>>
>>>> public DebugClass() {
>>>>
>>>> open();
>>>>
>>>> store();
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> private void open() {
>>>>
>>>> profile = loadProfile(uri);
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> private void store() {
>>>>
>>>> save2(profile, uri);
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> loadProfile and save2 methods from UMLAssistanceClass
>>>>
>>>>
>>>>
>>>> protected static final ResourceSet RESOURCE_SET = new
>>>> ResourceSetImpl();
>>>>
>>>>
>>>>
>>>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>>>
>>>> org.eclipse.uml2.uml.Profile profile_ = null;
>>>>
>>>>
>>>>
>>>> try {
>>>>
>>>> Resource resource = RESOURCE_SET.getResource(uri,
>>>> true);
>>>>
>>>>
>>>>
>>>> profile_ = (org.eclipse.uml2.uml.Profile)
>>>> EcoreUtil.getObjectByType(resource.getContents(),
>>>> UMLPackage.Literals.PACKAGE);
>>>>
>>>>
>>>>
>>>> } catch (WrappedException we) {
>>>>
>>>> err(we.getMessage());
>>>>
>>>> System.exit(1);
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> return profile_;
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
>>> uri)
>>>> {
>>>>
>>>> Resource resource = RESOURCE_SET.createResource(uri);
>>>>
>>>> EList contents = resource.getContents();
>>>>
>>>> contents.add(package_);
>>>>
>>>>
>>>>
>>>> for (Iterator allContents = UMLUtil.getAllContents(package_,
>>>> true,
>>>>
>>>> false); allContents.hasNext();) {
>>>>
>>>> EObject eObject = (EObject) allContents.next();
>>>>
>>>>
>>>>
>>>> if (eObject instanceof Element) {
>>>>
>>>>
>>> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> try {
>>>>
>>>> resource.save(null);
>>>>
>>>> System.out.println("SAVE2 is used");
>>>>
>>>>
>>>>
>>>> } catch (IOException ioe) {
>>>>
>>>> err(ioe.getMessage());
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Antti
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>> news:f5op21$p45$2@build.eclipse.org...
>>>>
>>>>
>>>>
>>>> > 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
>>>> >> >>
>>>> >> >>
>>>> >> >
>>>> >> >
>>>> >>
>>>> >>
>>>> >
>>>> >
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Re: Modifying existing profile [message #623316 is a reply to message #473766] Tue, 10 July 2007 12:55 Go to previous message
Eclipse UserFriend
Originally posted by: antti.evesti.vtt.fi

Hi Kenn,

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.

Antti

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());

}

}


protected static void update(org.eclipse.uml2.uml.Package p, URI uri) {

Resource resource = RESOURCE_SET.getResource(uri, true);

resource.getContents().add(p);

try {

System.out.println("Update");

resource.save(OPTION_SAVE_ONLY_IF_CHANGED);

} catch(IOException ioe) {

}

}


"Kenn Hussey" <khussey@ca.ibm.com> wrote in message
news:f6iuj1$3sd$1@build.eclipse.org...
> Antii,
>
> 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?
>
> Kenn
>
> "Antti" <antti.evesti@vtt.fi> wrote in message
> news:f5vu2u$a7$1@build.eclipse.org...
>> Hi James,
>>
>> 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?
>>
>> Regards,
>> Antti
>>
>> "Antti" <antti.evesti@vtt.fi> wrote in message
>> news:f5tn5h$env$1@build.eclipse.org...
>>> Hi James,
>>>
>>> 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.
>>>
>>> Before modification model that uses profile looks somethin like this.
>>> <Model> OwnComponentModel
>>> <<req1>> <Component> Component A
>>> +<Profile Application> ProfileName
>>>
>>> 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'
>>>
>>>
>>> Antti
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:f5r63k$d13$2@build.eclipse.org...
>>>> Hi 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?
>>>>
>>>> - James.
>>>>
>>>>
>>>> "Antti" <antti.evesti@vtt.fi> wrote in message
>>>> news:f5qtp0$ood$1@build.eclipse.org...
>>>>> James thanks for your answers.
>>>>>
>>>>>
>>>>>
>>>>> 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?
>>>>>
>>>>>
>>>>>
>>>>> My code looks as follows:
>>>>>
>>>>> Main-class:
>>>>>
>>>>> import org.eclipse.emf.common.util.URI;
>>>>>
>>>>> import org.eclipse.uml2.uml.Profile;
>>>>>
>>>>>
>>>>>
>>>>> public class DebugClass extends UMLAssistanceClass{
>>>>>
>>>>> private Profile profile = null;
>>>>>
>>>>> private String name = "C:\\Documents and
>>>>> Settings\\aeantti\\Desktop\\" +
>>>>>
>>>>> "PoistaKunAddToimii\\Poisto.profile.uml";
>>>>>
>>>>> private URI uri = URI.createURI("file:/" + name);
>>>>>
>>>>>
>>>>>
>>>>> public DebugClass() {
>>>>>
>>>>> open();
>>>>>
>>>>> store();
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> private void open() {
>>>>>
>>>>> profile = loadProfile(uri);
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> private void store() {
>>>>>
>>>>> save2(profile, uri);
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> loadProfile and save2 methods from UMLAssistanceClass
>>>>>
>>>>>
>>>>>
>>>>> protected static final ResourceSet RESOURCE_SET = new
>>>>> ResourceSetImpl();
>>>>>
>>>>>
>>>>>
>>>>> protected static org.eclipse.uml2.uml.Profile loadProfile(URI uri) {
>>>>>
>>>>> org.eclipse.uml2.uml.Profile profile_ = null;
>>>>>
>>>>>
>>>>>
>>>>> try {
>>>>>
>>>>> Resource resource =
>>>>> RESOURCE_SET.getResource(uri,
>>>>> true);
>>>>>
>>>>>
>>>>>
>>>>> profile_ = (org.eclipse.uml2.uml.Profile)
>>>>> EcoreUtil.getObjectByType(resource.getContents(),
>>>>> UMLPackage.Literals.PACKAGE);
>>>>>
>>>>>
>>>>>
>>>>> } catch (WrappedException we) {
>>>>>
>>>>> err(we.getMessage());
>>>>>
>>>>> System.exit(1);
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> return profile_;
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> protected static void save2(org.eclipse.uml2.uml.Package package_, URI
>>>> uri)
>>>>> {
>>>>>
>>>>> Resource resource = RESOURCE_SET.createResource(uri);
>>>>>
>>>>> EList contents = resource.getContents();
>>>>>
>>>>> contents.add(package_);
>>>>>
>>>>>
>>>>>
>>>>> for (Iterator allContents =
>>>>> UMLUtil.getAllContents(package_,
>>>>> true,
>>>>>
>>>>> false); allContents.hasNext();) {
>>>>>
>>>>> EObject eObject = (EObject) allContents.next();
>>>>>
>>>>>
>>>>>
>>>>> if (eObject instanceof Element) {
>>>>>
>>>>>
>>>> contents.addAll(((Element)eObject).getStereotypeApplications ());
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> try {
>>>>>
>>>>> resource.save(null);
>>>>>
>>>>> System.out.println("SAVE2 is used");
>>>>>
>>>>>
>>>>>
>>>>> } catch (IOException ioe) {
>>>>>
>>>>> err(ioe.getMessage());
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Antti
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>>> news:f5op21$p45$2@build.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>> > 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
>>>>> >> >>
>>>>> >> >>
>>>>> >> >
>>>>> >> >
>>>>> >>
>>>>> >>
>>>>> >
>>>>> >
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Previous Topic:Validation Problem
Next Topic:Load and parse UML file
Goto Forum:
  


Current Time: Mon Nov 20 21:24:47 GMT 2017

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

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