/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 create/intel_dom2.java

  • Committer: Suren A. Chilingaryan
  • Date: 2009-09-23 17:13:04 UTC
  • Revision ID: csa@dside.dyndns.org-20090923171304-osvtr4zqb29h11kd
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import java.io.*;
 
2
import java.util.*;
 
3
import java.text.*;
 
4
import java.lang.String;
 
5
import javax.xml.parsers.DocumentBuilderFactory; 
 
6
import javax.xml.parsers.DocumentBuilder; 
 
7
import org.w3c.dom.Document;
 
8
import org.w3c.dom.Node;
 
9
import org.w3c.dom.Element;
 
10
 
 
11
import javax.xml.transform.Transformer;
 
12
import javax.xml.transform.TransformerFactory;
 
13
import javax.xml.transform.dom.DOMSource;
 
14
import javax.xml.transform.stream.StreamResult;
 
15
 
 
16
/*
 
17
    Code differs depending on XML Pack used or not!
 
18
    Defaults to use with XML Pack!
 
19
    For details see forward!
 
20
*/
 
21
 
 
22
 
 
23
public class intel_dom2 extends bench {
 
24
    DocumentBuilderFactory factory;
 
25
    DocumentBuilder parser;
 
26
    Transformer serializer;
 
27
    Random generator;
 
28
    String nsxsi="http://www.w3.org/2001/XMLSchema-instance";
 
29
    String nsenc="http://www.w3.org/2001/12/soap-encoding";
 
30
    String nssoap="http://www.w3.org/2001/12/soap-envelope";
 
31
    String nsopc="http://opcfoundation.org/webservices/OPCDA/";
 
32
 
 
33
    public void InitXML(int enlarge) {
 
34
            factory = DocumentBuilderFactory.newInstance();
 
35
            try {
 
36
                parser = factory.newDocumentBuilder();
 
37
                
 
38
                TransformerFactory tf = TransformerFactory.newInstance();
 
39
                serializer = tf.newTransformer();
 
40
            }
 
41
            catch (Throwable err) {
 
42
                err.printStackTrace ();
 
43
            }
 
44
            if (enlarge>0) generator = new Random();
 
45
 
 
46
 
 
47
    }
 
48
 
 
49
    public void ParseXML(int enlarge, int iters, int iter) {
 
50
        Document doc;
 
51
        Element proot,pnode,node,node1,node2;
 
52
        String mem="";
 
53
        int i;
 
54
        
 
55
        try {
 
56
            doc = parser.newDocument();
 
57
            proot = doc.createElementNS(nssoap,"Envelope");
 
58
            proot.setAttribute("xmlns",nssoap);
 
59
            proot.setAttribute("xmlns:xsi",nsxsi);
 
60
            proot.setAttribute("xmlns:enc",nsenc);
 
61
            doc.appendChild(proot);
 
62
            pnode = doc.createElementNS(nssoap,"Body");
 
63
            proot.appendChild(pnode);
 
64
 
 
65
    node=doc.createElementNS(nsopc,"WriteResponse");
 
66
    pnode.appendChild(node);pnode=node;
 
67
    node=doc.createElementNS(nsopc,"WriteResult");
 
68
    node.setAttribute("RcvTime","2002-04-29T10:16:26.6806250+02:00");
 
69
    node.setAttribute("ReplyTime","2002-04-29T10:16:26.7806250+02:00");
 
70
    node.setAttribute("ClientRequestHandle","WriteError");
 
71
    node.setAttribute("RevisedLocaleID","en");
 
72
    node.setAttribute("ServerState","running");
 
73
    pnode.appendChild(node);
 
74
    node1=doc.createElementNS(nsopc,"RItemList");
 
75
    pnode.appendChild(node1);
 
76
    node=doc.createElementNS(nsopc,"Errors");
 
77
    node.setAttribute("ID","E_UNKNOWNITEMID");
 
78
    pnode.appendChild(node);
 
79
    node2=doc.createElementNS(nsopc,"Text");
 
80
    node.appendChild(node2);    
 
81
    node2.appendChild(doc.createTextNode("The item does not exist in the server address space."));
 
82
    node=doc.createElementNS(nsopc,"Errors");
 
83
    node.setAttribute("ID","S_CLAMP");
 
84
    pnode.appendChild(node);
 
85
    node2=doc.createElementNS(nsopc,"Text");
 
86
    node.appendChild(node2);    
 
87
    node2.appendChild(doc.createTextNode("The value written was accepted but the output was clamped."));
 
88
 
 
89
    pnode=node1;
 
90
    node=doc.createElementNS(nsopc,"Items");
 
91
    node.setAttribute("ItemPath","");
 
92
    node.setAttribute("ItemName","WrongItemID1");
 
93
    node.setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
 
94
    node.setAttribute("ErrorID","E_UNKNOWNITEMID");
 
95
    pnode.appendChild(node);
 
96
    node1=doc.createElementNS(nsopc,"Value");
 
97
    node.appendChild(node1);
 
98
    node.setAttribute("xsi:nil","true");
 
99
 
 
100
    node=doc.createElementNS(nsopc,"Items");
 
101
    node.setAttribute("ItemPath","");
 
102
    node.setAttribute("ItemName","WrongItemID2");
 
103
    node.setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
 
104
    node.setAttribute("ErrorID","E_UNKNOWNITEMID");
 
105
    pnode.appendChild(node);
 
106
    node1=doc.createElementNS(nsopc,"Value");
 
107
    node.appendChild(node1);
 
108
    node.setAttribute("xsi:nil","true");
 
109
 
 
110
    node=doc.createElementNS(nsopc,"Items");
 
111
    node.setAttribute("ItemPath","/Reals");
 
112
    node.setAttribute("ItemName","Float1");
 
113
    node.setAttribute("ValueType","xsd:float");
 
114
    node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
 
115
    pnode.appendChild(node);
 
116
    node1=doc.createElementNS(nsopc,"Value");
 
117
    node.appendChild(node1);
 
118
    node.setAttribute("xsi:type","xsd:float");
 
119
    node1.appendChild(doc.createTextNode("10.0141414"));
 
120
 
 
121
    node=doc.createElementNS(nsopc,"Items");
 
122
    node.setAttribute("ItemPath","/Reals");
 
123
    node.setAttribute("ItemName","Float2");
 
124
    node.setAttribute("ValueType","xsd:float");
 
125
    node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
 
126
    node.setAttribute("SuccessID","S_CLAMP");
 
127
    pnode.appendChild(node);
 
128
    node1=doc.createElementNS(nsopc,"Value");
 
129
    node.appendChild(node1);
 
130
    node.setAttribute("xsi:type","xsd:float");
 
131
    node1.appendChild(doc.createTextNode("1.07"));
 
132
    
 
133
    for (i=0;i<enlarge;i++) {
 
134
        node=doc.createElementNS(nsopc,"Items");
 
135
        node.setAttribute("ItemPath","/Integer");
 
136
        node.setAttribute("ItemName","IntN");
 
137
        node.setAttribute("ValueType","xsd:int");
 
138
        node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
 
139
        node.setAttribute("SuccessID","S_CLAMP");
 
140
        pnode.appendChild(node);
 
141
 
 
142
        node1=doc.createElementNS(nsopc,"Value");
 
143
        node.appendChild(node1);
 
144
        node1.setAttribute("xsi:type","xsd:int");
 
145
        node1.appendChild(doc.createTextNode(Integer.toString(generator.nextInt())));
 
146
    }
 
147
 
 
148
 
 
149
            java.io.StringWriter sw = new StringWriter();
 
150
            StreamResult result = new StreamResult(sw);
 
151
            serializer.transform(new DOMSource(doc), result);
 
152
            mem = sw.toString();
 
153
 
 
154
 
 
155
        }
 
156
        catch (Exception e)
 
157
        {
 
158
            System.out.println(e.toString());
 
159
        }
 
160
 
 
161
//      if (iter==iters) System.out.println(mem);
 
162
    }
 
163
    
 
164
 
 
165
    static public void main(String argv[]) throws IOException {
 
166
        bench mybench = new intel_dom2();
 
167
        mybench.Bench(argv);
 
168
    }
 
169
}
 
 
b'\\ No newline at end of file'