01: /*
02: * Copyright (c) 2000-2001 Sosnoski Software Solutions, Inc.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20: * IN THE SOFTWARE.
21: */
22:
23: package com.sosnoski.xmlbench;
24:
25: import java.io.*;
26: import java.util.*;
27:
28: import org.gjt.xpp.*;
29:
30: /**
31: * Benchmark for measuring performance of the XPP document representation
32: * with normal nodes.<p>
33: *
34: * This code is based on a sample provided by Aleksander Slominski.
35: *
36: * @author Dennis M. Sosnoski
37: * @version 1.2
38: */
39:
40: public class BenchXPPBase extends BenchXPP {
41: /** Pull parser used within a test run. */
42: protected XmlPullParser m_parser;
43:
44: /**
45: * Constructor.
46: */
47:
48: public BenchXPPBase() {
49: super ("XPP");
50: }
51:
52: /**
53: * Build document representation by parsing XML. This implementation uses
54: * the method defined by XPP to build the document from an input stream
55: * wrapped in a reader, since direct parsing from a stream is not supported.
56: * Note that XPP supports other methods for constructing the document, but
57: * an input stream is considered the most representative of real
58: * applications.
59: *
60: * @param in XML document input stream
61: * @return document representation
62: */
63:
64: protected Object build(InputStream in) {
65: XmlNode doc = null;
66: try {
67: if (m_parser == null) {
68: if (m_parserFactory == null) {
69: m_parserFactory = XmlPullParserFactory
70: .newInstance();
71: m_parserFactory.setNamespaceAware(true);
72: }
73: m_parser = m_parserFactory.newPullParser();
74: } else {
75: m_parser.reset();
76: }
77: m_parser.setInput(new BufferedReader(new InputStreamReader(
78: in)));
79: m_parser.next();
80: doc = m_parserFactory.newNode();
81: m_parser.readNode(doc);
82: } catch (Exception ex) {
83: ex.printStackTrace(System.out);
84: System.exit(0);
85: }
86: return doc;
87: }
88:
89: /**
90: * Reset test class instance. This discards the parser used within a test
91: * pass, and calls the superclass method to reset state at that level.
92: */
93:
94: protected void reset() {
95: m_parser = null;
96: super.reset();
97: }
98: }
|