Question

I've been googling around for a solution, and read a lot of questions/answers here in SOF, but didn't find anything I could use.

My problem is the following: I need to uniquely identify EMF elements across different machines. The lowest level known superclass would be org.eclipse.emf.common.notify.Notifier, as the elements may be resources and/or model elements.

The Id should be reproducible at runtime across the different machines (I may have to calculate the ID both in the client and server having only a reference to the Java object). I have no access to the source code, I cannot modify the models (files), and not all model elements have a uuids.

As the Id should be reproducible across different machines, I cannot use hashCode() (any form). I thought on using MD5 hashes, but I cannot figure out what to use as the seed of the MD5 hash that would make it unique (to some extent) and reproducible at the same time.

All help would be greatly appreciated!

Was it helpful?

Solution

Well, I kind of found a solution. I use different ID's for EObjects and for Resources:

  • For EObjects, I get their fragment URI (their path inside the containing resource), make it a String, and use that as the seed to the MD5 hash. It turns out that the result of fragmentURI().toString() looks amazingly similar to what EMF generates as the UUID. :-)

  • For Resources, I get the file's contents (model files are generally XMI/XML files) and calculate the MD5 hash on those.

The solution is a little heavy, specially the resource piece, but I make it up by minimizing the calls to the ID's generation algorithm, so it is ok for me. What it is is unique and reproducible across machines, which is what I needed.

Hope this helps someone in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top