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