uuid = UUID.fromString(source);
idBytes = ByteBuffer.wrap(UUIDGen.decompose(uuid));
}
catch (IllegalArgumentException e)
{
throw new MarshalException(String.format("unable to make UUID from '%s'", source), e);
}
} else if (source.toLowerCase().equals("now"))
{
idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes());
}
// Milliseconds since epoch?
else if (source.matches("^\\d+$"))
{
try
{
idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(Long.parseLong(source)));
}
catch (NumberFormatException e)
{
throw new MarshalException(String.format("unable to make version 1 UUID from '%s'", source), e);
}
}
// Last chance, attempt to parse as date-time string
else
{
try
{
long timestamp = DateUtils.parseDate(source, iso8601Patterns).getTime();
idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(timestamp));
}
catch (ParseException e1)
{
throw new MarshalException(String.format("unable to coerce '%s' to version 1 UUID", source), e1);
}
}
return idBytes;
}