1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.jaxb;
|
11
|
|
12
|
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
/**
|
17
|
* @author a.mueller
|
18
|
* @created 23.07.2008
|
19
|
* @version 1.0
|
20
|
*/
|
21
|
|
22
|
|
23
|
public class UUIDAdapter extends XmlAdapter<String, String> {
|
24
|
private static final Logger logger = Logger.getLogger(UUIDAdapter.class);
|
25
|
|
26
|
public static String UUID_URN_PREFIX = "urn-uuid-";
|
27
|
|
28
|
@Override
|
29
|
public String marshal(String uuidStr) throws Exception {
|
30
|
return UUIDAdapter.UUID_URN_PREFIX + uuidStr;
|
31
|
}
|
32
|
|
33
|
@Override
|
34
|
public String unmarshal(String string) throws Exception {
|
35
|
if(string.startsWith(UUIDAdapter.UUID_URN_PREFIX)) {
|
36
|
String uuidPart = string.substring(UUIDAdapter.UUID_URN_PREFIX.length());
|
37
|
return uuidPart;
|
38
|
} else {
|
39
|
throw new Exception("uuid attribute should start with " + UUIDAdapter.UUID_URN_PREFIX);
|
40
|
}
|
41
|
|
42
|
}
|
43
|
|
44
|
}
|