Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Stereotypes are lost when model is saved
Stereotypes are lost when model is saved [message #468517] Thu, 18 January 2007 15:48 Go to next message
Francisco  Gortázar is currently offline Francisco GortázarFriend
Messages: 20
Registered: July 2009
Location: Spain
Junior Member
Hi,

I'm trying to save a model containing elements with some stereotypes
applied. I'm using the code from UML2 article to programmatically apply
stereotypes. When the model is saved, the stereotypes are lost. However,
when debugging the application the stereotypes seem to be correctly
applied. Any suggestions?

I'm using Eclipse 3.2, UML 2.0.2. EMF 2.2.0, and I'm applying the
stereotypes as follows:

Model theModel = UMLFactory.eINSTANCE.createModel();
theModel.setName("ASModel");

Profile profile = (Profile) load(
URI.createURI("platform:/resource/parserProfile.uml"));
UML2Article.applyProfile(theModel, profile);

Class umlClass = theModel.createOwnedClass("MyClass", false);

Stereotype typeStereotype = profile.getOwnedStereotype("type");
UML2Article.applyStereotype(umlClass, typeStereotype);

savePackage("SimpleStereotypeUsage.uml", theModel);
this.printAppliedStereotypes(umlClass, ""); // OK: prints "type"


Thank you,
Patxi


Re: Stereotypes are lost when model is saved [message #468523 is a reply to message #468517] Fri, 19 January 2007 01:45 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Francisco,
.... from a previous posting..... try making your save look something like
this ...


protected static void save(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);

out("Done.");
} catch (IOException ioe) {
err(ioe.getMessage());
}
}

- James.

"Francisco Gortazar Bellas" <francisco.gortazar@urjc.es> wrote in message
news:eoo4vv$fap$1@utils.eclipse.org...
> Hi,
>
> I'm trying to save a model containing elements with some stereotypes
> applied. I'm using the code from UML2 article to programmatically apply
> stereotypes. When the model is saved, the stereotypes are lost. However,
> when debugging the application the stereotypes seem to be correctly
> applied. Any suggestions?
>
> I'm using Eclipse 3.2, UML 2.0.2. EMF 2.2.0, and I'm applying the
> stereotypes as follows:
>
> Model theModel = UMLFactory.eINSTANCE.createModel();
> theModel.setName("ASModel");
>
> Profile profile = (Profile) load(
> URI.createURI("platform:/resource/parserProfile.uml"));
> UML2Article.applyProfile(theModel, profile);
>
> Class umlClass = theModel.createOwnedClass("MyClass", false);
>
> Stereotype typeStereotype = profile.getOwnedStereotype("type");
> UML2Article.applyStereotype(umlClass, typeStereotype);
>
> savePackage("SimpleStereotypeUsage.uml", theModel);
> this.printAppliedStereotypes(umlClass, ""); // OK: prints "type"
>
>
> Thank you,
> Patxi
Re: Stereotypes are lost when model is saved [message #468683 is a reply to message #468523] Fri, 19 January 2007 09:09 Go to previous messageGo to next message
Francisco  Gortázar is currently offline Francisco GortázarFriend
Messages: 20
Registered: July 2009
Location: Spain
Junior Member
It works!

However, were there something wrong in my code? Does I have to add my
stereotypes applications by hand to the package? I supposed that this
was done automatically whenever I applied an stereotype (in fact, the
profile application is added automatically, why not the stereotypes
application?).

Thanks a lot!

James Bruck escribió:
> Hi Francisco,
> ... from a previous posting..... try making your save look something like
> this ...
>
>
> protected static void save(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);
>
> out("Done.");
> } catch (IOException ioe) {
> err(ioe.getMessage());
> }
> }
>
> - James.
>
> "Francisco Gortazar Bellas" <francisco.gortazar@urjc.es> wrote in message
> news:eoo4vv$fap$1@utils.eclipse.org...
>> Hi,
>>
>> I'm trying to save a model containing elements with some stereotypes
>> applied. I'm using the code from UML2 article to programmatically apply
>> stereotypes. When the model is saved, the stereotypes are lost. However,
>> when debugging the application the stereotypes seem to be correctly
>> applied. Any suggestions?
>>
>> I'm using Eclipse 3.2, UML 2.0.2. EMF 2.2.0, and I'm applying the
>> stereotypes as follows:
>>
>> Model theModel = UMLFactory.eINSTANCE.createModel();
>> theModel.setName("ASModel");
>>
>> Profile profile = (Profile) load(
>> URI.createURI("platform:/resource/parserProfile.uml"));
>> UML2Article.applyProfile(theModel, profile);
>>
>> Class umlClass = theModel.createOwnedClass("MyClass", false);
>>
>> Stereotype typeStereotype = profile.getOwnedStereotype("type");
>> UML2Article.applyStereotype(umlClass, typeStereotype);
>>
>> savePackage("SimpleStereotypeUsage.uml", theModel);
>> this.printAppliedStereotypes(umlClass, ""); // OK: prints "type"
>>
>>
>> Thank you,
>> Patxi
>
>


