Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » generation of ID to identify EMF element (without modifying the name based referencing mechanism)(ID generation )
generation of ID to identify EMF element (without modifying the name based referencing mechanism) [message #1757989] Wed, 22 March 2017 14:59 Go to next message
Zakir Meer is currently offline Zakir MeerFriend
Messages: 25
Registered: February 2016
Junior Member
Hello Experts,

** I want to generate unique ID's for each EMF model element without disturbing the referencing mechanism of the EMF model (as we have name based referencing mechanism for the mdoel elements - instead of ID based)

index.php/fa/28831/0/

I used below code to set ID's for each element, but unfortunately below code is disturbing the referencing mechanism and setting generated ID at the place where reference should be specified.

private void visitElements(Resource inputSource) {
		if(inputSource instanceof XMLResource){
			TreeIterator<EObject> allContents = null;
			if(inputSource instanceof Resource){
				allContents=  EcoreUtil.getAllContents(inputSource, true);
			} 
			for (final TreeIterator<EObject> iter = allContents; iter.hasNext();) {
				final EObject element = iter.next();

				((XMLResource)inputSource).setID(element, EcoreUtil.generateUUID());
			}
		}
	}


index.php/fa/28832/0/


Input Model:

<tags name="testTag" tagType="COMPONENT"/>

<components name="testComponent" tags="testTag" callback="false" service="false">

</components>


Expected change in Model:

index.php/fa/28831/0/


I am looking for EMF attribute (at EObject level - valid as per XMI schema: for storing ID ) which can be used in the serialized EMF model without impacting the validity of the model XMI and without changing the referencing mechanism (name based references) which is predefined.


[Updated on: Wed, 22 March 2017 15:01]

Report message to a moderator

Re: generation of ID to identify EMF element (without modifying the name based referencing mechanism [message #1757993 is a reply to message #1757989] Wed, 22 March 2017 15:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5580
Registered: July 2009
Senior Member
Hi

If you use xmi:id, you must use xmi:id and indeed you do. I see nothing wrong with your wrong usage apart from poor human readability.

If you want readability and/or stability, you may choose to code an xmi:id generator that exploits the semantics/hierarchy to give unique names that are readable.

You should find that you only interfere with EMF referencing capability if you set xmi:ids on one Resource and neglect to save other Resources that reference it.

What are you really trying to achieve in comparison to default EMF functionality? Readability/compactness/stability/... Do you really need it? I suggest that this is a premature optimization that you should defer until you have much more experience with using EMF.

Regards

Ed Willink
Re: generation of ID to identify EMF element (without modifying the name based referencing mechanism [message #1758072 is a reply to message #1757993] Thu, 23 March 2017 09:44 Go to previous messageGo to next message
Zakir Meer is currently offline Zakir MeerFriend
Messages: 25
Registered: February 2016
Junior Member
Hi Ed,

I want to enhance the serialized model xmi with features which are not specified in the metamodel. Basically modifying the serialized model XMI with additional data (without making it invalid - as per the loader).

I got some hints form the following forum entry : https://www.eclipse.org/forums/index.php?t=msg&th=551708&goto=1138919&#msg_1138919

Once I have a concrete solution I will post it back on the group the approach which I have followed.


Re: generation of ID to identify EMF element (without modifying the name based referencing mechanism [message #1758078 is a reply to message #1758072] Thu, 23 March 2017 10:46 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5580
Registered: July 2009
Senior Member
Hi

I really can't recommend it, but if you really want anarchic extension, there is support for weird XSDisms. You can find many clues in http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchemaToEcoreMapping.pdf

Probably the best way to proceed is to write an XSD that includes the major mechanisms that you need, then use the XSD2Ecore conversion to discover the Ecore equivalent.

I repeat. I really do not recommend this. Rethink and use Ecore conventionally.

Regards

Ed Willink

Previous Topic:How can access eStructuralFeatures any of EClassifier?
Next Topic:How can I implement a workflow wizard over a EMF Ecore metamodel?
Goto Forum:
  


Current Time: Fri Jan 19 00:13:38 GMT 2018

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

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