org.apache.xerces.validators.schema
Class XSchemaValidator

java.lang.Object
  |
  +--org.apache.xerces.validators.schema.XSchemaValidator

public class XSchemaValidator
extends java.lang.Object
implements XMLValidator

XSchemaValidator is an experimental implementation of a validator for the W3C Schema Language. All of its implementation is subject to change.


Inner classes inherited from class org.apache.xerces.framework.XMLValidator
XMLValidator.ContentSpec
 
Constructor Summary
XSchemaValidator(StringPool stringPool, XMLErrorReporter errorReporter, XMLEntityHandler entityHandler)
           
 
Method Summary
protected  void addRequiredNotation(int notationName, Locator locator, int majorCode, int minorCode, java.lang.Object[] args)
           
 boolean attributeSpecified(int elementTypeIndex, XMLAttrList attrList, int attrNameIndex, Locator attrNameLocator, int attValueIndex)
          add an attribute definition for an attribute name attrName to the element elementType.
 void characters(char[] chars, int offset, int length)
          a callback for character data - String object version
 void characters(int stringIndex)
          a callback for character data - string pool version
 int checkContent(int elementIndex, int childCount, int[] children)
          Check that the content of an element is valid.
 void checkIDRefNames()
          Check that all ID references were to ID attributes present in the document.
 boolean endElement(int elementTypeIndex)
          a callback for the end tag of an element
 boolean externalReferenceInContent(int entityIndex)
          return true if entityIndex's entity is external, and it satisfies the requirements for an external entity reference within content
 int getAttName(int attDefIndex)
           
 int getAttValue(int attDefIndex)
           
 XMLContentModel getContentModel(int elementIndex)
           
 int getContentSpec(int elementIndex)
           
 java.lang.String getContentSpecAsString(int elementIndex)
          return elementIndex's content spec as a string
 void getContentSpecNode(int contentSpecIndex, XMLContentSpecNode csn)
           
 int getContentSpecType(int elementIndex)
           
 boolean getDynamicValidationEnabled()
           
 int getElement(int elementTypeIndex)
           
 int getElementType(int elementIndex)
           
 int getEntityName(int entityIndex)
           
 int getEntityValue(int entityIndex)
          return the replacement text for entityIndex
 boolean getNamespacesEnabled()
           
 int getNotationName(int entityIndex)
           
 int getParameterEntityValue(int peIndex)
          return the replacement text for a parameter entity
 int getPublicIdIndexOfEntity(int entityIndex)
           
 java.lang.String getPublicIdOfEntity(int entityIndex)
          return the public identifer for entityIndex
 java.lang.String getPublicIdOfParameterEntity(int peIndex)
          return the public identifier for a parameter entity
 Document getSchemaDocument()
          Deprecated.  
 int getSystemIdIndexOfEntity(int entityIndex)
           
 java.lang.String getSystemIdOfEntity(int entityIndex)
          return the system identifier for entityIndex
 java.lang.String getSystemIdOfParameterEntity(int peIndex)
          return the system identifier for a parameter entity
 boolean getValidationEnabled()
           
 boolean getWarningOnDuplicateAttDef()
           
 boolean getWarningOnUndeclaredElements()
           
 void ignorableWhitespace(char[] chars, int offset, int length)
          a callback for ignorable whitespace - String object version
 void ignorableWhitespace(int stringIndex)
          a callback for ignorable whitespace - string pool version
 boolean isExternalEntity(int entityIndex)
          return true if entityIndex's entity is external
 boolean isExternalParameterEntity(int peIndex)
          return true if a parameter entity is external
 boolean isUnparsedEntity(int entityIndex)
          return true if entityIndex's entity is unparsed
 void loadSchema(InputSource is)
           
 int lookupEntity(int entityNameIndex)
          return a handle to an entity.
 int lookupParameterEntity(int peNameIndex)
          return a handle to a parameter entity - this handle can then be passed to other XMLEntityHandler methods on XMLValidator
 boolean notationDeclared(int notationNameIndex)
           
