Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Setting element 'ID's in KDM and traversing references
Setting element 'ID's in KDM and traversing references [message #638474] Thu, 11 November 2010 07:37 Go to next message
Amir Yazdanshenas is currently offline Amir Yazdanshenas
Messages: 8
Registered: July 2009
Junior Member
Hi,

I have a question regarding element IDs and references.

In the KDM reference document, the elements have an ID like the following:
<someElement xmi:id="id.12" ... to="id.18" from="id.1">

1) I don't know how to set element IDs in KDM in that way. I set an ID by (mis)using XMI:
((XMIResourceImpl)someModel).setID(((EObject)someElement), "123456");

And the result serialization of such model is:
<someElement xmi:id="123456" ... >

Is this way of setting IDs correct? Can I later retrieve a model element by saying sth like this:
model.getElementByID(123456) ?

2) I use TaggedRef to extend my model with some references between elements. For a reference from myElement1 to myElement2, I have:
myTaggedRef.setRef(myElement2);
myElement1.getTaggedValue.add(myTaggedRef);

and the result model after serialization is:
<inventoryElement ... name="myElement1">
<taggedValue xsi:type="kdm:TaggedRef" tag=... ref="/0/@inventoryElement.0"/>
</inventoryElement>

The 'ref' attribute seems to point to the right element in the XMI file, if I interpret "/0/@inventoryElement.0"/" as a directory-like path.

Am I doing these two actions correctly? Or, there is a better way to set IDs and references in KDM models? (What is the best solution to make traversal models?)

Sorry for the lengthy message:) I highly appreciate any helps.

Cheers,
Amir

[Updated on: Thu, 11 November 2010 07:38]

Report message to a moderator

Re: Setting element 'ID's in KDM and traversing references [message #638698 is a reply to message #638474] Fri, 12 November 2010 04:12 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hi,

in common use cases you should not take care of Id/refs management. It
is only technical stuff and the framework is doing it for you.
So you just have to set relations between elements from a semantic point
of view.

e.g.
a kdm.StorableUnit instance has a type[1..1]->DataType
So we may invoke "myST.setType(myDT)", and then we may add "myST" to the
contents of a first XMIResource instance and then "myDT" to the contents
of a second XMIResource instance --> serialization does the job of
managing the references between the two xmi files.

-> So "XMLResource.SetID" should not be used in common use cases. But
may be i don't know enough about your use case.
-> Using kdm.TaggedRef allows, in kdm domain, "information to be
attached to any model element in the form of a reference to another
exiting model element". So you may use it if your relation does not
match any existing kdm relation (e.g type[0..1]). It is a kind of
metamodel extension mechanism as we find it in UML domain (UML profiles).

I hope i answer your question. May be you have some advanced need i
dont't know.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Setting element 'ID's in KDM and traversing references [message #638762 is a reply to message #638698] Fri, 12 November 2010 08:53 Go to previous messageGo to next message
Amir Yazdanshenas is currently offline Amir Yazdanshenas
Messages: 8
Registered: July 2009
Junior Member
Hi Fabien,

Many thanks for your reply.

I am pulling out some information from a C program (using a program analysis tool), and I want to store, process and represent this information using KDM.

All 'data units' in this program analysis tool come with a unique ID, and there are multiple relations between these data items (e.g. different types of dependencies). That's why I am curious to know about IDs and references in KDM.
(The semantics of some of the mentioned 'data units' fit some of the KDM metaelement classes, and some don't. So I am instantiating KDM existing classes for some, also extending some metamodel classes for the others.)

I am using a two-phase approach for this transformation. First I build all model elements from the 'data units' and on the second phase build the relations between the elements.

But, If I don't set an ID for the element, how am I going to retrieve the item in the second phase and add its relations?

And also, what is the best way to query models? Can I say sth like this:
myModel.getElementByName("myFile.c")?

Ragrds,
Amir

[Updated on: Fri, 12 November 2010 09:01]

Report message to a moderator

Re: Setting element 'ID's in KDM and traversing references [message #639096 is a reply to message #638762] Mon, 15 November 2010 04:49 Go to previous message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
ok i understand better your questions now.
So, you may use ID for your two-phase approach. Or else building localy
a Map<String, EObject> with ids as keys during your first phase, and
using it during your second phase...


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Previous Topic:[JSP Component] Help with generation plugin
Next Topic:MoDisco for annotation processing
Goto Forum:
  


Current Time: Thu Jul 24 16:17:21 EDT 2014

Powered by FUDForum. Page generated in 0.02652 seconds