Source Code Cross Referenced for XMLByteStreamCompilerInterpreterTestCase.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » sax » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.sax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.components.sax;
018:
019:        import org.xml.sax.helpers.DefaultHandler;
020:        import org.xml.sax.ContentHandler;
021:        import org.apache.cocoon.xml.dom.DOMBuilder;
022:        import org.apache.cocoon.xml.AbstractXMLTestCase;
023:        import org.apache.cocoon.xml.DefaultHandlerWrapper;
024:        import javax.xml.parsers.SAXParser;
025:        import javax.xml.parsers.SAXParserFactory;
026:        import java.io.ByteArrayInputStream;
027:
028:        /**
029:         * Testcase for XMLByteStreamCompiler and Interpreter
030:         *
031:         * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
032:         * @version
033:         */
034:
035:        public final class XMLByteStreamCompilerInterpreterTestCase extends
036:                AbstractXMLTestCase {
037:            public XMLByteStreamCompilerInterpreterTestCase(String s) {
038:                super (s);
039:            }
040:
041:            public void testCompareDOM() throws Exception {
042:                // reference
043:                DOMBuilder in = new DOMBuilder();
044:                generateLargeSAX(in);
045:
046:                // capture events
047:                XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
048:                generateLargeSAX(xmlc);
049:
050:                // recall events and build a DOM from it
051:                XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
052:                DOMBuilder out = new DOMBuilder();
053:                xmli.setConsumer(out);
054:                xmli.deserialize(xmlc.getSAXFragment());
055:
056:                // compare DOMs
057:                assertXMLEqual(in.getDocument(), out.getDocument());
058:            }
059:
060:            public void testCompareByteArray() throws Exception {
061:                // capture events
062:                XMLByteStreamCompiler sa = new XMLByteStreamCompiler();
063:                generateLargeSAX(sa);
064:
065:                // serialize events
066:                byte[] aa = (byte[]) sa.getSAXFragment();
067:
068:                // deserialize and capture
069:                XMLByteStreamCompiler sb = new XMLByteStreamCompiler();
070:                XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
071:                xmli.setConsumer(sb);
072:                xmli.deserialize(aa);
073:
074:                // serialize again
075:                byte[] ab = (byte[]) sb.getSAXFragment();
076:
077:                assertTrue(aa.length == ab.length);
078:
079:                for (int i = 0; i < aa.length; i++) {
080:                    assertEquals(aa[i], ab[i]);
081:                }
082:            }
083:
084:            public void testStressLoop() throws Exception {
085:                XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
086:
087:                long loop = 10000;
088:
089:                // simply consume documents
090:                long start = System.currentTimeMillis();
091:                for (int i = 0; i < loop; i++) {
092:                    generateSmallSAX(xmlc);
093:                    xmlc.recycle();
094:                }
095:                long stop = System.currentTimeMillis();
096:
097:                double r = 1000 * loop / (stop - start);
098:                System.out.println("consuming: " + r + " documents per second");
099:            }
100:
101:            public void testCompareToParsing() throws Exception {
102:                DOMBuilder in = new DOMBuilder();
103:                generateSmallSAX(in);
104:
105:                SAXParserFactory pfactory = SAXParserFactory.newInstance();
106:                SAXParser p = pfactory.newSAXParser();
107:
108:                XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
109:                DefaultHandlerWrapper wrapper = new DefaultHandlerWrapper(xmlc);
110:
111:                ByteArrayInputStream bis = new ByteArrayInputStream(
112:                        generateByteArray());
113:
114:                long loop = 10000;
115:
116:                // parse documents
117:                long start = System.currentTimeMillis();
118:                for (int i = 0; i < loop; i++) {
119:                    xmlc.recycle();
120:                    bis.reset();
121:                    p.parse(bis, wrapper);
122:                }
123:                long stop = System.currentTimeMillis();
124:
125:                double r = 1000 * loop / (stop - start);
126:                System.out.println("parsed: " + r + " documents per second");
127:
128:                XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
129:                ContentHandler ch = new DefaultHandler();
130:
131:                // recall documents
132:                start = System.currentTimeMillis();
133:                for (int i = 0; i < loop; i++) {
134:                    xmli.setContentHandler(ch);
135:                    xmli.deserialize(xmlc.getSAXFragment());
136:                }
137:                stop = System.currentTimeMillis();
138:
139:                r = 1000 * loop / (stop - start);
140:                System.out.println("recalling: " + r + " documents per second");
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.