/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/intel_dom2.java

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-01 16:30:16 UTC
  • Revision ID: csa@dside.dyndns.org-20091001163016-qum8v7u9726vfwi8
DOM Walking for deferred mode parsers

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import javax.xml.parsers.DocumentBuilder; 
6
6
 
7
7
import org.w3c.dom.Document;
 
8
import org.w3c.dom.NamedNodeMap;
 
9
import org.w3c.dom.Node;
 
10
import org.w3c.dom.Text;
 
11
import java.lang.Float;
8
12
 
9
13
public class intel_dom2 extends bench {
10
 
 
11
 
    DocumentBuilder parser;
12
 
    DocumentBuilderFactory factory;
13
 
    
14
 
    public void InitXML() {
 
14
 int walk_mode;
 
15
 DocumentBuilder parser;
 
16
 DocumentBuilderFactory factory;
 
17
    
 
18
 double walker_process_node(Node cur_node) {
 
19
    double res;
 
20
    Node child;
 
21
    
 
22
    child = cur_node.getFirstChild();
 
23
    if ((child!=null)&&(child.getNodeType() == Node.TEXT_NODE)) {
 
24
        try {
 
25
            res = Float.parseFloat(child.getNodeValue());
 
26
            if (res!=0) return res;
 
27
        } catch(Exception e) {
 
28
        }
 
29
    } 
 
30
 
 
31
    NamedNodeMap attrMap = cur_node.getAttributes();
 
32
    int length = attrMap.getLength();
 
33
 
 
34
    for (int i = 0; i < length; i++) {
 
35
        try {
 
36
            res = Float.parseFloat(attrMap.item(i).getNodeValue());
 
37
            if (res!=0) return res;
 
38
        } catch (Exception e) {
 
39
        }
 
40
    }
 
41
 
 
42
    return 0;
 
43
 }
 
44
 
 
45
 
 
46
 double walker(Node node) {
 
47
    int i = 0;
 
48
    double res = 0;
 
49
    Node cur_node;
 
50
 
 
51
    for (cur_node = node; cur_node!=null; cur_node = cur_node.getNextSibling()) {
 
52
        if((cur_node.getNodeType() == Node.ELEMENT_NODE)&&(++i>3)) break;
 
53
    }
 
54
    
 
55
    if (i<=3) i = 0;
 
56
 
 
57
    for (cur_node = node; cur_node!=null; cur_node = cur_node.getNextSibling()) {
 
58
        if (cur_node.getNodeType() == Node.ELEMENT_NODE) {
 
59
            if (i>0) {
 
60
                res += walker_process_node(cur_node);
 
61
            }
 
62
            res+=walker(cur_node.getFirstChild());
 
63
        }
 
64
    }
 
65
    return res;
 
66
 }
 
67
 
 
68
 
 
69
 public void InitXML() {
15
70
        factory = DocumentBuilderFactory.newInstance();
16
71
        factory.setNamespaceAware(true);
17
72
        factory.setValidating(false);
18
73
        try {
19
 
            if (System.getenv("memory_bench")!=null) {
 
74
//          if (System.getenv("memory_bench")!=null) {
 
75
            if (System.getenv("allow_deferring")!=null) {
20
76
                factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
21
77
            } else {
22
78
                factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
23
79
            }
 
80
 
 
81
            if (System.getenv("walk_tree")!=null) {
 
82
                walk_mode = 1;
 
83
            } else {
 
84
                walk_mode = 0;
 
85
            }
24
86
        } catch (Throwable err) {
25
87
            // ignoring missing option
26
88
        }
31
93
        catch (Throwable err) {
32
94
            err.printStackTrace ();
33
95
        }
34
 
    }
 
96
 }
35
97
 
36
 
    public void ParseXML(FileInputStream is, int iters, int iter) {
 
98
 public void ParseXML(FileInputStream is, int iters, int iter) {
37
99
        try {
38
100
            Document doc = parser.parse(is);            
 
101
            if (walk_mode!=0) {
 
102
                double res = walker(doc.getFirstChild());
 
103
//              System.out.println("Sum: " + res);
 
104
            }           
39
105
        }
40
106
        catch (Exception e)
41
107
        {
42
108
            System.out.println(e.toString());
43
109
        }
44
 
    }
 
110
 }
45
111
  
46
 
    static public void main(String argv[]) throws IOException {
 
112
 static public void main(String argv[]) throws IOException {
47
113
        bench mybench = new intel_dom2();
48
114
        mybench.Bench(argv);
49
 
    }
 
115
 }
50
116
}