01: /*
02: * Copyright (C) 2004, 2005 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.io.path;
13:
14: import com.thoughtworks.xstream.converters.ErrorWriter;
15: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16: import com.thoughtworks.xstream.io.ReaderWrapper;
17:
18: /**
19: * Wrapper for HierarchicalStreamReader that tracks the path (a subset of XPath) of the current node that is being read.
20: *
21: * @see PathTracker
22: * @see Path
23: *
24: * @author Joe Walnes
25: */
26: public class PathTrackingReader extends ReaderWrapper {
27:
28: private final PathTracker pathTracker;
29:
30: public PathTrackingReader(HierarchicalStreamReader reader,
31: PathTracker pathTracker) {
32: super (reader);
33: this .pathTracker = pathTracker;
34: pathTracker.pushElement(getNodeName());
35: }
36:
37: public void moveDown() {
38: super .moveDown();
39: pathTracker.pushElement(getNodeName());
40: }
41:
42: public void moveUp() {
43: super .moveUp();
44: pathTracker.popElement();
45: }
46:
47: public void appendErrors(ErrorWriter errorWriter) {
48: errorWriter.add("path", pathTracker.getPath().toString());
49: super.appendErrors(errorWriter);
50: }
51:
52: }
|