1 39 40 package serializer.dom; 41 42 import java.io.File ; 43 import java.io.ByteArrayInputStream ; 44 import java.io.ByteArrayOutputStream ; 45 46 import javax.xml.transform.Transformer ; 47 import javax.xml.transform.TransformerFactory ; 48 import javax.xml.transform.dom.DOMSource ; 49 50 import com.sun.japex.*; 51 import com.sun.xml.fastinfoset.dom.DOMDocumentSerializer; 52 import org.w3c.dom.Document ; 53 54 55 56 public class FIDOMDriver extends JapexDriverBase { 57 String _xmlFile; 58 ByteArrayInputStream _inputStream; 59 Transformer _transformer; 60 DOMSource _source; 61 Document _d; 62 protected DOMDocumentSerializer _serializer; 63 ByteArrayOutputStream _baos; 64 65 public FIDOMDriver() { 66 } 67 68 public void initializeDriver() { 69 try { 70 _transformer = TransformerFactory.newInstance().newTransformer(); 71 } catch (Exception 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 ("xmlfile not specified"); 80 } 81 82 Util util = new Util(); 83 _source = util.getDOMSource(new File (_xmlFile)); 84 _d = (Document )_source.getNode(); 85 _baos = new ByteArrayOutputStream (); 86 _serializer = new DOMDocumentSerializer(); 87 _serializer.setOutputStream(_baos); 88 } 89 90 public void warmup(TestCase testCase) { 91 try { 92 _baos.reset(); 93 _serializer.serialize(_d); 94 } 95 catch (Exception e) { 96 e.printStackTrace(); 97 } 98 } 99 100 public void run(TestCase testCase) { 101 try { 102 _baos.reset(); 103 _serializer.serialize(_d); 104 } 105 catch (Exception e) { 106 e.printStackTrace(); 107 } 108 } 109 110 public void finish(TestCase testCase) { 111 } 112 113 public void terminateDriver() { 114 } 115 } 116 | Popular Tags |