import java.io.*; import java.util.*; import java.io.IOException; import com.jclark.xml.parse.*; import com.jclark.xml.parse.io.Application; import com.jclark.xml.parse.io.Parser; import com.jclark.xml.parse.io.ParserImpl; //import com.jclark.xml.parse.EntityManagerImpl; //import com.jclark.xml.parse.OpenEntity; //import com.jclark.xml.parse.NotWellFormedException; /* * @author Aleksander Slominski [aslom@extreme.indiana.edu] */ public class JClarkXP implements Tester, Application { int count; String elementName; Parser parser; public JClarkXP() { } public void setUp(Properties props) throws Exception { parser = new ParserImpl(); parser.setApplication(this); } public TestResult testCount(String data, int runs, String elementName) throws Exception { this.elementName = elementName; char[] bufElementName = elementName.toCharArray(); int bufElementNameLen = bufElementName.length; //char[] buf = data.toCharArray(); String enc = "UTF-16"; //UTF8 byte[] buf = data.getBytes(enc); OpenEntity[] entities = new OpenEntity[runs]; for(int i = 0; i < runs ; ++i) { //EntityManagerImpl.openFile(); entities[i] = new OpenEntity( new ByteArrayInputStream(buf), enc, new java.net.URL("file:/tmp")); } count = -1; // start timing double start = TestTimer.tick(); for(int i = 0; i < runs ; ++i) { count = 0; //try { parser.parseDocument(entities[i]); //} //catch (NotWellFormedException e) { // System.err.println(e.getMessage()); //} } double end = TestTimer.tick(); TestResult result = new TestResult(); result.elementCount = count; result.timeSecs = (end - start) / runs; return result; } // -- Application interface public void startElement(StartElementEvent event) throws IOException { //System.err.println("el name ="+event.getName()); if(elementName.equals(event.getName())) ++count; int nAtts = event.getAttributeCount(); for (int i = 0; i < nAtts; i++) { String s1 = event.getAttributeName(i); String s2 = event.getAttributeValue(i); } } public void startDocument() throws IOException { } public void endDocument() throws IOException { } public void characterData(CharacterDataEvent event) throws IOException { } public void endElement(EndElementEvent event) throws IOException { } public void processingInstruction(ProcessingInstructionEvent pi) throws IOException { } public void endProlog(EndPrologEvent event) throws IOException { } public void comment(CommentEvent event) throws IOException { } public void startCdataSection(StartCdataSectionEvent event) throws IOException { } public void endCdataSection(EndCdataSectionEvent event) throws IOException { } public void startEntityReference(StartEntityReferenceEvent event) throws IOException { } public void endEntityReference(EndEntityReferenceEvent event) throws IOException { } public void startDocumentTypeDeclaration(StartDocumentTypeDeclarationEvent event) throws IOException { } public void endDocumentTypeDeclaration(EndDocumentTypeDeclarationEvent event) throws IOException { } public void markupDeclaration(MarkupDeclarationEvent event) throws IOException { } }