1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package validation.jdk8036951; 19 20 21 import com.sun.org.apache.xerces.internal.xs.ElementPSVI; 22 import com.sun.org.apache.xerces.internal.xs.ItemPSVI; 23 import javax.xml.XMLConstants; 24 import javax.xml.namespace.QName; 25 import javax.xml.parsers.DocumentBuilder; 26 import javax.xml.parsers.DocumentBuilderFactory; 27 import javax.xml.validation.SchemaFactory; 28 import org.testng.annotations.AfterClass; 29 import org.testng.annotations.BeforeClass; 30 import org.testng.annotations.Test; 31 import org.w3c.dom.Document; 32 import validation.BaseTest; 33 34 /** 35 * @author Peter McCracken, IBM 36 * @version $Id$ 37 */ 38 public class RootTypeDefinitionTest extends BaseTest { 39 40 private QName unknownType; 41 private QName typeX; 42 private QName typeY; 43 private QName typeZ; 44 private QName typeOtherNamespace; 45 46 private final static String UNKNOWN_TYPE_ERROR = "cvc-type.1"; 47 48 private final static String INVALID_DERIVATION_ERROR = "cvc-elt.4.3"; 49 50 @BeforeClass setUp()51 protected void setUp() throws Exception { 52 super.setUp(); 53 } 54 55 @AfterClass tearDown()56 protected void tearDown() throws Exception { 57 super.tearDown(); 58 } 59 getXMLDocument()60 protected String getXMLDocument() { 61 return "base.xml"; 62 } 63 getSchemaFile()64 protected String getSchemaFile() { 65 return "base.xsd"; 66 } 67 getRelevantErrorIDs()68 protected String[] getRelevantErrorIDs() { 69 return new String[] { UNKNOWN_TYPE_ERROR, INVALID_DERIVATION_ERROR }; 70 } 71 RootTypeDefinitionTest(String name)72 public RootTypeDefinitionTest(String name) { 73 super(name); 74 unknownType = new QName("W"); 75 typeX = new QName("X"); 76 typeY = new QName("Y"); 77 typeZ = new QName("Z"); 78 typeOtherNamespace = new QName("xslt.unittests", "W", "unit"); 79 } 80 81 82 /** 83 * XERCESJ-1141 root-type-definition property not read by XMLSchemaValidator during reset() 84 */ 85 @Test testUsingDocumentBuilderFactory()86 public void testUsingDocumentBuilderFactory() throws Exception { 87 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 88 dbf.setAttribute(ROOT_TYPE, typeX); 89 dbf.setAttribute(DOCUMENT_CLASS_NAME,"com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl"); 90 dbf.setNamespaceAware(true); 91 dbf.setValidating(false); 92 93 SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 94 dbf.setSchema(sf.newSchema(fSchemaURL)); 95 96 DocumentBuilder db = dbf.newDocumentBuilder(); 97 Document document = db.parse(fDocumentURL.toExternalForm()); 98 ElementPSVI rootNode = (ElementPSVI) document.getDocumentElement(); 99 100 assertValidity(ItemPSVI.VALIDITY_VALID, rootNode.getValidity()); 101 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, rootNode 102 .getValidationAttempted()); 103 assertElementNull(rootNode.getElementDeclaration()); 104 assertTypeName("X", rootNode.getTypeDefinition().getName()); 105 } 106 checkDefault()107 private void checkDefault() { 108 assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity()); 109 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode 110 .getValidationAttempted()); 111 assertElementName("A", fRootNode.getElementDeclaration().getName()); 112 assertTypeName("X", fRootNode.getTypeDefinition().getName()); 113 } 114 } 115