01: /*
02: * Copyright (C) 2008 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 04. January 2008 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.converters.basic;
12:
13: import com.thoughtworks.xstream.converters.ConversionException;
14:
15: import java.util.UUID;
16:
17: /**
18: * Converts a java.util.UUID to a string.
19: *
20: * @author Jörg Schaible
21: */
22: public class UUIDConverter extends AbstractSingleValueConverter {
23:
24: public boolean canConvert(Class type) {
25: return type.equals(UUID.class);
26: }
27:
28: public Object fromString(String str) {
29: try {
30: return UUID.fromString(str);
31: } catch (IllegalArgumentException e) {
32: throw new ConversionException(
33: "Cannot create UUID instance", e);
34: }
35: }
36:
37: }
|