Re: Stereotypes are lost when model is saved [message #468685 is a reply to message #468683] Fri, 19 January 2007 14:08 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Francisco,

The stereotype applications are kept at the root level of the resource.
This is a change from the previous version where such things were kept as
child nodes.
The getting started with profiles article should be updated but the
migration document mentions this.

Regards,

- James.


"Francisco Gortazar Bellas" <francisco.gortazar@urjc.es> wrote in message
news:eoq20o$e58$1@utils.eclipse.org...
> It works!
>
> However, were there something wrong in my code? Does I have to add my
> stereotypes applications by hand to the package? I supposed that this
> was done automatically whenever I applied an stereotype (in fact, the
> profile application is added automatically, why not the stereotypes
> application?).
>
> Thanks a lot!
>
> James Bruck escribi
Re: Stereotypes are lost when model is saved [message #572429 is a reply to message #468517] Fri, 19 January 2007 01:45 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Francisco,
.... from a previous posting..... try making your save look something like
this ...


protected static void save(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);

out("Done.");
} catch (IOException ioe) {
err(ioe.getMessage());
}
}

- James.

"Francisco Gortazar Bellas" <francisco.gortazar@urjc.es> wrote in message
news:eoo4vv$fap$1@utils.eclipse.org...
> Hi,
>
> I'm trying to save a model containing elements with some stereotypes
> applied. I'm using the code from UML2 article to programmatically apply
> stereotypes. When the model is saved, the stereotypes are lost. However,
> when debugging the application the stereotypes seem to be correctly
> applied. Any suggestions?
>
> I'm using Eclipse 3.2, UML 2.0.2. EMF 2.2.0, and I'm applying the
> stereotypes as follows:
>
> Model theModel = UMLFactory.eINSTANCE.createModel();
> theModel.setName("ASModel");
>
> Profile profile = (Profile) load(
> URI.createURI("platform:/resource/parserProfile.uml"));
> UML2Article.applyProfile(theModel, profile);
>
> Class umlClass = theModel.createOwnedClass("MyClass", false);
>
> Stereotype typeStereotype = profile.getOwnedStereotype("type");
> UML2Article.applyStereotype(umlClass, typeStereotype);
>
> savePackage("SimpleStereotypeUsage.uml", theModel);
> this.printAppliedStereotypes(umlClass, ""); // OK: prints "type"
>
>
> Thank you,
> Patxi
Re: Stereotypes are lost when model is saved [message #572638 is a reply to message #468523] Fri, 19 January 2007 09:09 Go to previous message
Francisco  Gortázar is currently offline Francisco GortázarFriend
Messages: 20
Registered: July 2009
Location: Spain
Junior Member
It works!

However, were there something wrong in my code? Does I have to add my
stereotypes applications by hand to the package? I supposed that this
was done automatically whenever I applied an stereotype (in fact, the
profile application is added automatically, why not the stereotypes
application?).

Thanks a lot!

James Bruck escribió:
> Hi Francisco,
> ... from a previous posting..... try making your save look something like
> this ...
>
>
> protected static void save(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);
>
> out("Done.");
> } catch (IOException ioe) {
> err(ioe.getMessage());
> }
> }
>
> - James.
>
> "Francisco Gortazar Bellas" <francisco.gortazar@urjc.es> wrote in message
> news:eoo4vv$fap$1@utils.eclipse.org...
>> Hi,
>>
>> I'm trying to save a model containing elements with some stereotypes
>> applied. I'm using the code from UML2 article to programmatically apply
>> stereotypes. When the model is saved, the stereotypes are lost. However,
>> when debugging the application the stereotypes seem to be correctly
>> applied. Any suggestions?
>>
>> I'm using Eclipse 3.2, UML 2.0.2. EMF 2.2.0, and I'm applying the
>> stereotypes as follows:
>>
>> Model theModel = UMLFactory.eINSTANCE.createModel();
>> theModel.setName("ASModel");
>>
>> Profile profile = (Profile) load(
>> URI.createURI("platform:/resource/parserProfile.uml"));
>> UML2Article.applyProfile(theModel, profile);
>>
>> Class umlClass = theModel.createOwnedClass("MyClass", false);
>>
>> Stereotype typeStereotype = profile.getOwnedStereotype("type");
>> UML2Article.applyStereotype(umlClass, typeStereotype);
>>
>> savePackage("SimpleStereotypeUsage.uml", theModel);
>> this.printAppliedStereotypes(umlClass, ""); // OK: prints "type"
>>
>>
>> Thank you,
>> Patxi
>
>


Re: Stereotypes are lost when model is saved [message #572666 is a reply to message #468683] Fri, 19 January 2007 14:08 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Francisco,

The stereotype applications are kept at the root level of the resource.
This is a change from the previous version where such things were kept as
child nodes.
The getting started with profiles article should be updated but the
migration document mentions this.

Regards,

- James.


"Francisco Gortazar Bellas" <francisco.gortazar@urjc.es> wrote in message
news:eoq20o$e58$1@utils.eclipse.org...
> It works!
>
> However, were there something wrong in my code? Does I have to add my
> stereotypes applications by hand to the package? I supposed that this
> was done automatically whenever I applied an stereotype (in fact, the
> profile application is added automatically, why not the stereotypes
> application?).
>
> Thanks a lot!
>
> James Bruck escribi
Previous Topic:[Announce] MDT UML2 2.1.0 I200701182158 is available
Next Topic:Overview Diagram of UML2
Goto Forum:
  


Current Time: Fri Apr 19 13:31:07 GMT 2024

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

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

Back to the top