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 |
Francisco Gortázar 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
http://www.gavab.es/eclipsegavab
http://sidelab.wordpress.com
|
|
|
Re: Stereotypes are lost when model is saved [message #468523 is a reply to message #468517] |
Fri, 19 January 2007 01:45 |
james bruck 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 |
Francisco Gortázar 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
>
>
http://www.gavab.es/eclipsegavab
http://sidelab.wordpress.com
|
|
| |
Re: Stereotypes are lost when model is saved [message #572429 is a reply to message #468517] |
Fri, 19 January 2007 01:45 |
james bruck 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 |
Francisco Gortázar 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
>
>
http://www.gavab.es/eclipsegavab
http://sidelab.wordpress.com
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 11:53:22 GMT 2024
Powered by FUDForum. Page generated in 0.03855 seconds
|