Why is the Ecore iD attribute scoped to the resource? [message #1855603] |
Sun, 23 October 2022 04:50  |
Eclipse User |
|
|
|
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 05:22   |
Eclipse User |
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07561 seconds