KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > serializer > dom > XercesXMLSerializerDriver


1 /*
2  * Japex ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * This Software is distributed under the following terms:
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, is permitted provided that the following conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistribution in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * Neither the name of Sun Microsystems, Inc., 'Java', 'Java'-based names,
19  * nor the names of contributors may be used to endorse or promote products
20  * derived from this Software without specific prior written permission.
21  *
22  * The Software is provided "AS IS," without a warranty of any kind. ALL
23  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
24  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25  * PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS
26  * SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE
27  * AS A RESULT OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE
28  * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE
29  * LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
30  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED
31  * AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
32  * INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGES.
34  *
35  * You acknowledge that the Software is not designed, licensed or intended
36  * for use in the design, construction, operation or maintenance of any
37  * nuclear facility.
38  */

39
40 package serializer.dom;
41
42 import java.io.File JavaDoc;
43 import java.io.ByteArrayInputStream JavaDoc;
44 import java.io.ByteArrayOutputStream JavaDoc;
45
46 import javax.xml.transform.Transformer JavaDoc;
47 import javax.xml.transform.TransformerFactory JavaDoc;
48 import javax.xml.transform.dom.DOMSource JavaDoc;
49
50 import com.sun.japex.*;
51 import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
52 import org.w3c.dom.Document JavaDoc;
53
54
55
56 public class XercesXMLSerializerDriver extends JapexDriverBase {
57     String JavaDoc _xmlFile;
58     ByteArrayInputStream JavaDoc _inputStream;
59     Transformer JavaDoc _transformer;
60     DOMSource JavaDoc _source;
61     Document JavaDoc _d;
62     XMLSerializer _xmlSerializer;
63     ByteArrayOutputStream JavaDoc _baos;
64
65     public XercesXMLSerializerDriver() {
66     }
67     
68     public void initializeDriver() {
69         try {
70             _transformer = TransformerFactory.newInstance().newTransformer();
71         } catch (Exception JavaDoc e) {
72             e.printStackTrace();
73         }
74     }
75     
76     public void prepare(TestCase testCase) {
77         _xmlFile = testCase.getParam("xmlfile");
78         if (_xmlFile == null) {
79             throw new RuntimeException JavaDoc("xmlfile not specified");
80         }
81         
82         Util util = new Util();
83         _source = util.getDOMSource(new File JavaDoc(_xmlFile));
84         _d = (Document JavaDoc)_source.getNode();
85         _baos = new ByteArrayOutputStream JavaDoc();
86         _xmlSerializer = new XMLSerializer();
87         _xmlSerializer.setOutputByteStream(_baos);
88     }
89     
90     public void warmup(TestCase testCase) {
91         try {
92             _baos.reset();
93             _xmlSerializer.serialize(_d);
94         }
95         catch (Exception JavaDoc e) {
96             e.printStackTrace();
97         }
98     }
99     
100     public void run(TestCase testCase) {
101         try {
102             _baos.reset();
103             _xmlSerializer.serialize(_d);
104         }
105         catch (Exception JavaDoc e) {
106             e.printStackTrace();
107         }
108     }
109     
110     public void finish(TestCase testCase) {
111     }
112     
113     public void terminateDriver() {
114     }
115 }
116
Popular Tags