01: /*
02: * Copyright (C) 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 04. May 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.benchmark.strings.products;
12:
13: import com.thoughtworks.xstream.XStream;
14: import com.thoughtworks.xstream.io.xml.XppDriver;
15: import com.thoughtworks.xstream.tools.benchmark.Product;
16:
17: import java.io.InputStream;
18: import java.io.OutputStream;
19: import java.util.Collections;
20: import java.util.WeakHashMap;
21:
22: /**
23: * Uses WeakHashMap for StringConverter.
24: *
25: * @author Jörg Schaible
26: * @see com.thoughtworks.xstream.tools.benchmark.Harness
27: * @see Product
28: */
29: public class StringWithSynchronizedWeakHashMapConverter implements
30: Product {
31:
32: private final XStream xstream;
33:
34: public StringWithSynchronizedWeakHashMapConverter() {
35: xstream = new XStream(new XppDriver());
36: xstream
37: .registerConverter(new StringWithWeakHashMapConverter.StringConverter(
38: Collections.synchronizedMap(new WeakHashMap())));
39: }
40:
41: public void serialize(Object object, OutputStream output)
42: throws Exception {
43: xstream.toXML(object, output);
44: }
45:
46: public Object deserialize(InputStream input) throws Exception {
47: return xstream.fromXML(input);
48: }
49:
50: public String toString() {
51: return "StringConverter using synchronized WeakHashMap";
52: }
53: }
|