01: /*
02: * Copyright (C) 2004, 2006 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 03. April 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.core;
13:
14: import com.thoughtworks.xstream.alias.ClassMapper;
15: import com.thoughtworks.xstream.converters.ConverterLookup;
16: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17: import com.thoughtworks.xstream.io.path.Path;
18: import com.thoughtworks.xstream.mapper.Mapper;
19:
20: public class ReferenceByXPathMarshaller extends
21: AbstractReferenceMarshaller {
22:
23: private final int mode;
24:
25: public ReferenceByXPathMarshaller(HierarchicalStreamWriter writer,
26: ConverterLookup converterLookup, Mapper mapper, int mode) {
27: super (writer, converterLookup, mapper);
28: this .mode = mode;
29: }
30:
31: /**
32: * @deprecated As of 1.2, use {@link #ReferenceByXPathMarshaller(HierarchicalStreamWriter, ConverterLookup, Mapper, int)}
33: */
34: public ReferenceByXPathMarshaller(HierarchicalStreamWriter writer,
35: ConverterLookup converterLookup, ClassMapper classMapper) {
36: this (writer, converterLookup, classMapper,
37: ReferenceByXPathMarshallingStrategy.RELATIVE);
38: }
39:
40: protected String createReference(Path currentPath,
41: Object existingReferenceKey) {
42: return (mode == ReferenceByXPathMarshallingStrategy.RELATIVE ? currentPath
43: .relativeTo((Path) existingReferenceKey)
44: : existingReferenceKey).toString();
45: }
46:
47: protected Object createReferenceKey(Path currentPath) {
48: return currentPath;
49: }
50:
51: protected void fireValidReference(Object referenceKey) {
52: // nothing to do
53: }
54: }
|