1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package validation;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29
30 import javax.xml.parsers.ParserConfigurationException;
31 import javax.xml.parsers.SAXParserFactory;
32 import javax.xml.transform.stream.StreamSource;
33 import javax.xml.validation.Schema;
34 import javax.xml.validation.SchemaFactory;
35 import javax.xml.validation.TypeInfoProvider;
36 import javax.xml.validation.ValidatorHandler;
37
38 import org.testng.Assert;
39 import org.testng.annotations.Test;
40 import org.w3c.dom.TypeInfo;
41 import org.xml.sax.Attributes;
42 import org.xml.sax.InputSource;
43 import org.xml.sax.SAXException;
44 import org.xml.sax.XMLReader;
45 import org.xml.sax.helpers.DefaultHandler;
46
47 /*
48 * @bug 6509668
49 * @summary Test TypeInfoProvider.getElementTypeInfo() for union type when startElement and endElement.
50 */
51 public class Bug6509668 {
52
53 public static final String XSD = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n"
54 + " xmlns:ns='http://example.org/jaxp13_test'\n" + " targetNamespace='http://example.org/jaxp13_test'\n" + " elementFormDefault='qualified'>\n"
55 + " <simpleType name='intOrString'>\n" + " <union memberTypes='int string'/>\n" + " </simpleType>\n"
56 + " <element name='test' type='ns:intOrString'/>\n" + "</schema>\n";
57
58 public static final String XML = "<?xml version='1.0'?>\n" + "<ns:test xmlns:ns='http://example.org/jaxp13_test'>abc</ns:test>\n";
59
60 private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
61 SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
62
63 InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
64 StreamSource xsdSource = new StreamSource(reader);
65
66 Schema schema = schemaFactory.newSchema(xsdSource);
67 return schema.newValidatorHandler();
68 }
69
70 private XMLReader createXMLReader() throws ParserConfigurationException, SAXException {
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package validation;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29
30 import javax.xml.parsers.ParserConfigurationException;
31 import javax.xml.parsers.SAXParserFactory;
32 import javax.xml.transform.stream.StreamSource;
33 import javax.xml.validation.Schema;
34 import javax.xml.validation.SchemaFactory;
35 import javax.xml.validation.TypeInfoProvider;
36 import javax.xml.validation.ValidatorHandler;
37
38 import org.testng.Assert;
39 import org.testng.annotations.Listeners;
40 import org.testng.annotations.Test;
41 import org.w3c.dom.TypeInfo;
42 import org.xml.sax.Attributes;
43 import org.xml.sax.InputSource;
44 import org.xml.sax.SAXException;
45 import org.xml.sax.XMLReader;
46 import org.xml.sax.helpers.DefaultHandler;
47
48 /*
49 * @bug 6509668
50 * @summary Test TypeInfoProvider.getElementTypeInfo() for union type when startElement and endElement.
51 */
52 @Listeners({jaxp.library.BasePolicy.class})
53 public class Bug6509668 {
54
55 public static final String XSD = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n"
56 + " xmlns:ns='http://example.org/jaxp13_test'\n" + " targetNamespace='http://example.org/jaxp13_test'\n" + " elementFormDefault='qualified'>\n"
57 + " <simpleType name='intOrString'>\n" + " <union memberTypes='int string'/>\n" + " </simpleType>\n"
58 + " <element name='test' type='ns:intOrString'/>\n" + "</schema>\n";
59
60 public static final String XML = "<?xml version='1.0'?>\n" + "<ns:test xmlns:ns='http://example.org/jaxp13_test'>abc</ns:test>\n";
61
62 private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
63 SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
64
65 InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
66 StreamSource xsdSource = new StreamSource(reader);
67
68 Schema schema = schemaFactory.newSchema(xsdSource);
69 return schema.newValidatorHandler();
70 }
71
72 private XMLReader createXMLReader() throws ParserConfigurationException, SAXException {
|