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