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 FIStAXDriver 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 FIStAXDriver() { 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 boolean FISTAXFactory = true; 87 Util util = new Util(Util.STAX_SERIALIZER_FI); 88 _source = util.getDOMSource(new File (_xmlFile)); 89 _baos = new ByteArrayOutputStream (); 90 _result = util.getSAXResult(_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 |