Source Code Cross Referenced for BenchXerces.java in  » XML » tclib » com » sosnoski » xmlbench » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » tclib » com.sosnoski.xmlbench 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2000-2001 Sosnoski Software Solutions, Inc.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
019:         * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
020:         * IN THE SOFTWARE.
021:         */
022:
023:        package com.sosnoski.xmlbench;
024:
025:        import java.io.*;
026:        import java.util.*;
027:
028:        import javax.xml.parsers.*;
029:
030:        import org.apache.xerces.dom.*;
031:        import org.apache.xerces.parsers.*;
032:        import org.apache.xml.serialize.*;
033:
034:        import org.w3c.dom.*;
035:
036:        import org.xml.sax.*;
037:
038:        /**
039:         * Abstract base class for benchmarks measuring performance of the Xerces DOM
040:         * document representation. This base class implementation can be customized
041:         * by subclasses to experiment with options for the representation, in
042:         * particular for trying the deferred node expansion feature of Xerces.
043:         *
044:         * @author Dennis M. Sosnoski
045:         * @version 1.2
046:         */
047:
048:        public abstract class BenchXerces extends BenchDOM {
049:            /** Flag for using deferred node expansion. */
050:            private boolean m_deferExpansion;
051:
052:            /** DOM parser used within a test run. */
053:            private DOMParser m_parser;
054:
055:            /** XML output serializer used within a test run. */
056:            private XMLSerializer m_serializer;
057:
058:            /**
059:             * Constructor.
060:             *
061:             * @param config test configuration name
062:             * @param defer defer node expansion flag
063:             */
064:
065:            protected BenchXerces(String config, boolean defer) {
066:                super (config);
067:                m_deferExpansion = defer;
068:            }
069:
070:            /**
071:             * Set deferred node expansion mode.
072:             *
073:             * @param defer defer node expansion flag
074:             */
075:
076:            protected void setDeferExpansion(boolean defer) {
077:                m_deferExpansion = defer;
078:            }
079:
080:            /**
081:             * Build document representation by parsing XML. This implementation
082:             * creates a DOM parser if one does not already exist, then reuses
083:             * that parser for the duration of a test run..
084:             *
085:             * @param in XML document input stream
086:             * @return document representation
087:             */
088:
089:            protected Object build(InputStream in) {
090:                if (m_parser == null) {
091:                    m_parser = new DOMParser();
092:                    try {
093:                        m_parser
094:                                .setFeature(
095:                                        "http://xml.org/sax/features/validation",
096:                                        false);
097:                        m_parser
098:                                .setFeature(
099:                                        "http://apache.org/xml/features/dom/defer-node-expansion",
100:                                        m_deferExpansion);
101:                        m_parser.setFeature(
102:                                "http://xml.org/sax/features/namespaces", true);
103:                    } catch (Exception ex) {
104:                        ex.printStackTrace(System.err);
105:                        System.exit(0);
106:                    }
107:                }
108:                Object doc = null;
109:                try {
110:                    m_parser.parse(new InputSource(in));
111:                    doc = m_parser.getDocument();
112:                    m_parser.reset();
113:                } catch (Exception ex) {
114:                    ex.printStackTrace(System.err);
115:                    System.exit(0);
116:                }
117:                return doc;
118:            }
119:
120:            /**
121:             * Output a document as XML text. This method uses the method defined
122:             * by the Xerces DOM to output a text representation of the document.
123:             *
124:             * @param doc document representation to be output
125:             * @param out XML document output stream
126:             */
127:
128:            protected void output(Object doc, OutputStream out) {
129:                if (m_serializer == null) {
130:                    OutputFormat format = new OutputFormat((Document) doc);
131:                    m_serializer = new XMLSerializer(format);
132:                }
133:                try {
134:                    m_serializer.reset();
135:                    m_serializer.setOutputByteStream(out);
136:                    m_serializer.serialize(((Document) doc)
137:                            .getDocumentElement());
138:                } catch (Exception ex) {
139:                    ex.printStackTrace(System.err);
140:                    System.exit(0);
141:                }
142:            }
143:
144:            /**
145:             * Reset test class instance. This discards the parser used
146:             * within a test pass.
147:             */
148:
149:            protected void reset() {
150:                m_parser = null;
151:                m_serializer = null;
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.