One of a kind – Generating UUID with EMF
Eclipse EMF provides the functionality to create universally unique identifier as described in A Universally Unique IDentifier (UUID) URN Namespace
To use this functionality just add a dependency to “org.eclipse.emf.ecore” to your plugin and you can start using it.
package de.vogella.emf.uuid;
import org.eclipse.emf.ecore.util.EcoreUtil;
public class MakeUniqueIds {
public static void main(String[] args) {
for (int i=0; i<100; i++){
System.out.println(EcoreUtil.generateUUID());
}
}
}
For example you may get “_Fj9QPC0XEd-zxLXA4jfyXA” as a result.
Eclipse e4 is currently using this functionality to generated unique model Id's. The responsible class for this is "org.eclipse.e4.workbench.ui.internal.E4XMIResource".
Thanks to Remy Suen for providing this info on the e4 mailing list.
March 11th, 2010 at 8:34 pm
You can also use java.util.UUID.randomUUID() to achive the same result without EMF.
March 12th, 2010 at 4:25 am
@Bryan: Thanks for the info!
March 13th, 2010 at 3:50 am
I am a bit puzzled by this claim. Being familiar with this RFC, I know it details different versions and variants, which can be particularly relevant for the context the UUID is used in.
The UUID utility class from the java.util library supports several of these. Why exactly has this wheel been reinvented?
Ironically, as I consider a project like EMF quite bloated, should I now conclude that part of the cause for that is that standard Java classes have been rewritten?
March 13th, 2010 at 4:46 am
@Dann Sorry, but I don’t know why EMF has re-implemented this. I’m also not aware of the difference between both implementations. If you want to know I suggest to check on the EMF forum.
March 14th, 2010 at 1:05 am
@Lars No worries! As a well-known critic of the role of EMF in e4, this type of thing is just ‘Gefundenes Fressen’. I am perfectly happy to see EMF continue its MDD quest, but not as a core part of the framework. I feel that EMF lacks the maturity and the broad appeal it needs to warrant adoption on this level by this community.
Because EMF is being pushed down our throats, I now have to spend time on criticizing, instead of on helping the Eclipse community to work for everyone. That’s pretty sad.
EMF wants to be in the driver seat? You’d better buckle up, then
March 15th, 2010 at 2:58 pm
I think EMF might have introduced its own variant because EMF did not originally target 1.5. I myself did not know of the java.util.UUID class until I read Bryan’s comment since I’ve primarily been working with 1.4 until e4 came along.