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 13. January 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.extended;
13:
14: import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
15:
16: import java.io.File;
17:
18: /**
19: * This converter will take care of storing and retrieving File with either
20: * an absolute path OR a relative path depending on how they were created.
21: *
22: * @author Joe Walnes
23: */
24: public class FileConverter extends AbstractSingleValueConverter {
25:
26: public boolean canConvert(Class type) {
27: return type.equals(File.class);
28: }
29:
30: public Object fromString(String str) {
31: return new File(str);
32: }
33:
34: public String toString(Object obj) {
35: return ((File) obj).getPath();
36: }
37:
38: }
|