KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > test > xmlrpc > PerfTest


1 /* ****************************************************************************
2  * PerfTest.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.test.xmlrpc;
11
12 import java.util.*;
13 import java.io.*;
14 import javax.xml.rpc.*;
15 import javax.xml.parsers.*;
16 import javax.xml.namespace.*;
17 import org.w3c.dom.*;
18 import org.xml.sax.*;
19 import org.apache.axis.Constants;
20 import org.apache.axis.utils.*;
21 import org.apache.log4j.Logger;
22
23 class PerfDataParser
24 {
25     DocumentBuilder mBuilder;
26
27     public PerfDataParser() throws ParserConfigurationException
28     {
29         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
30         mBuilder = factory.newDocumentBuilder();
31     }
32     
33     
34     public Map parse(String JavaDoc file)
35         throws IOException, SAXException {
36
37         Map map = new HashMap();
38
39         Element root = mBuilder.parse(new InputSource(new FileReader(file))).getDocumentElement();
40         NodeList children = root.getChildNodes();
41         for (int i=0; i < children.getLength(); i++) {
42             Node node = children.item(i);
43             if (node.getNodeType() != Node.ELEMENT_NODE) continue;
44             Map item = new HashMap();
45             NamedNodeMap attributes = ((Element)node).getAttributes();
46             for (int j=0; j < attributes.getLength(); j++) {
47                 Attr attr = (Attr)attributes.item(j);
48                 item.put(attr.getName(), attr.getValue());
49             }
50             map.put(item.get("id"), item);
51         }
52
53         return map;
54     }
55 }
56
57
58 public class PerfTest
59 {
60     static String JavaDoc PERF_DATA_DIR = "/home/pkang/perforce/qa/testharness/docroot/perf-data";
61
62     static Map addrMap = new HashMap();
63
64     static {
65         try {
66             PerfDataParser p = new PerfDataParser();
67             addrMap.put(new Integer JavaDoc(0), p.parse(PERF_DATA_DIR + "/0k.xml"));
68             addrMap.put(new Integer JavaDoc(1), p.parse(PERF_DATA_DIR + "/1k.xml"));
69             addrMap.put(new Integer JavaDoc(10), p.parse(PERF_DATA_DIR + "/10k.xml"));
70             addrMap.put(new Integer JavaDoc(25), p.parse(PERF_DATA_DIR + "/25k.xml"));
71         } catch (Exception JavaDoc e) {
72             e.printStackTrace();
73         }
74     }
75     
76     public static Map getAddresses(int k) {
77         return (Map)addrMap.get(new Integer JavaDoc(k));
78     }
79 }
80
Popular Tags