Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » IntroductionToUMLProfiles Question
IntroductionToUMLProfiles Question [message #1384627] Thu, 29 May 2014 17:29 Go to next message
Bill McLaren is currently offline Bill McLarenFriend
Messages: 4
Registered: May 2014
Junior Member
In the IntroductionToUMLProfiles example, we create a profile and apply a stereotype to some EAttributes and ERelationships. In Luna RC1 I'm having a challenge enhancing the example when attempting to save the modified epo2Model after all of the new stereotype attributes are set and then read.

If I follow the tutorial using the graphical UML tree editor, it saves the modifications just fine, but it also modifies the model UML file by moving the UML XML element into an outer xmi:XMI element. The build from code method doesn't do this.

I tried adding XMI2UMLResource.Factory.INSTANCE to the initial RESOURCE_SET registration and was able to get the file to save in the right XMI format, but the save method doesn't persist the stereotype attributes that were set in the code. I'm happy to post what I've written but it's really straightforward and feel that I'm probably missing something that may be version related to help steer the model into a newer format.

Any guidance would be appreciated. I've been reading the tests, google, etc... but haven't found the answer.

-Bill
Re: IntroductionToUMLProfiles Question [message #1384675 is a reply to message #1384627] Fri, 30 May 2014 09:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

"I'm happy to post what I've written but it's really straightforward"

It's amazing how many ways there are to do something stupid; not saying
that what you have done is so. But even if your code is stupid, knowing
what stupid things are attempted is also instructive for the developers.

So posting what you have as a zipped project will almost certainly be
useful and save guessing at how to replicate your problem.

Regards

Ed Willink



On 30/05/2014 00:52, Bill McLaren wrote:
> In the IntroductionToUMLProfiles example, we create a profile and
> apply a stereotype to some EAttributes and ERelationships. In Luna
> RC1 I'm having a challenge enhancing the example when attempting to
> save the modified epo2Model after all of the new stereotype attributes
> are set and then read.
>
> If I follow the tutorial using the graphical UML tree editor, it saves
> the modifications just fine, but it also modifies the model UML file
> by moving the UML XML element into an outer xmi:XMI element. The
> build from code method doesn't do this.
>
> I tried adding XMI2UMLResource.Factory.INSTANCE to the initial
> RESOURCE_SET registration and was able to get the file to save in the
> right XMI format, but the save method doesn't persist the stereotype
> attributes that were set in the code. I'm happy to post what I've
> written but it's really straightforward and feel that I'm probably
> missing something that may be version related to help steer the model
> into a newer format.
>
> Any guidance would be appreciated. I've been reading the tests,
> google, etc... but haven't found the answer.
>
> -Bill
>
Re: IntroductionToUMLProfiles Question [message #1384694 is a reply to message #1384627] Fri, 30 May 2014 13:25 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Bill,

See seome replies in-line, below.

HTH,

Christian

On 2014-05-29 23:52:47 +0000, Bill McLaren said:

> In the IntroductionToUMLProfiles example, we create a profile and apply
> a stereotype to some EAttributes and ERelationships. In Luna RC1 I'm
> having a challenge enhancing the example when attempting to save the
> modified epo2Model after all of the new stereotype attributes are set
> and then read.
>
> If I follow the tutorial using the graphical UML tree editor, it saves
> the modifications just fine, but it also modifies the model UML file by
> moving the UML XML element into an outer xmi:XMI element. The build
> from code method doesn't do this.

The <xmi:XMI> element is a container for serialization purposes only,
to contain multiple elements that logically are roots of the resource.
The XML document format is a single-rooted tree structure, so this
basically ensures that you have a valid XML document. On loading a
resource, EMF elides the <xmi:XMI> element and presents its children as
the roots of the resource.

So, this suggests to me that you are getting the correct serialization
by walking through the example in the UML Editor but not when running
your code.

> I tried adding XMI2UMLResource.Factory.INSTANCE to the initial
> RESOURCE_SET registration and was able to get the file to save in the
> right XMI format, but the save method doesn't persist the stereotype
> attributes that were set in the code. I'm happy to post what I've
> written but it's really straightforward and feel that I'm probably
> missing something that may be version related to help steer the model
> into a newer format.

The XMI2UMLResource has nothing to do with, I expect.


> Any guidance would be appreciated. I've been reading the tests,
> google, etc... but haven't found the answer.

Indeed, details like this are hidden in dark corners where even the
might Google has difficulty seeing. :-)

I suspect the problem is in the way you save the resource. If I add
the following to the end of the main() method of the
IntroductionToUMLProfiles example, I get the updated model correctly
saved with the stereotype applications in an <xmi:XMI> container:


Resource res = epo2Model.eResource();
URI newURI = res.getURI().trimSegments(1).appendSegment("updated.uml");

// This saves the model and the stereotype applications that were added
// to its resource
res.setURI(newURI);
res.save(null);

// This would only save the model because it adds the passed-in package
// to a new resource, omitting all of the stereotype applications
//save(epo2Model, newURI);

I suspect you are doing something like the commented-out second
approach to saving. but, by all means, share your code so that
everybody reading the newsgroup may learn from it!


>
> -Bill
Re: IntroductionToUMLProfiles Question [message #1384701 is a reply to message #1384694] Fri, 30 May 2014 14:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Christian

It seems that while the example save() method is fine for the purposes
of the example, it is misleading for more general use.

Perhaps we want to upgrade save() on both examples and add a step
similar to Bill's in the real tutorial.

Regards

Ed

On 30/05/2014 14:25, Christian W. Damus wrote:
> Hi, Bill,
>
> See seome replies in-line, below.
>
> HTH,
>
> Christian
>
> On 2014-05-29 23:52:47 +0000, Bill McLaren said:
>
>> In the IntroductionToUMLProfiles example, we create a profile and
>> apply a stereotype to some EAttributes and ERelationships. In Luna
>> RC1 I'm having a challenge enhancing the example when attempting to
>> save the modified epo2Model after all of the new stereotype
>> attributes are set and then read.
>>
>> If I follow the tutorial using the graphical UML tree editor, it
>> saves the modifications just fine, but it also modifies the model UML
>> file by moving the UML XML element into an outer xmi:XMI element.
>> The build from code method doesn't do this.
>
> The <xmi:XMI> element is a container for serialization purposes only,
> to contain multiple elements that logically are roots of the
> resource. The XML document format is a single-rooted tree structure,
> so this basically ensures that you have a valid XML document. On
> loading a resource, EMF elides the <xmi:XMI> element and presents its
> children as the roots of the resource.
>
> So, this suggests to me that you are getting the correct serialization
> by walking through the example in the UML Editor but not when running
> your code.
>
>> I tried adding XMI2UMLResource.Factory.INSTANCE to the initial
>> RESOURCE_SET registration and was able to get the file to save in the
>> right XMI format, but the save method doesn't persist the stereotype
>> attributes that were set in the code. I'm happy to post what I've
>> written but it's really straightforward and feel that I'm probably
>> missing something that may be version related to help steer the model
>> into a newer format.
>
> The XMI2UMLResource has nothing to do with, I expect.
>
>
>> Any guidance would be appreciated. I've been reading the tests,
>> google, etc... but haven't found the answer.
>
> Indeed, details like this are hidden in dark corners where even the
> might Google has difficulty seeing. :-)
>
> I suspect the problem is in the way you save the resource. If I add
> the following to the end of the main() method of the
> IntroductionToUMLProfiles example, I get the updated model correctly
> saved with the stereotype applications in an <xmi:XMI> container:
>
>
> Resource res = epo2Model.eResource();
> URI newURI =
> res.getURI().trimSegments(1).appendSegment("updated.uml");
>
> // This saves the model and the stereotype applications that were
> added
> // to its resource
> res.setURI(newURI);
> res.save(null);
>
> // This would only save the model because it adds the passed-in
> package
> // to a new resource, omitting all of the stereotype applications
> //save(epo2Model, newURI);
>
> I suspect you are doing something like the commented-out second
> approach to saving. but, by all means, share your code so that
> everybody reading the newsgroup may learn from it!
>
>
>>
>> -Bill
>
>
Re: IntroductionToUMLProfiles Question [message #1384727 is a reply to message #1384701] Fri, 30 May 2014 20:17 Go to previous messageGo to next message
Bill McLaren is currently offline Bill McLarenFriend
Messages: 4
Registered: May 2014
Junior Member
Hi Ed/Christian. Thanks for the quick responses. Christian, the save(epo2Model, newURI) is exactly what I was doing. Creating a new resource as shown in your example worked like a charm so I now have a model with the profile and stereotypes applied. The fun part for today will be to see if I can update the exiting model without creating a new one. Sorry for not posting the code yesterday. I've created a project with the new save additions.

github.com/billmclaren/UML2/tree/master/examples

I did spend all day yesterday going through previous posts, help files, tests, Google, etc.. Building the model from scratch using code is appealing since it reduces the opportunity for human error and is something that can be constantly reproduced during the build process. Figuring out how to keep the generated ID's or enhancing the example to test for the existence of something will be trickier. Hopefully I'm up to the task and maybe naive enough to think I can do it. Razz

As far as the ultimate example, what I'm really trying to do is create DSL's like this.

1. Define a framework like TOGAF, BPMN, TM Forum Frameworx, etc... using UML2 java code.
2. Add UML Profiles as necessary.
3. Automate exporting the UML model to Ecore (keeping the UML documentation/comment so that it shows up in JavaDocs)
4. Execute genmodel to create the model source and associated edit/editor/tests.
5. Use Sirius to create the editors.
6. Use Acceleo to create additional documentation, etc...
7. Lather, rinse, repeat.

Thanks again for taking the time to point me in the right direction. Any additional hints for how to get the generated UML model exported to Ecore and then through the genmodel phase is absolutely welcomed.

-Bill
Re: IntroductionToUMLProfiles Question [message #1384982 is a reply to message #1384701] Tue, 03 June 2014 13:02 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Ed,

Indeed, that seems like a good idea. Please raise an enhancement request.

cW


On 2014-05-30 14:27:18 +0000, Ed Willink said:

> Hi Christian
>
> It seems that while the example save() method is fine for the purposes
> of the example, it is misleading for more general use.
>
> Perhaps we want to upgrade save() on both examples and add a step
> similar to Bill's in the real tutorial.
>
> Regards
>
> Ed
>
> On 30/05/2014 14:25, Christian W. Damus wrote:
>> Hi, Bill,
>>
>> See seome replies in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>> On 2014-05-29 23:52:47 +0000, Bill McLaren said:
>>
>>> In the IntroductionToUMLProfiles example, we create a profile and apply
>>> a stereotype to some EAttributes and ERelationships. In Luna RC1 I'm
>>> having a challenge enhancing the example when attempting to save the
>>> modified epo2Model after all of the new stereotype attributes are set
>>> and then read.
>>>
>>> If I follow the tutorial using the graphical UML tree editor, it saves
>>> the modifications just fine, but it also modifies the model UML file by
>>> moving the UML XML element into an outer xmi:XMI element. The build
>>> from code method doesn't do this.
>>
>> The <xmi:XMI> element is a container for serialization purposes only,
>> to contain multiple elements that logically are roots of the resource.
>> The XML document format is a single-rooted tree structure, so this
>> basically ensures that you have a valid XML document. On loading a
>> resource, EMF elides the <xmi:XMI> element and presents its children as
>> the roots of the resource.
>>
>> So, this suggests to me that you are getting the correct serialization
>> by walking through the example in the UML Editor but not when running
>> your code.
>>
>>> I tried adding XMI2UMLResource.Factory.INSTANCE to the initial
>>> RESOURCE_SET registration and was able to get the file to save in the
>>> right XMI format, but the save method doesn't persist the stereotype
>>> attributes that were set in the code. I'm happy to post what I've
>>> written but it's really straightforward and feel that I'm probably
>>> missing something that may be version related to help steer the model
>>> into a newer format.
>>
>> The XMI2UMLResource has nothing to do with, I expect.
>>
>>
>>> Any guidance would be appreciated. I've been reading the tests,
>>> google, etc... but haven't found the answer.
>>
>> Indeed, details like this are hidden in dark corners where even the
>> might Google has difficulty seeing. :-)
>>
>> I suspect the problem is in the way you save the resource. If I add
>> the following to the end of the main() method of the
>> IntroductionToUMLProfiles example, I get the updated model correctly
>> saved with the stereotype applications in an <xmi:XMI> container:
>>
>>
>> Resource res = epo2Model.eResource();
>> URI newURI = res.getURI().trimSegments(1).appendSegment("updated.uml");
>>
>> // This saves the model and the stereotype applications that were added
>> // to its resource
>> res.setURI(newURI);
>> res.save(null);
>>
>> // This would only save the model because it adds the passed-in package
>> // to a new resource, omitting all of the stereotype applications
>> //save(epo2Model, newURI);
>>
>> I suspect you are doing something like the commented-out second
>> approach to saving. but, by all means, share your code so that
>> everybody reading the newsgroup may learn from it!
>>
>>
>>>
>>> -Bill
Re: IntroductionToUMLProfiles Question [message #1384983 is a reply to message #1384982] Tue, 03 June 2014 13:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=436456

On 03/06/2014 14:02, Christian W. Damus wrote:
> Hi, Ed,
>
> Indeed, that seems like a good idea. Please raise an enhancement
> request.
>
> cW
Re: IntroductionToUMLProfiles Question [message #1384984 is a reply to message #1384727] Tue, 03 June 2014 13:13 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Bill,

See some replies in-line, below.

HTH,

Christian


On 2014-05-30 20:17:49 +0000, Bill McLaren said:

> Hi Ed/Christian. Thanks for the quick responses. Christian, the
> save(epo2Model, newURI) is exactly what I was doing. Creating a new
> resource as shown in your example worked like a charm so I now have a
> model with the profile and stereotypes applied. The fun part for today
> will be to see if I can update the exiting model without creating a new
> one. Sorry for not posting the code yesterday. I've created a project
> with the new save additions.
>
> github.com/billmclaren/UML2/tree/master/examples

Sorry, maybe I'll have a chance to take a look at this code, but not
very soon. Am a bit swamped.


> I did spend all day yesterday going through previous posts, help files,
> tests, Google, etc.. Building the model from scratch using code is
> appealing since it reduces the opportunity for human error and is
> something that can be constantly reproduced during the build process.
> Figuring out how to keep the generated ID's or enhancing the example to
> test for the existence of something will be trickier. Hopefully I'm up
> to the task and maybe naive enough to think I can do it. :p

You might look at how the "Convert to Metamodel" action in the UML
Editor (which action is available when you install the UML2 Examples
feature) generates predictable and stable XMI IDs for every element
based on names. Some similar strategy may be best for generating your
IDs (certainly letting the resource create UUIDs will not be helpful).


> As far as the ultimate example, what I'm really trying to do is create
> DSL's like this.
>
> 1. Define a framework like TOGAF, BPMN, TM Forum Frameworx, etc...
> using UML2 java code.
> 2. Add UML Profiles as necessary.
> 3. Automate exporting the UML model to Ecore (keeping the UML
> documentation/comment so that it shows up in JavaDocs)
> 4. Execute genmodel to create the model source and associated
> edit/editor/tests.
> 5. Use Sirius to create the editors.
> 6. Use Acceleo to create additional documentation, etc...
> 7. Lather, rinse, repeat.
>
> Thanks again for taking the time to point me in the right direction.
> Any additional hints for how to get the generated UML model exported to
> Ecore and then through the genmodel phase is absolutely welcomed.

The UML2 project provides an Ant task in the
org.eclipse.uml2.uml.ecore.importer plug-in for importing UML models
and profiles into EMF generator models. From there, the Ant tasks
provided by EMF can generate the code. I can't tell you what Sirius
may have for process automation, but Acceleo has fairly complete Ant
and Maven support. That's not something to discuss in this forum,
though.


>
> -Bill
Re: IntroductionToUMLProfiles Question [message #1384991 is a reply to message #1384984] Tue, 03 June 2014 13:48 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Some complexities you might want to worry about...

There is currently discussion in the OMG TIWG to support stable semantic
IDs for future specifications.

A key requirement is that a package refactoring need not change IDs.

In order to make this work with current tooling, the suggestion is to
apply an identity stereotype to each metamodel element. This can be
persisted and migrate with refactoring.

To save space there can be a default ID generation algorithm, so that
default IDs need not be persisted.

Another desirable requirement is that if you use model transformations
then rerunning the transformation independently to recreate the output
should produce the same IDs. Transformation output IDs should therefore
be derived as a repeatable function of the input IDs.

Regards

Ed Willink


On 03/06/2014 14:13, Christian W. Damus wrote:
> Hi, Bill,
>
> See some replies in-line, below.
>
> HTH,
>
> Christian
>
>
> On 2014-05-30 20:17:49 +0000, Bill McLaren said:
>
>> Hi Ed/Christian. Thanks for the quick responses. Christian, the
>> save(epo2Model, newURI) is exactly what I was doing. Creating a new
>> resource as shown in your example worked like a charm so I now have a
>> model with the profile and stereotypes applied. The fun part for
>> today will be to see if I can update the exiting model without
>> creating a new one. Sorry for not posting the code yesterday. I've
>> created a project with the new save additions.
>>
>> github.com/billmclaren/UML2/tree/master/examples
>
> Sorry, maybe I'll have a chance to take a look at this code, but not
> very soon. Am a bit swamped.
>
>
>> I did spend all day yesterday going through previous posts, help
>> files, tests, Google, etc.. Building the model from scratch using
>> code is appealing since it reduces the opportunity for human error
>> and is something that can be constantly reproduced during the build
>> process. Figuring out how to keep the generated ID's or enhancing
>> the example to test for the existence of something will be trickier.
>> Hopefully I'm up to the task and maybe naive enough to think I can do
>> it. :p
>
> You might look at how the "Convert to Metamodel" action in the UML
> Editor (which action is available when you install the UML2 Examples
> feature) generates predictable and stable XMI IDs for every element
> based on names. Some similar strategy may be best for generating your
> IDs (certainly letting the resource create UUIDs will not be helpful).
>
>
>> As far as the ultimate example, what I'm really trying to do is
>> create DSL's like this.
>>
>> 1. Define a framework like TOGAF, BPMN, TM Forum Frameworx, etc...
>> using UML2 java code.
>> 2. Add UML Profiles as necessary.
>> 3. Automate exporting the UML model to Ecore (keeping the UML
>> documentation/comment so that it shows up in JavaDocs)
>> 4. Execute genmodel to create the model source and associated
>> edit/editor/tests.
>> 5. Use Sirius to create the editors.
>> 6. Use Acceleo to create additional documentation, etc...
>> 7. Lather, rinse, repeat.
>>
>> Thanks again for taking the time to point me in the right
>> direction. Any additional hints for how to get the generated UML
>> model exported to Ecore and then through the genmodel phase is
>> absolutely welcomed.
>
> The UML2 project provides an Ant task in the
> org.eclipse.uml2.uml.ecore.importer plug-in for importing UML models
> and profiles into EMF generator models. From there, the Ant tasks
> provided by EMF can generate the code. I can't tell you what Sirius
> may have for process automation, but Acceleo has fairly complete Ant
> and Maven support. That's not something to discuss in this forum,
> though.
>
>
>>
>> -Bill
>
>
Previous Topic:EMF - not possible to create a profile model
Next Topic:Notification problem with class package
Goto Forum:
  


Current Time: Thu Apr 25 17:00:14 GMT 2024

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

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

Back to the top