1 package parser; 2 40 41 import java.io.*; 42 import java.util.Properties ; 43 44 import com.sun.japex.*; 45 46 import org.xmlpull.v1.XmlPullParser; 47 import org.xmlpull.v1.XmlPullParserException; 48 import org.xmlpull.v1.XmlPullParserFactory; 49 50 public class XPP3Driver extends JapexDriverBase { 51 52 String _xmlFile; 53 byte[] _xmlFileByteArray; 54 ByteArrayInputStream _inputStream; 55 XmlPullParser _parser; 56 57 public XPP3Driver() { 58 } 59 60 public void initializeDriver() { 61 try { 62 XmlPullParserFactory factory = XmlPullParserFactory.newInstance( 63 System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); 64 factory.setNamespaceAware(true); 65 _parser = factory.newPullParser(); 66 } 67 catch (Exception e) { 68 e.printStackTrace(); 69 } 70 } 71 72 public void prepare(TestCase testCase) { 73 _xmlFile = testCase.getParam("xmlfile"); 74 if (_xmlFile == null) { 75 throw new RuntimeException ("xmlfile not specified"); 76 } 77 78 try { 80 FileInputStream fis = new FileInputStream(new File(_xmlFile)); 81 _xmlFileByteArray = com.sun.japex.Util.streamToByteArray(fis); 82 _inputStream = new ByteArrayInputStream(_xmlFileByteArray); 83 fis.close(); 84 } 85 catch (IOException e) { 86 e.printStackTrace(); 87 } 88 } 89 90 public void warmup(TestCase testCase) { 91 try { 92 _inputStream.reset(); 93 _parser.setInput(_inputStream, null); while (_parser.next() != XmlPullParser.END_DOCUMENT); 95 } 96 catch (Exception e) { 97 e.printStackTrace(); 98 } 99 } 100 101 public void run(TestCase testCase) { 102 try { 103 _inputStream.reset(); 104 _parser.setInput(_inputStream, null); while (_parser.next() != XmlPullParser.END_DOCUMENT); 106 } 107 catch (Exception e) { 108 e.printStackTrace(); 109 } 110 } 111 112 public void terminateDriver() { 113 } 114 } 115 | Popular Tags |