Setting element 'ID's in KDM and traversing references [message #638474] |
Thu, 11 November 2010 12:37 |
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 12:38] Report message to a moderator
|
|
|
|
Re: Setting element 'ID's in KDM and traversing references [message #638762 is a reply to message #638698] |
Fri, 12 November 2010 13:53 |
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 14: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 09:49 |
Fabien Giquel Messages: 147 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
rue Nina Simone
44000 NANTES
----------------------------------------------------
|
|
|
Powered by
FUDForum. Page generated in 0.02685 seconds