protected  void reportRecoverableXMLError(int majorCode, int minorCode)
           
protected  void reportRecoverableXMLError(int majorCode, int minorCode, int stringIndex1)
           
protected  void reportRecoverableXMLError(int majorCode, int minorCode, int stringIndex1, int stringIndex2)
           
protected  void reportRecoverableXMLError(int majorCode, int minorCode, java.lang.String string1)
           
protected  void reportRecoverableXMLError(int majorCode, int minorCode, java.lang.String string1, java.lang.String string2)
           
protected  void reportRecoverableXMLError(int majorCode, int minorCode, java.lang.String string1, java.lang.String string2, java.lang.String string3)
           
 void reset(StringPool stringPool, XMLErrorReporter errorReporter, XMLEntityHandler entityHandler)
           
 void rootElementSpecified(int rootElementType)
          Check to see if the rootElement matches the root element specified by the DOCTYPE line.
 void setDynamicValidationEnabled(boolean flag)
           
 void setNamespacesEnabled(boolean flag)
           
 void setValidationEnabled(boolean flag)
           
 void setWarningOnDuplicateAttDef(boolean flag)
           
 void setWarningOnUndeclaredElements(boolean flag)
           
 boolean startElement(int elementTypeIndex, XMLAttrList attrList)
          a callback for the start tag of an element
 int traverseDatatypeDecl(Element datatypeDecl)
           
 int valueOfReferenceInAttValue(int entityIndex)
          return the string pool index of an entity the entity must be allowed to appear in an attribute value
 int whatCanGoHere(int elementIndex, boolean fullyValid, InsertableElementsInfo info)
          Returns information about which elements can be placed at a particular point in the passed element's content model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XSchemaValidator

public XSchemaValidator(StringPool stringPool,
                        XMLErrorReporter errorReporter,
                        XMLEntityHandler entityHandler)
Method Detail

reset

public void reset(StringPool stringPool,
                  XMLErrorReporter errorReporter,
                  XMLEntityHandler entityHandler)
           throws java.lang.Exception

getSchemaDocument

public Document getSchemaDocument()
Deprecated.  


setValidationEnabled

public void setValidationEnabled(boolean flag)

getValidationEnabled

public boolean getValidationEnabled()

setDynamicValidationEnabled

public void setDynamicValidationEnabled(boolean flag)

getDynamicValidationEnabled

public boolean getDynamicValidationEnabled()

setNamespacesEnabled

public void setNamespacesEnabled(boolean flag)

getNamespacesEnabled

public boolean getNamespacesEnabled()

setWarningOnDuplicateAttDef

public void setWarningOnDuplicateAttDef(boolean flag)

getWarningOnDuplicateAttDef

public boolean getWarningOnDuplicateAttDef()

setWarningOnUndeclaredElements

public void setWarningOnUndeclaredElements(boolean flag)

getWarningOnUndeclaredElements

public boolean getWarningOnUndeclaredElements()

notationDeclared

public boolean notationDeclared(int notationNameIndex)

addRequiredNotation

protected void addRequiredNotation(int notationName,
                                   Locator locator,
                                   int majorCode,
                                   int minorCode,
                                   java.lang.Object[] args)
                            throws java.lang.Exception

characters

public void characters(char[] chars,
                       int offset,
                       int length)
                throws java.lang.Exception
Description copied from interface: XMLValidator
a callback for character data - String object version
Specified by:
characters in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
chars - array containing the characters that were scanned
offset - offset in chars of characters that were scanned
length - length of characters that were scanned
Throws:
java.lang.Exception -  

characters

public void characters(int stringIndex)
                throws java.lang.Exception
Description copied from interface: XMLValidator
a callback for character data - string pool version
Specified by:
characters in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
stringIndex - string pool index of the string that was scanned
Throws:
java.lang.Exception -  

ignorableWhitespace

public void ignorableWhitespace(char[] chars,
                                int offset,
                                int length)
                         throws java.lang.Exception
