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 pull 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 BenchXPPPull extends BenchXPP {
41: /**
42: * Constructor.
43: */
44:
45: public BenchXPPPull() {
46: super ("XPP pull");
47: }
48:
49: /**
50: * Build document representation by parsing XML. This implementation uses
51: * the method defined by XPP to build the document from an input stream
52: * wrapped in a reader, since direct parsing from a stream is not supported.
53: * Note that XPP supports other methods for constructing the document, but
54: * an input stream is considered the most representative of real
55: * applications.
56: *
57: * @param in XML document input stream
58: * @return document representation
59: */
60:
61: protected Object build(InputStream in) {
62: XmlNode doc = null;
63: try {
64: if (m_parserFactory == null) {
65: m_parserFactory = XmlPullParserFactory.newInstance();
66: m_parserFactory.setNamespaceAware(true);
67: }
68: XmlPullParser parser = m_parserFactory.newPullParser();
69: parser.setInput(new BufferedReader(
70: new InputStreamReader(in)));
71: parser.next();
72: doc = m_parserFactory.newPullNode(parser);
73: ;
74: } catch (Exception ex) {
75: ex.printStackTrace(System.out);
76: System.exit(0);
77: }
78: return doc;
79: }
80: }
|