Home » Modeling » UML2 » Stereotypes are lost when model is saved
Stereotypes are lost when model is saved [message #468517] |
Thu, 18 January 2007 10:48  |
Eclipse User |
|
|
|
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] |
Thu, 18 January 2007 20:45   |
Eclipse User |
|
|
|
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 04:09   |
Eclipse User |
|
|
|
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 09:08  |
Eclipse User |
|
|
|
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] |
Thu, 18 January 2007 20:45  |
Eclipse User |
|
|
|
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 04:09  |
Eclipse User |
|
|
|
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 09:08  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Sun Jul 27 06:39:56 EDT 2025
Powered by FUDForum. Page generated in 0.05064 seconds
|