/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.String;
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.parsers.DocumentBuilder; 
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

/*
    Code differs depending on XML Pack used or not!
    Defaults to use with XML Pack!
    For details see forward!
*/


public class sun_dom2 extends bench {
    DocumentBuilderFactory factory;
    DocumentBuilder parser;
    Random generator;
    String nsxsi="http://www.w3.org/2001/XMLSchema-instance";
    String nsenc="http://www.w3.org/2001/12/soap-encoding";
    String nssoap="http://www.w3.org/2001/12/soap-envelope";
    String nsopc="http://opcfoundation.org/webservices/OPCDA/";

    public void InitXML(int enlarge) {
	    factory = DocumentBuilderFactory.newInstance();
	    try {
    		parser = factory.newDocumentBuilder();
	    }
	    catch (Throwable err) {
    		err.printStackTrace ();
	    }
	    if (enlarge>0) generator = new Random();
    }

    public void ParseXML(int enlarge, int iters, int iter) {
	Document doc;
	Element proot,pnode,node,node1,node2;
	String mem="";
	int i;
	
	try {
	    doc = parser.newDocument();
	    proot = doc.createElementNS(nssoap,"Envelope");
	    proot.setAttribute("xmlns",nssoap);
	    proot.setAttribute("xmlns:xsi",nsxsi);
	    proot.setAttribute("xmlns:enc",nsenc);
	    doc.appendChild(proot);
	    pnode = doc.createElementNS(nssoap,"Body");
	    proot.appendChild(pnode);

    node=doc.createElementNS(nsopc,"WriteResponse");
    pnode.appendChild(node);pnode=node;
    node=doc.createElementNS(nsopc,"WriteResult");
    node.setAttribute("RcvTime","2002-04-29T10:16:26.6806250+02:00");
    node.setAttribute("ReplyTime","2002-04-29T10:16:26.7806250+02:00");
    node.setAttribute("ClientRequestHandle","WriteError");
    node.setAttribute("RevisedLocaleID","en");
    node.setAttribute("ServerState","running");
    pnode.appendChild(node);
    node1=doc.createElementNS(nsopc,"RItemList");
    node.appendChild(node1);
    node=doc.createElementNS(nsopc,"Errors");
    node.setAttribute("ID","E_UNKNOWNITEMID");
    pnode.appendChild(node);
    node2=doc.createElementNS(nsopc,"Text");
    node.appendChild(node2);    
    node2.appendChild(doc.createTextNode("The item does not exist in the server address space."));
    node=doc.createElementNS(nsopc,"Errors");
    node.setAttribute("ID","S_CLAMP");
    pnode.appendChild(node);
    node2=doc.createElementNS(nsopc,"Text");
    node.appendChild(node2);    
    node2.appendChild(doc.createTextNode("The value written was accepted but the output was clamped."));

    pnode=node1;
    node=doc.createElementNS(nsopc,"Items");
    node.setAttribute("ItemPath","");
    node.setAttribute("ItemName","WrongItemID1");
    node.setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
    node.setAttribute("ErrorID","E_UNKNOWNITEMID");
    pnode.appendChild(node);
    node1=doc.createElementNS(nsopc,"Value");
    node.appendChild(node1);
    node.setAttribute("xsi:nil","true");

    node=doc.createElementNS(nsopc,"Items");
    node.setAttribute("ItemPath","");
    node.setAttribute("ItemName","WrongItemID2");
    node.setAttribute("Timestamp","0001-01-01T00:00:00.0000000+01:00");
    node.setAttribute("ErrorID","E_UNKNOWNITEMID");
    pnode.appendChild(node);
    node1=doc.createElementNS(nsopc,"Value");
    node.appendChild(node1);
    node.setAttribute("xsi:nil","true");

    node=doc.createElementNS(nsopc,"Items");
    node.setAttribute("ItemPath","/Reals");
    node.setAttribute("ItemName","Float1");
    node.setAttribute("ValueType","xsd:float");
    node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
    pnode.appendChild(node);
    node1=doc.createElementNS(nsopc,"Value");
    node.appendChild(node1);
    node.setAttribute("xsi:type","xsd:float");
    node1.appendChild(doc.createTextNode("10.0141414"));

    node=doc.createElementNS(nsopc,"Items");
    node.setAttribute("ItemPath","/Reals");
    node.setAttribute("ItemName","Float2");
    node.setAttribute("ValueType","xsd:float");
    node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
    node.setAttribute("SuccessID","S_CLAMP");
    pnode.appendChild(node);
    node1=doc.createElementNS(nsopc,"Value");
    node.appendChild(node1);
    node.setAttribute("xsi:type","xsd:float");
    node1.appendChild(doc.createTextNode("1.07"));
    
    for (i=0;i<enlarge;i++) {
        node=doc.createElementNS(nsopc,"Items");
	node.setAttribute("ItemPath","/Integer");
        node.setAttribute("ItemName","IntN");
	node.setAttribute("ValueType","xsd:int");
        node.setAttribute("Timestamp","2002-04-29T11:47:18.1493750+02:00");
        node.setAttribute("SuccessID","S_CLAMP");
	pnode.appendChild(node);
        node1=doc.createElementNS(nsopc,"Value");
	node.appendChild(node1);
	node1.setAttribute("xsi:type","xsd:int");
        node1.appendChild(doc.createTextNode(Integer.toString(generator.nextInt())));
    }

	// Use this in case of pure J2SE 1.4 used (without XML Pack - Crismon parser)
	    //mem=proot.toString();

	// Use this in case of J2SE 1.4 + XML Pack used (Xerces parser)
	    //org.apache.xerces.dom3.ls.DOMWriter dw = new org.apache.xml.serialize.XMLSerializer();
	    //mem = dw.writeToString(doc);

	// Use this in case of J2SE 1.4 + Java WebService Developer Pack 1.2
	    java.io.StringWriter sw = new StringWriter();
	    org.apache.xml.serialize.XMLSerializer dw = new org.apache.xml.serialize.XMLSerializer(sw,null);
	    dw.serialize(doc);
	    dw.asDOMSerializer();
	    mem = sw.toString();
	}
	catch (Exception e)
	{
    	    System.out.println(e.toString());
	}

//	if (iter==iters) System.out.println(mem);
    }
    

    static public void main(String argv[]) throws IOException {
	bench mybench = new sun_dom2();
	mybench.Bench(argv);
    }
}