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