1 package parser.sax; 2 40 41 import java.io.*; 42 import javax.xml.parsers.*; 43 import java.util.Properties ; 44 45 import com.sun.japex.*; 46 47 public class JAXPDriver extends JapexDriverBase { 48 49 String _xmlFile; 50 byte[] _xmlFileByteArray; 51 ByteArrayInputStream _inputStream; 52 SAXParser _parser; 53 54 public JAXPDriver() { 55 } 56 57 public void initializeDriver() { 58 try { 59 SAXParserFactory spf = SAXParserFactory.newInstance(); 60 spf.setNamespaceAware(true); 61 _parser = spf.newSAXParser(); 62 } 63 catch (Exception e) { 64 e.printStackTrace(); 65 } 66 } 67 68 public void prepare(TestCase testCase) { 69 _xmlFile = testCase.getParam("xmlfile"); 70 if (_xmlFile == null) { 71 throw new RuntimeException ("xmlfile not specified"); 72 } 73 74 try { 76 FileInputStream fis = new FileInputStream(new File(_xmlFile)); 78 _xmlFileByteArray = com.sun.japex.Util.streamToByteArray(fis); 79 _inputStream = new ByteArrayInputStream(_xmlFileByteArray); 80 fis.close(); 81 } 82 catch (IOException e) { 83 e.printStackTrace(); 84 } 85 } 86 87 public void warmup(TestCase testCase) { 88 try { 89 _inputStream.reset(); 90 _parser.parse(_inputStream, 91 new org.xml.sax.helpers.DefaultHandler ()); 92 } 93 catch (Exception e) { 94 e.printStackTrace(); 95 } 96 } 97 98 public void run(TestCase testCase) { 99 try { 100 _inputStream.reset(); 101 _parser.parse(_inputStream, 102 new org.xml.sax.helpers.DefaultHandler ()); 103 } 104 catch (Exception e) { 105 e.printStackTrace(); 106 } 107 } 108 109 public void terminateDriver() { 110 } 111 } 112 | Popular Tags |