1320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson/* 2320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one or more 3320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * contributor license agreements. See the NOTICE file distributed with 4320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * this work for additional information regarding copyright ownership. 5320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The ASF licenses this file to You under the Apache License, Version 2.0 6320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * (the "License"); you may not use this file except in compliance with 7320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the License. You may obtain a copy of the License at 8320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 9320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 10320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * 11320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Unless required by applicable law or agreed to in writing, software 12320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 13320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * See the License for the specific language governing permissions and 15320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * limitations under the License. 16320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 17320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson// $Id: TypeInfoProvider.java 884939 2009-11-27 18:20:46Z mrglavas $ 18320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 19320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonpackage javax.xml.validation; 20320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 21320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonimport org.w3c.dom.TypeInfo; 22320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson 23320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson/** 24320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * This class provides access to the type information determined 25f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * by {@link ValidatorHandler}. 26f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 27320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 28320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Some schema languages, such as W3C XML Schema, encourages a validator 29320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * to report the "type" it assigns to each attribute/element. 30320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Those applications who wish to access this type information can invoke 31320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * methods defined on this "interface" to access such type information. 32f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 33320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 34320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Implementation of this "interface" can be obtained through the 35320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link ValidatorHandler#getTypeInfoProvider()} method. 36f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 37320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @author <a href="mailto:Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a> 38320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @version $Revision: 884939 $, $Date: 2009-11-27 10:20:46 -0800 (Fri, 27 Nov 2009) $ 39f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * @see org.w3c.dom.TypeInfo 40320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @since 1.5 41320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 42320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilsonpublic abstract class TypeInfoProvider { 43f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 44320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 45320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Constructor for the derived class. 46f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 47320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 48320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The constructor does nothing. 49320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 50320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson protected TypeInfoProvider() { 51320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson } 52f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 53320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 54320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p>Returns the immutable {@link TypeInfo} object for the current element.</p> 55f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 56320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 57320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The method may only be called by the startElement and endElement event of 58320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.ContentHandler} that the application sets to the 59320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link ValidatorHandler}.</p> 60f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 61320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalStateException 62320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If this method is called from other {@link org.xml.sax.ContentHandler} 63320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * methods. 64320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return 65320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * An immutable {@link TypeInfo} object that represents the 66f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * type of the current element. 67320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Note that the caller can keep references to the obtained 68320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link TypeInfo} longer than the callback scope. 69f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 70320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Otherwise, this method returns 71320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * null if the validator is unable to 72320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * determine the type of the current element for some reason 73320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * (for example, if the validator is recovering from 74320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * an earlier error.) 75f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 76320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 77320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract TypeInfo getElementTypeInfo(); 78f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 79320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 80320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns the immutable {@link TypeInfo} object for the specified 81320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * attribute of the current element. 82f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 83320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 84320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The method may only be called by the startElement event of 85320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.ContentHandler} that the application sets to the 86320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link ValidatorHandler}. 87f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 88320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param index 89320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The index of the attribute. The same index for 90320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.Attributes} object passed to the 91320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <tt>startElement</tt> callback. 92f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 93320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IndexOutOfBoundsException 94320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If the index is invalid. 95320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalStateException 96320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If this method is called from other {@link org.xml.sax.ContentHandler} 97320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * methods. 98f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 99320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return 100320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * An immutable {@link TypeInfo} object that represents the 101f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * type of the specified attribute. 102320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Note that the caller can keep references to the obtained 103320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link TypeInfo} longer than the callback scope. 104f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 105320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Otherwise, this method returns 106320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * null if the validator is unable to 107320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * determine the type. 108320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 109320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract TypeInfo getAttributeTypeInfo(int index); 110f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 111320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 112320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns <tt>true</tt> if the specified attribute is determined 113320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * to be ID. 114f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 115320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 116320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Exactly how an attribute is "determined to be ID" is up to the 117320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * schema language. In case of W3C XML Schema, this means 118320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * that the actual type of the attribute is the built-in ID type 119320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * or its derived type. 120f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 121320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 122320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * A {@link javax.xml.parsers.DocumentBuilder} uses this information 123320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * to properly implement {@link org.w3c.dom.Attr#isId()}. 124f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 125320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 126320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The method may only be called by the startElement event of 127320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.ContentHandler} that the application sets to the 128320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link ValidatorHandler}. 129f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 130320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param index 131320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The index of the attribute. The same index for 132320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.Attributes} object passed to the 133320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <tt>startElement</tt> callback. 134f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 135320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IndexOutOfBoundsException 136320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If the index is invalid. 137320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalStateException 138320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If this method is called from other {@link org.xml.sax.ContentHandler} 139320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * methods. 140f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 141320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return true 142320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * if the type of the specified attribute is ID. 143320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 144320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract boolean isIdAttribute(int index); 145f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 146320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson /** 147320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * Returns <tt>false</tt> if the attribute was added by the validator. 148f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 149320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 150320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * This method provides information necessary for 151320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * a {@link javax.xml.parsers.DocumentBuilder} to determine what 152320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the DOM tree should return from the {@link org.w3c.dom.Attr#getSpecified()} method. 153f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 154320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 155320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The method may only be called by the startElement event of 156320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.ContentHandler} that the application sets to the 157320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * {@link ValidatorHandler}. 158f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 159320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <p> 160320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * A general guideline for validators is to return true if 161320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the attribute was originally present in the pipeline, and 162320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * false if it was added by the validator. 163f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 164320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @param index 165320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * The index of the attribute. The same index for 166320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * the {@link org.xml.sax.Attributes} object passed to the 167320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <tt>startElement</tt> callback. 168f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 169320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IndexOutOfBoundsException 170320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If the index is invalid. 171320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @throws IllegalStateException 172320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * If this method is called from other {@link org.xml.sax.ContentHandler} 173320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * methods. 174f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 175320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * @return 176320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * <tt>true</tt> if the attribute was present before the validator 177320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * processes input. <tt>false</tt> if the attribute was added 178320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson * by the validator. 179320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson */ 180320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson public abstract boolean isSpecified(int index); 181320c9890e8241fb0ad05de6fa5e6c3eb3aece159Jesse Wilson} 182