01: /*
02: * Copyright (C) 2006, 2007, 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 26.09.2007 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.core;
12:
13: import com.thoughtworks.xstream.MarshallingStrategy;
14: import com.thoughtworks.xstream.alias.ClassMapper;
15: import com.thoughtworks.xstream.converters.ConverterLookup;
16: import com.thoughtworks.xstream.converters.DataHolder;
17: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19: import com.thoughtworks.xstream.mapper.Mapper;
20:
21: /**
22: * Basic functionality of a tree based marshalling strategy.
23: *
24: * @author Joe Walnes
25: * @author Jörg Schaible
26: * @since 1.3
27: */
28: public abstract class AbstractTreeMarshallingStrategy implements
29: MarshallingStrategy {
30:
31: public Object unmarshal(Object root,
32: HierarchicalStreamReader reader, DataHolder dataHolder,
33: ConverterLookup converterLookup, Mapper mapper) {
34: TreeUnmarshaller context = createUnmarshallingContext(root,
35: reader, converterLookup, mapper);
36: return context.start(dataHolder);
37: }
38:
39: public void marshal(HierarchicalStreamWriter writer, Object obj,
40: ConverterLookup converterLookup, Mapper mapper,
41: DataHolder dataHolder) {
42: TreeMarshaller context = createMarshallingContext(writer,
43: converterLookup, mapper);
44: context.start(obj, dataHolder);
45: }
46:
47: protected abstract TreeUnmarshaller createUnmarshallingContext(
48: Object root, HierarchicalStreamReader reader,
49: ConverterLookup converterLookup, Mapper mapper);
50:
51: protected abstract TreeMarshaller createMarshallingContext(
52: HierarchicalStreamWriter writer,
53: ConverterLookup converterLookup, Mapper mapper);
54:
55: /**
56: * @deprecated As of 1.2, use {@link #unmarshal(Object, HierarchicalStreamReader, DataHolder, ConverterLookup, Mapper)}
57: */
58: public Object unmarshal(Object root,
59: HierarchicalStreamReader reader, DataHolder dataHolder,
60: DefaultConverterLookup converterLookup,
61: ClassMapper classMapper) {
62: return unmarshal(root, reader, dataHolder,
63: (ConverterLookup) converterLookup, (Mapper) classMapper);
64: }
65:
66: /**
67: * @deprecated As of 1.2, use {@link #marshal(HierarchicalStreamWriter, Object, ConverterLookup, Mapper, DataHolder)}
68: */
69: public void marshal(HierarchicalStreamWriter writer, Object obj,
70: DefaultConverterLookup converterLookup,
71: ClassMapper classMapper, DataHolder dataHolder) {
72: marshal(writer, obj, converterLookup, (Mapper) classMapper,
73: dataHolder);
74: }
75:
76: }
|