Description copied from interface: XMLValidator
a callback for ignorable whitespace - String object version
Specified by:
ignorableWhitespace in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
chars - array containing the white space that was scanned
offset - offset in chars of the white space that was scanned
length - length of the white space that was scanned
Throws:
java.lang.Exception -  

ignorableWhitespace

public void ignorableWhitespace(int stringIndex)
                         throws java.lang.Exception
Description copied from interface: XMLValidator
a callback for ignorable whitespace - string pool version
Specified by:
ignorableWhitespace in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
stringIndex - - string pool index of the white space that was scanned
Throws:
java.lang.Exception -  

getElement

public int getElement(int elementTypeIndex)

getElementType

public int getElementType(int elementIndex)
                   throws java.lang.Exception

getContentSpecType

public int getContentSpecType(int elementIndex)

getContentSpec

public int getContentSpec(int elementIndex)

getContentSpecAsString

public java.lang.String getContentSpecAsString(int elementIndex)
Description copied from interface: XMLValidator
return elementIndex's content spec as a string
Specified by:
getContentSpecAsString in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
elementIndex - element handle
Returns:
String containing the content spec for elementIndex

getContentSpecNode

public void getContentSpecNode(int contentSpecIndex,
                               XMLContentSpecNode csn)

getAttName

public int getAttName(int attDefIndex)

getAttValue

public int getAttValue(int attDefIndex)

lookupEntity

public int lookupEntity(int entityNameIndex)
Description copied from interface: XMLValidator
return a handle to an entity. This handle can then be passed to the other XMLEntityHandler methods on XMLValidator
Specified by:
lookupEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityName - string pool index of entity name
Returns:
entity Handle
Throws:
java.lang.Exception -  

externalReferenceInContent

public boolean externalReferenceInContent(int entityIndex)
                                   throws java.lang.Exception
Description copied from interface: XMLValidator
return true if entityIndex's entity is external, and it satisfies the requirements for an external entity reference within content
Specified by:
externalReferenceInContent in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
true if the entity is external
Throws:
java.lang.Exception -  

valueOfReferenceInAttValue

public int valueOfReferenceInAttValue(int entityIndex)
                               throws java.lang.Exception
Description copied from interface: XMLValidator
return the string pool index of an entity the entity must be allowed to appear in an attribute value
Specified by:
valueOfReferenceInAttValue in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
string pool index of entity valkue
Throws:
java.lang.Exception -  

isExternalEntity

public boolean isExternalEntity(int entityIndex)
Description copied from interface: XMLValidator
return true if entityIndex's entity is external
Specified by:
isExternalEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
true if entityIndex's entity is external
Throws:
java.lang.Exception -  

isUnparsedEntity

public boolean isUnparsedEntity(int entityIndex)
Description copied from interface: XMLValidator
return true if entityIndex's entity is unparsed
Specified by:
isUnparsedEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
true if entityIndex's entity is unparsed
Throws:
java.lang.Exception -  

getEntityName

public int getEntityName(int entityIndex)

getEntityValue

public int getEntityValue(int entityIndex)
Description copied from interface: XMLValidator
return the replacement text for entityIndex
Specified by:
getEntityValue in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
the string pool index of entityIndex's replacement text
Throws:
java.lang.Exception -  

getPublicIdOfEntity

public java.lang.String getPublicIdOfEntity(int entityIndex)
Description copied from interface: XMLValidator
return the public identifer for entityIndex
Specified by:
getPublicIdOfEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
String containing entityIndex's public identifier
Throws:
java.lang.Exception -  

getPublicIdIndexOfEntity

public int getPublicIdIndexOfEntity(int entityIndex)

getSystemIdOfEntity

public java.lang.String getSystemIdOfEntity(int entityIndex)
Description copied from interface: XMLValidator
return the system identifier for entityIndex
Specified by:
getSystemIdOfEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
entityIndex - entity handle
Returns:
String containing entityIndex' system identifier
Throws:
java.lang.Exception -  

getSystemIdIndexOfEntity

public int getSystemIdIndexOfEntity(int entityIndex)

getNotationName

public int getNotationName(int entityIndex)

