1. // $Id: TypeInfoProvider.java,v 1.11 2004/02/06 01:16:10 kk122374 Exp $
  2. /*
  3. * @(#)TypeInfoProvider.java 1.5 04/07/26
  4. *
  5. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  6. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  7. */
  8. package javax.xml.validation;
  9. import org.w3c.dom.TypeInfo;
  10. /**
  11. * This class provides access to the type information determined
  12. * by {@link ValidatorHandler}.
  13. *
  14. * <p>
  15. * Some schema languages, such as W3C XML Schema, encourages a validator
  16. * to report the "type" it assigns to each attribute/element.
  17. * Those applications who wish to access this type information can invoke
  18. * methods defined on this "interface" to access such type information.
  19. *
  20. * <p>
  21. * Implementation of this "interface" can be obtained through the
  22. * {@link ValidatorHandler#getTypeInfoProvider()} method.
  23. *
  24. * @author <a href="mailto:Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
  25. * @version $Revision: 1.11 $, $Date: 2004/02/06 01:16:10 $
  26. * @see org.w3c.dom.TypeInfo
  27. * @since 1.5
  28. */
  29. public abstract class TypeInfoProvider {
  30. /**
  31. * Constructor for the derived class.
  32. *
  33. * <p>
  34. * The constructor does nothing.
  35. */
  36. protected TypeInfoProvider() {
  37. }
  38. /**
  39. * <p>Returns the immutable {@link TypeInfo} object for the current element.</p>
  40. *
  41. * <p>
  42. * The method may only be called by the startElement event of
  43. * the {@link org.xml.sax.ContentHandler} that the application sets to the
  44. * {@link ValidatorHandler}.</p>
  45. *
  46. * @throws IllegalStateException
  47. * If this method is called from other {@link org.xml.sax.ContentHandler}
  48. * methods.
  49. * @return
  50. * An immutable {@link TypeInfo} object that represents the
  51. * type of the current element.
  52. * Note that the caller can keep references to the obtained
  53. * {@link TypeInfo} longer than the callback scope.
  54. *
  55. * Otherwise, this method returns
  56. * null if the validator is unable to
  57. * determine the type of the current element for some reason
  58. * (for example, if the validator is recovering from
  59. * an earlier error.)
  60. *
  61. */
  62. public abstract TypeInfo getElementTypeInfo();
  63. /**
  64. * Returns the immutable {@link TypeInfo} object for the specified
  65. * attribute of the current element.
  66. *
  67. * <p>
  68. * The method may only be called by the startElement event of
  69. * the {@link org.xml.sax.ContentHandler} that the application sets to the
  70. * {@link ValidatorHandler}.
  71. *
  72. * @param index
  73. * The index of the attribute. The same index for
  74. * the {@link org.xml.sax.Attributes} object passed to the
  75. * <tt>startElement</tt> callback.
  76. *
  77. * @throws IndexOutOfBoundsException
  78. * If the index is invalid.
  79. * @throws IllegalStateException
  80. * If this method is called from other {@link org.xml.sax.ContentHandler}
  81. * methods.
  82. *
  83. * @return
  84. * An immutable {@link TypeInfo} object that represents the
  85. * type of the specified attribute.
  86. * Note that the caller can keep references to the obtained
  87. * {@link TypeInfo} longer than the callback scope.
  88. *
  89. * Otherwise, this method returns
  90. * null if the validator is unable to
  91. * determine the type.
  92. */
  93. public abstract TypeInfo getAttributeTypeInfo(int index);
  94. /**
  95. * Returns <tt>true</tt> if the specified attribute is determined
  96. * to be ID.
  97. *
  98. * <p>
  99. * Exacly how an attribute is "determined to be ID" is up to the
  100. * schema language. In case of W3C XML Schema, this means
  101. * that the actual type of the attribute is the built-in ID type
  102. * or its derived type.
  103. *
  104. * <p>
  105. * A {@link javax.xml.parsers.DocumentBuilder} uses this information
  106. * to properly implement {@link org.w3c.dom.Attr#isId()}.
  107. *
  108. * <p>
  109. * The method may only be called by the startElement event of
  110. * the {@link org.xml.sax.ContentHandler} that the application sets to the
  111. * {@link ValidatorHandler}.
  112. *
  113. * @param index
  114. * The index of the attribute. The same index for
  115. * the {@link org.xml.sax.Attributes} object passed to the
  116. * <tt>startElement</tt> callback.
  117. *
  118. * @throws IndexOutOfBoundsException
  119. * If the index is invalid.
  120. * @throws IllegalStateException
  121. * If this method is called from other {@link org.xml.sax.ContentHandler}
  122. * methods.
  123. *
  124. * @return true
  125. * if the type of the specified attribute is ID.
  126. */
  127. public abstract boolean isIdAttribute(int index);
  128. /**
  129. * Returns <tt>false</tt> if the attribute was added by the validator.
  130. *
  131. * <p>
  132. * This method provides information necessary for
  133. * a {@link javax.xml.parsers.DocumentBuilder} to determine what
  134. * the DOM tree should return from the {@link org.w3c.dom.Attr#getSpecified()} method.
  135. *
  136. * <p>
  137. * The method may only be called by the startElement event of
  138. * the {@link org.xml.sax.ContentHandler} that the application sets to the
  139. * {@link ValidatorHandler}.
  140. *
  141. * <p>
  142. * A general guideline for validators is to return true if
  143. * the attribute was originally present in the pipeline, and
  144. * false if it was added by the validator.
  145. *
  146. * @param index
  147. * The index of the attribute. The same index for
  148. * the {@link org.xml.sax.Attributes} object passed to the
  149. * <tt>startElement</tt> callback.
  150. *
  151. * @throws IndexOutOfBoundsException
  152. * If the index is invalid.
  153. * @throws IllegalStateException
  154. * If this method is called from other {@link org.xml.sax.ContentHandler}
  155. * methods.
  156. *
  157. * @return
  158. * <tt>true</tt> if the attribute was present before the validator
  159. * processes input. <tt>false</tt> if the attribute was added
  160. * by the validator.
  161. */
  162. public abstract boolean isSpecified(int index);
  163. }