bzr branch
http://darksoft.org/webbzr/xmlbench/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
import java.io.*; |
2 |
import java.util.*; |
|
3 |
import java.text.*; |
|
4 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
5 |
import javax.xml.parsers.DocumentBuilder; |
|
6 |
||
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
7 |
import javax.xml.transform.Source; |
8 |
import javax.xml.transform.stream.StreamSource; |
|
9 |
import javax.xml.transform.dom.DOMSource; |
|
10 |
import javax.xml.XMLConstants; |
|
11 |
import javax.xml.validation.SchemaFactory; |
|
12 |
import javax.xml.validation.Schema; |
|
13 |
import javax.xml.validation.Validator; |
|
14 |
||
15 |
import org.w3c.dom.Document; |
|
16 |
||
1
by Suren A. Chilingaryan
Initial import |
17 |
public class sun_dom2 extends bench { |
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
18 |
SchemaFactory schemaFactory; |
19 |
Schema schema; |
|
20 |
Validator validator; |
|
21 |
||
1
by Suren A. Chilingaryan
Initial import |
22 |
DocumentBuilderFactory factory; |
23 |
DocumentBuilder parser; |
|
24 |
final String JAXP_SS="http://java.sun.com/xml/jaxp/properties/schemaSource"; |
|
25 |
final String JAXP_SL="http://java.sun.com/xml/jaxp/properties/schemaLanguage"; |
|
26 |
final String W3C_Schema="http://www.w3.org/2001/XMLSchema"; |
|
27 |
||
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
28 |
public void InitXML(boolean large_data) { |
1
by Suren A. Chilingaryan
Initial import |
29 |
factory = DocumentBuilderFactory.newInstance(); |
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
30 |
factory.setNamespaceAware(true); |
1
by Suren A. Chilingaryan
Initial import |
31 |
factory.setValidating(false); |
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
32 |
|
33 |
try { |
|
34 |
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); |
|
35 |
} catch (Throwable err) { |
|
36 |
// ignoring missing option
|
|
37 |
}
|
|
38 |
||
1
by Suren A. Chilingaryan
Initial import |
39 |
try { |
40 |
parser = factory.newDocumentBuilder(); |
|
41 |
}
|
|
42 |
catch (Throwable err) { |
|
43 |
err.printStackTrace (); |
|
44 |
return; |
|
45 |
}
|
|
46 |
||
47 |
}
|
|
48 |
||
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
49 |
public void InitXML_Validation(String schema_file) { |
1
by Suren A. Chilingaryan
Initial import |
50 |
factory = DocumentBuilderFactory.newInstance(); |
51 |
factory.setNamespaceAware(true); |
|
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
52 |
|
53 |
factory.setValidating(false); |
|
54 |
||
55 |
try { |
|
56 |
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); |
|
57 |
} catch (Throwable err) { |
|
58 |
// ignoring missing option
|
|
59 |
}
|
|
60 |
||
61 |
/*
|
|
1
by Suren A. Chilingaryan
Initial import |
62 |
factory.setValidating(true);
|
63 |
try {
|
|
64 |
factory.setAttribute(JAXP_SL,W3C_Schema);
|
|
65 |
}
|
|
66 |
catch (IllegalArgumentException x) {
|
|
67 |
System.out.println("JAXP 1.2 Unsupported!");
|
|
68 |
}
|
|
69 |
||
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
70 |
*/
|
1
by Suren A. Chilingaryan
Initial import |
71 |
// factory.setAttribute(JAXP_SS,new File("test.xsd"));
|
72 |
try { |
|
73 |
parser = factory.newDocumentBuilder(); |
|
74 |
}
|
|
75 |
catch (Throwable err) { |
|
76 |
err.printStackTrace (); |
|
77 |
return; |
|
78 |
}
|
|
79 |
||
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
80 |
|
81 |
Source schemaSource = new StreamSource(schema_file); |
|
82 |
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
|
83 |
||
84 |
try { |
|
85 |
schema = schemaFactory.newSchema(schemaSource); |
|
86 |
validator = schema.newValidator(); |
|
87 |
} catch (Throwable err) { |
|
88 |
err.printStackTrace (); |
|
89 |
return; |
|
90 |
}
|
|
91 |
||
92 |
/*
|
|
93 |
import org.apache.xerces.parsers.XMLGrammarPreparser;
|
|
94 |
import org.apache.xerces.xni.grammars.XMLGrammarPool;
|
|
95 |
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
|
|
96 |
||
97 |
XMLGrammarPreparser preparser = new XMLGrammarPreparser();
|
|
98 |
preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
|
|
99 |
XMLGrammarPool grammarPool = new XMLGrammarPool();
|
|
100 |
preparser.setProperty(GRAMMAR_POOL, grammarPool);
|
|
101 |
preparser.setFeature(NAMESPACES_FEATURE_ID, true);
|
|
102 |
preparser.setFeature(VALIDATION_FEATURE_ID, true);
|
|
103 |
|
|
104 |
Grammar g = preparser.preparseGrammar(MLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, schema_file, null));
|
|
105 |
||
106 |
parser =
|
|
107 |
*/
|
|
1
by Suren A. Chilingaryan
Initial import |
108 |
}
|
109 |
||
110 |
||
111 |
public void ParseXML(FileInputStream is, int iters, int iter) { |
|
112 |
try { |
|
113 |
parser.parse(is); |
|
114 |
}
|
|
115 |
catch (Exception e) |
|
116 |
{
|
|
117 |
System.out.println(e.toString()); |
|
118 |
}
|
|
119 |
}
|
|
120 |
||
121 |
public void ValidateXML(FileInputStream is, int iters, int iter) { |
|
122 |
try { |
|
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
123 |
Document doc = parser.parse(is); |
124 |
validator.validate(new DOMSource(doc)); |
|
1
by Suren A. Chilingaryan
Initial import |
125 |
}
|
126 |
catch (Exception e) |
|
127 |
{
|
|
128 |
System.out.println(e.toString()); |
|
129 |
}
|
|
130 |
}
|
|
131 |
||
132 |
static public void main(String argv[]) throws IOException { |
|
133 |
bench mybench = new sun_dom2(); |
|
134 |
mybench.Bench(argv); |
|
135 |
}
|
|
136 |
}
|