lookupParameterEntity

public int lookupParameterEntity(int peNameIndex)
                          throws java.lang.Exception
Description copied from interface: XMLValidator
return a handle to a parameter entity - this handle can then be passed to other XMLEntityHandler methods on XMLValidator
Specified by:
lookupParameterEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
peName - string pool index of a parameter entity name
Returns:
handle to the parameter entity named by peName
Throws:
java.lang.Exception -  

isExternalParameterEntity

public boolean isExternalParameterEntity(int peIndex)
Description copied from interface: XMLValidator
return true if a parameter entity is external
Specified by:
isExternalParameterEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
peIndex - parameter entity handle
Returns:
true if peIndex's parameter entity is external
Throws:
java.lang.Exception -  

getParameterEntityValue

public int getParameterEntityValue(int peIndex)
Description copied from interface: XMLValidator
return the replacement text for a parameter entity
Specified by:
getParameterEntityValue in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
peIndex - parameter entity handle
Returns:
the string pool index of the replacment text for peIndex's parameter entity
Throws:
java.lang.Exception -  

getPublicIdOfParameterEntity

public java.lang.String getPublicIdOfParameterEntity(int peIndex)
Description copied from interface: XMLValidator
return the public identifier for a parameter entity
Specified by:
getPublicIdOfParameterEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
peIndex - parameter entity handle
Returns:
a String containing the public identifier for peIndex's parameter entity
Throws:
java.lang.Exception -  

getSystemIdOfParameterEntity

public java.lang.String getSystemIdOfParameterEntity(int peIndex)
Description copied from interface: XMLValidator
return the system identifier for a parameter entity
Specified by:
getSystemIdOfParameterEntity in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
peIndex - parameter entity handle
Throws:
java.lang.Exception -  

rootElementSpecified

public void rootElementSpecified(int rootElementType)
                          throws java.lang.Exception
Description copied from interface: XMLValidator
Check to see if the rootElement matches the root element specified by the DOCTYPE line. Signal an error to the application if it does not.
Specified by:
rootElementSpecified in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
rootElementType - StringPool handle for the rootElement
Throws:
java.lang.Exception -  

attributeSpecified

public boolean attributeSpecified(int elementTypeIndex,
                                  XMLAttrList attrList,
                                  int attrNameIndex,
                                  Locator attrNameLocator,
                                  int attValueIndex)
                           throws java.lang.Exception
Description copied from interface: XMLValidator
add an attribute definition for an attribute name attrName to the element elementType.
Specified by:
attributeSpecified in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
elementType - the index of the element
attrList - the XMLAttrList to receive the new attribute
attrName - the string pool index of the attribute name
attrNameLocator - a SAX Locator (for error reporting)
attValue - the string pool index of the attribute value
Throws:
java.lang.Exception -  

startElement

public boolean startElement(int elementTypeIndex,
                            XMLAttrList attrList)
                     throws java.lang.Exception
Description copied from interface: XMLValidator
a callback for the start tag of an element
Specified by:
startElement in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
elementType - the index of the element
attrList - the XMLAttrList containing the attributes for the element
Returns:
true if processing element content //REVISIT
Throws:
java.lang.Exception -  

endElement

public boolean endElement(int elementTypeIndex)
                   throws java.lang.Exception
Description copied from interface: XMLValidator
a callback for the end tag of an element
Specified by:
endElement in interface XMLValidator
Tags copied from interface: XMLValidator
Parameters:
elementType - the index of the element
Returns:
true if processing element content //REVISIT
Throws:
java.lang.Exception -  

checkContent

public int checkContent(int elementIndex,
                        int childCount,
                        int[] children)
                 throws java.lang.Exception
Check that the content of an element is valid.

This is the method of primary concern to the validator. This method is called upon the scanner reaching the end tag of an element. At that time, the element's children must be structurally validated, so it calls this method. The index of the element being checked (in the decl pool), is provided as well as an array of element name indexes of the children. The validator must confirm that this element can have these children in this order.

This can also be called to do 'what if' testing of content models just to see if they would be valid.

