Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352347

Summary: Add encodeUUID() and decodeUUID() to EcoreUtil
Product: [Modeling] EMF Reporter: Eike Stepper <stepper>
Component: CoreAssignee: Ed Merks <Ed.Merks>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3    
Version: 2.8.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch v1
none
Patch v2 none

Description Eike Stepper CLA 2011-07-18 10:14:44 EDT
Created attachment 199836 [details]
Patch v1

I need the ability to base64 encode and decode the byte arrays that are populated by EcoreUtil.generateUUID(byte[]).
Comment 1 Eike Stepper CLA 2011-07-18 10:18:55 EDT
If you generally agree with this patch we could optimize the static footprint a little by stripping off some leading and trailing zero elements from the BASE64_INDEX array.
Comment 2 Ed Merks CLA 2011-07-18 11:51:29 EDT
XMLTypeFactory already has support for base64 encoding and decoding (because there's a data type for that in XML Schema. 

I'm just curious why you'd need something specific to EMF's UUID class; you could use the above utilities stripping/adding the leading _.  In particular, in what situations can you ever really assume you're dealing with a UUID as opposed to some arbitrary String representing any old ID?
Comment 3 Eike Stepper CLA 2011-07-18 14:02:20 EDT
(In reply to comment #2)
> XMLTypeFactory already has support for base64 encoding and decoding (because
> there's a data type for that in XML Schema. 

Oh, I didn't know that one. Since there's this generateUUID() method on EcoreUtil with the String return value I thought it would be good to use the reverse of that particular encoding in my own I/O.

> I'm just curious why you'd need something specific to EMF's UUID class; you
> could use the above utilities stripping/adding the leading _.  In particular,
> in what situations can you ever really assume you're dealing with a UUID as
> opposed to some arbitrary String representing any old ID?

In CDO I'm currently adding support for client-side assigned object IDs. They must be "system wide" unique without contacting any master authority. The actual ID value generation is pluggable and the values are stored in a CDOID subclass with a byte[] field (side note: because in a CDO system there's a considerable number of CDOID values I'm even considering to use 16 single byte primitive fields or 2 long fields instead to spare a pointer and some heap fragmentation).

At some places in the CDO framework, for example, the database mappings, I need String de/encoding of the bytes. So I thought it may have some value to use the same en/decoding that users wold see in their XML or other resources.
Comment 4 Eike Stepper CLA 2011-07-18 19:55:13 EDT
Created attachment 199871 [details]
Patch v2

This version makes the nested UUID class public and adds the ability to pass a node address. If no node address is passed then the class tries to determine the hardware address (jre6 needed) or, if that fails, a random 6 bytes sequence.

The decoder's static footprint contribution has been reduced from 1024 to 78 bytes.
Comment 5 Eike Stepper CLA 2011-07-18 19:57:03 EDT
v2 assumes that a jdk6+ is used to compile EMF. If that's not true then reflection must be used to invoke the NetworkInterface.getHardwareAddress() method.
Comment 6 Ed Merks CLA 2012-10-05 01:46:24 EDT
Not really needed.