01: /*
02: * Copyright (C) 2006, 2007 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 20. February 2006 by Mauro Talevi
10: */
11: package com.thoughtworks.xstream.converters;
12:
13: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15:
16: /**
17: * Wrapper to convert a {@link com.thoughtworks.xstream.converters.SingleValueConverter} into a
18: * {@link com.thoughtworks.xstream.converters.Converter}.
19: *
20: * @author Jörg Schaible
21: * @see com.thoughtworks.xstream.converters.Converter
22: * @see com.thoughtworks.xstream.converters.SingleValueConverter
23: */
24: public class SingleValueConverterWrapper implements Converter,
25: SingleValueConverter {
26:
27: private final SingleValueConverter wrapped;
28:
29: public SingleValueConverterWrapper(SingleValueConverter wrapped) {
30: this .wrapped = wrapped;
31: }
32:
33: public boolean canConvert(Class type) {
34: return wrapped.canConvert(type);
35: }
36:
37: public String toString(Object obj) {
38: return wrapped.toString(obj);
39: }
40:
41: public Object fromString(String str) {
42: return wrapped.fromString(str);
43: }
44:
45: public void marshal(Object source, HierarchicalStreamWriter writer,
46: MarshallingContext context) {
47: writer.setValue(toString(source));
48: }
49:
50: public Object unmarshal(HierarchicalStreamReader reader,
51: UnmarshallingContext context) {
52: return fromString(reader.getValue());
53: }
54:
55: }
|