1 package parser.stax; 2 40 41 import java.io.*; 42 import javax.xml.stream.*; 43 import java.util.Properties ; 44 45 import com.sun.japex.*; 46 47 public class StAXRIDriver extends JapexDriverBase { 48 49 String _xmlFile; 50 byte[] _xmlFileByteArray; 51 ByteArrayInputStream _inputStream; 52 XMLInputFactory _factory; 53 XMLStreamReader _reader; 54 55 public StAXRIDriver() { 56 } 57 58 public void initializeDriver() { 59 try { 60 _factory = new com.bea.xml.stream.MXParserFactory(); 61 } 62 catch (Exception e) { 63 e.printStackTrace(); 64 } 65 } 66 67 public void prepare(TestCase testCase) { 68 _xmlFile = testCase.getParam("xmlfile"); 69 if (_xmlFile == null) { 70 throw new RuntimeException ("xmlfile not specified"); 71 } 72 73 try { 75 FileInputStream fis = new FileInputStream(new File(_xmlFile)); 77 _xmlFileByteArray = com.sun.japex.Util.streamToByteArray(fis); 78 _inputStream = new ByteArrayInputStream(_xmlFileByteArray); 79 fis.close(); 80 } 81 catch (IOException e) { 82 e.printStackTrace(); 83 } 84 } 85 86 public void warmup(TestCase testCase) { 87 try { 88 _inputStream.reset(); 89 _reader = _factory.createXMLStreamReader(_inputStream); 90 while (_reader.hasNext()) { 91 _reader.next(); 92 } 93 } 94 catch (Exception e) { 95 e.printStackTrace(); 96 } 97 } 98 99 public void run(TestCase testCase) { 100 try { 101 _inputStream.reset(); 102 _reader = _factory.createXMLStreamReader(_inputStream); 103 while (_reader.hasNext()) { 104 _reader.next(); 105 } 106 } 107 catch (Exception e) { 108 e.printStackTrace(); 109 } 110 } 111 112 public void terminateDriver() { 113 } 114 } 115 | Popular Tags |