Why is the Ecore iD attribute scoped to the resource? [message #1855603] |
Sun, 23 October 2022 08:50 |
|
I understand that the iD flag of EAttribute indicates that the value of that attribute is a unique identifier of the EObject in the containing resource. It is that last part that I am struggling with.
If Ecore models are defined conceptually and the Resource abstraction is meant to protect the storage aspects, why is iD's definition referring to the Resource scope?
Does this not create a problem if a model is moved from one resource to another, and embedded, so the iD property does not hold any more?
Or does the ID property have to hold in every resource that implements storage for this EClass. Feels like the iD property then is a UUID?
|
|
|
Re: Why is the Ecore iD attribute scoped to the resource? [message #1855604 is a reply to message #1855603] |
Sun, 23 October 2022 09:22 |
Ed Merks Messages: 32985 Registered: July 2009 |
Senior Member |
|
|
Yes, ID attributes have limited usefulness and it's difficult to maintain their uniqueness.
The concept mirrors what's provided via xml:id, i.e., "the value is unique within the XML document, and that each element has at most one single unique identifier":
https://www.w3.org/TR/xml-id/
In EMF document == resource.
Yes, if you move or copy an element with an ID you are likely to violate the constraint.
The constraint is implemented like this:
public boolean validate_UniqueID(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
{
boolean result = true;
String id = EcoreUtil.getID(eObject);
if (id != null)
{
Resource resource = eObject.eResource();
if (resource != null)
{
EObject otherEObject = resource.getEObject(id);
if (eObject != otherEObject && otherEObject != null)
{
result = false;
if (diagnostics != null)
{
diagnostics.add
(createDiagnostic
(Diagnostic.ERROR,
DIAGNOSTIC_SOURCE,
EOBJECT__UNIQUE_ID,
"_UI_DuplicateID_diagnostic",
new Object []
{
id,
getObjectLabel(eObject, context),
getObjectLabel(otherEObject, context)
},
new Object [] { eObject, otherEObject, id },
context));
}
}
}
}
return result;
} So every resource is expected to support looking up an object by its ID. For two resources r1 and r2 there is no requirement that r1.getEObject(id) and r2.getEObject(id) can't both be return non-null different objects. In other words, resources can reuse IDs.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Why is the Ecore iD attribute scoped to the resource? [message #1855605 is a reply to message #1855604] |
Sun, 23 October 2022 10:03 |
|
Ok. That explains it. I had read that code, but not thought that implication through to the end. Very helpful. Reason I am asking is I see a lot re-invention happening with people doing resource management at a second tier when EMF already has what seems excellent resource management and clean semantics built in. So I am trying to write an article to cohesively explain this. Especially features like IDs and resolution/canonisation are core to all larger applications and I feel they are often ignored.
|
|
|
|
|
Re: Why is the Ecore iD attribute scoped to the resource? [message #1855612 is a reply to message #1855607] |
Sun, 23 October 2022 13:45 |
|
Thanks for the detail. I did not mean to take up that match of your time! This has helped. If you care, I am happy to provide draft of the document. I assume that the LUSSIDs are essentially a type of semi-structured hash? I have not found the reference using a web search, so I cannot add this, but will reference this discussion thread.
|
|
|
|
Re: Why is the Ecore iD attribute scoped to the resource? [message #1855618 is a reply to message #1855617] |
Sun, 23 October 2022 20:33 |
|
Another one along the same lines. Assuming I would like to reuse the setUUID() mechanism in XmlResourceImpl, but render a different output syntax, what would be the correct way to contribute the concrete syntax rendering for the alternate notation. It seems it would be org.eclipse.emf.ecore.xmi.DOMHandler and org.eclipse.emf.ecore.xmi.DOMHelper. Is that correct? How does the override look for this case?
|
|
|
|
Powered by
FUDForum. Page generated in 0.02223 seconds