Note that the element index is an index into the element decl pool, whereas the children indexes are name indexes, i.e. into the string pool.

A value of -1 in the children array indicates a PCDATA node. All other indexes will be positive and represent child elements. The count can be zero, since some elements have the EMPTY content model and that must be confirmed.

Specified by:
checkContent in interface XMLValidator
Parameters:
elementIndex - The index within the ElementDeclPool of this element.
childCount - The number of entries in the children array.
children - The children of this element. Each integer is an index within the StringPool of the child element name. An index of -1 is used to indicate an occurrence of non-whitespace character data.
Returns:
The value -1 if fully valid, else the 0 based index of the child that first failed. If the value returned is equal to the number of children, then additional content is required to reach a valid ending state.
Throws:
java.lang.Exception - Thrown on error.

checkIDRefNames

public void checkIDRefNames()
                     throws java.lang.Exception
Check that all ID references were to ID attributes present in the document.

This method is a convenience call that allows the validator to do any id ref checks above and beyond those done by the scanner. The scanner does the checks specificied in the XML spec, i.e. that ID refs refer to ids which were eventually defined somewhere in the document.

If the validator is for a Schema perhaps, which defines id semantics beyond those of the XML specificiation, this is where that extra checking would be done. For most validators, this is a no-op.

Throws:
java.lang.Exception - Thrown on error.

whatCanGoHere

public int whatCanGoHere(int elementIndex,
                         boolean fullyValid,
                         InsertableElementsInfo info)
                  throws java.lang.Exception
Returns information about which elements can be placed at a particular point in the passed element's content model.

Note that the incoming content model to test must be valid at least up to the insertion point. If not, then -1 will be returned and the info object will not have been filled in.

If, on return, the info.isValidEOC flag is set, then the 'insert after' elemement is a valid end of content, i.e. nothing needs to be inserted after it to make the parent element's content model valid.

Parameters:
elementIndex - The index within the ElementDeclPool of the element which is being querying.
fullyValid - Only return elements that can be inserted and still maintain the validity of subsequent elements past the insertion point (if any). If the insertion point is at the end, and this is true, then only elements that can be legal final states will be returned.
info - An object that contains the required input data for the method, and which will contain the output information if successful.
Returns:
The value -1 if fully valid, else the 0 based index of the child that first failed before the insertion point. If the value returned is equal to the number of children, then the specified children are valid but additional content is required to reach a valid ending state.
Throws:
java.lang.Exception - Thrown on error.
See Also:
InsertableElementsInfo

getContentModel

public XMLContentModel getContentModel(int elementIndex)
                                throws CMException

reportRecoverableXMLError

protected void reportRecoverableXMLError(int majorCode,
                                         int minorCode)
                                  throws java.lang.Exception

reportRecoverableXMLError

protected void reportRecoverableXMLError(int majorCode,
                                         int minorCode,
                                         int stringIndex1)
                                  throws java.lang.Exception

reportRecoverableXMLError

protected void reportRecoverableXMLError(int majorCode,
                                         int minorCode,
                                         java.lang.String string1)
                                  throws java.lang.Exception

reportRecoverableXMLError

protected void reportRecoverableXMLError(int majorCode,
                                         int minorCode,
                                         int stringIndex1,
                                         int stringIndex2)
                                  throws java.lang.Exception

reportRecoverableXMLError

protected void reportRecoverableXMLError(int majorCode,
                                         int minorCode,
                                         java.lang.String string1,
                                         java.lang.String string2)
                                  throws java.lang.Exception

reportRecoverableXMLError

protected void reportRecoverableXMLError(int majorCode,
                                         int minorCode,
                                         java.lang.String string1,
                                         java.lang.String string2,
                                         java.lang.String string3)
                                  throws java.lang.Exception

loadSchema

public void loadSchema(InputSource is)

traverseDatatypeDecl

public int traverseDatatypeDecl(Element datatypeDecl)
                         throws java.lang.Exception


Copyright © 1999 Apache XML Project. All Rights Reserved.