/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/sun_dom2.java

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

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