Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Unique element ID before saving
Unique element ID before saving [message #891654] Mon, 25 June 2012 12:15 Go to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Hi,

within my application I have to find elements by means of a unique ID. However, the resource is not saved yet. Otherwise, I found out that I could use:

element.eResource().getURIFragment(element);

But what if the element is not part of the resource yet as it is not saved? How can I get a unique identifier?

Using package1.package2.elementName is not unique as within the same package several elements with the same name can exist.

Regards,

Tex
Re: Unique element ID before saving [message #891671 is a reply to message #891654] Mon, 25 June 2012 13:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Save creates the ids that do not exist.

You can assign them yourself earlier.

Regards

Ed Willink

On 25/06/2012 13:15, Tex Iano wrote:
> Hi,
>
> within my application I have to find elements by means of a unique ID.
> However, the resource is not saved yet. Otherwise, I found out that I
> could use:
>
> element.eResource().getURIFragment(element);
>
> But what if the element is not part of the resource yet as it is not
> saved? How can I get a unique identifier?
>
> Using package1.package2.elementName is not unique as within the same
> package several elements with the same name can exist.
> Regards,
>
> Tex
Re: Unique element ID before saving [message #900218 is a reply to message #891671] Sun, 05 August 2012 17:07 Go to previous messageGo to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Hi,

I am still having problems with this point.

I am creating a UML model programmatically and I do not want to save it every time I change something. So I came to the conclusion that working on the resource is not a good idea.

However, sometimes on my UI I have to select a UML element etc. and have to transfer a unique identifier from my presentation layer to the business layer. What can I use as unique ID? As I wrote, my first thought was to use the name and its package location:

package1.package2.myClass

However in package2 several elements with the name "myClass" can exist. So: How can I identify a UML element within a model before it is saved? You said, I could assign an ID. But what kind of ID is it? The XMI ID? Is there no other way independent of XMI to reference an element?

Regards,

Tex

[Updated on: Sun, 05 August 2012 17:08]

Report message to a moderator

Re: Unique element ID before saving [message #900222 is a reply to message #900218] Sun, 05 August 2012 17:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
I'd expect a UUID to be assigned by UML's resource when the object is
attached. So eObject.eResource().getURIFragment(eObject) will generally
return you the UUID.


On 05/08/2012 7:07 PM, Tex Iano wrote:
> Hi,
>
> I am still having problems with this point.
>
> I am creating a UML model programmatically and I do not want to save
> it every time I change anything. So I came to the conclusion that
> working on the resource is not a good idea.
> However, sometimes on my UI I have to select a UML element etc. and
> have to transfer a unique identifier from my presentation layer to the
> business layer. What can I use as unique ID? As I wrote, my first
> thought was to use the name and its package location:
>
> package1.package2.myClass
>
> However in package2 several elements with the name "myClass" can
> exist. So: How can I identify a UML element within a model before it
> is saved? You said, I could assign an ID. But what kind of ID is it?
> The XMI ID? Is there no other way independent of XMI to reference an
> element?
>
> Regards,
>
> Tex


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Unique element ID before saving [message #900304 is a reply to message #900222] Mon, 06 August 2012 12:35 Go to previous message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Hi,

ah ok thanks.

And for other interested parties:

String id = element.eResource().getURIFragment(element);
		System.out.println("ID: " + element.eResource().getURIFragment(element));
		System.out.println("Element: " + element.eResource().getEObject(id))


This is how to get the object by ID.

Regards,

Tex
Previous Topic:UML Model Transformator
Next Topic:Possible Children
Goto Forum:
  


Current Time: Thu Apr 25 23:00:51 GMT 2024

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

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

Back to the top