/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
import java.io.*;
import java.util.*;
import java.text.*;
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.parsers.DocumentBuilder; 

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;

import org.w3c.dom.Document;

public class sun_dom2 extends bench {
    SchemaFactory schemaFactory;
    Schema schema;
    Validator validator;

    DocumentBuilderFactory factory;
    DocumentBuilder parser;
    final String JAXP_SS="http://java.sun.com/xml/jaxp/properties/schemaSource";
    final String JAXP_SL="http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    final String W3C_Schema="http://www.w3.org/2001/XMLSchema";
    
    public void InitXML(boolean large_data) {
	    factory = DocumentBuilderFactory.newInstance();
	    factory.setNamespaceAware(true);
	    factory.setValidating(false);

	    try {
		factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
	    } catch (Throwable err) {
		// ignoring missing option
    	    }

	    try {
    		parser = factory.newDocumentBuilder();
	    }
	    catch (Throwable err) {
    		err.printStackTrace ();
		return;
	    }

    }
    
    public void InitXML_Validation(String schema_file) {
	    factory = DocumentBuilderFactory.newInstance();
	    factory.setNamespaceAware(true);

	    factory.setValidating(false);

	    try {
		factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
	    } catch (Throwable err) {
		// ignoring missing option
    	    }

/*
	    factory.setValidating(true);
	    try {
		factory.setAttribute(JAXP_SL,W3C_Schema);
	    }
	    catch (IllegalArgumentException x) {
		System.out.println("JAXP 1.2 Unsupported!");
	    }

*/
//	    factory.setAttribute(JAXP_SS,new File("test.xsd"));
	    try {
    		parser = factory.newDocumentBuilder();
	    }
	    catch (Throwable err) {
    		err.printStackTrace ();
		return;
	    }


	    Source schemaSource = new StreamSource(schema_file);
	    schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

	    try {
		schema = schemaFactory.newSchema(schemaSource);
	        validator = schema.newValidator();
	    } catch (Throwable err) {
    		err.printStackTrace ();
		return;
	    }

/*
import org.apache.xerces.parsers.XMLGrammarPreparser;
import org.apache.xerces.xni.grammars.XMLGrammarPool;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;

	    XMLGrammarPreparser preparser = new XMLGrammarPreparser();
	    preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
	    XMLGrammarPool grammarPool = new XMLGrammarPool();
	    preparser.setProperty(GRAMMAR_POOL, grammarPool);
	    preparser.setFeature(NAMESPACES_FEATURE_ID, true);
	    preparser.setFeature(VALIDATION_FEATURE_ID, true);
	    
	    Grammar g = preparser.preparseGrammar(MLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, schema_file, null));

	    parser = 	    
*/
    }

    
    public void ParseXML(FileInputStream is, int iters, int iter) {
	try {
	    parser.parse(is);		
	}
	catch (Exception e)
        {
    	    System.out.println(e.toString());
        }
    }

    public void ValidateXML(FileInputStream is, int iters, int iter) {
	try {
	    Document doc = parser.parse(is);		
	    validator.validate(new DOMSource(doc));
	}
	catch (Exception e)
        {
    	    System.out.println(e.toString());
        }
    }
    
    static public void main(String argv[]) throws IOException {
	bench mybench = new sun_dom2();
	mybench.Bench(argv);
    }
}