org.apache.xerces.impl.dv.dtd
Class IDDatatypeValidator

java.lang.Object
  |
  +--org.apache.xerces.impl.dv.dtd.AbstractDatatypeValidator
        |
        +--org.apache.xerces.impl.dv.dtd.IDDatatypeValidator
All Implemented Interfaces:
DatatypeValidator, StatefullDatatypeValidator

public class IDDatatypeValidator
extends AbstractDatatypeValidator
implements StatefullDatatypeValidator

IDDatatypeValidator - ID represents the ID attribute type from XML 1.0 Recommendation. The value space od ID is the set of all strings that match the NCName production and have been used in an XML document. The lexical space of ID is the set of all strings that match the NCName production.

The value space of ID is scoped to a specific instance document.

The following constraint applies: An ID must not appear more than once in an XML document as a value of this type; i.e., ID values must uniquely identify the elements which bear them.

An ID validator is a statefull validator, it needs read/write access to the associated instant document table of IDs.

The following snippet shows typical use of the the IDDatatype:

  DatatypeValidator  idData = tstRegistry.getDatatypeValidator( "ID" );
 
       if (  idData != null ) {
          ((IDDatatypeValidator) idData).initialize();
          try {
             idData.validate( "a1", null );
             idData.validate( "a2", null );
          } catch ( Exception ex ) {
             ex.printStackTrace();
          }
          Hashtable tst = (Hashtable)((IDDatatypeValidator) idData).getTableIds();
          if (tst != null) {
             System.out.println("Table of ID = " + tst.toString());
          }
 
       }
 
       DatatypeValidator idRefData = tstRegistry.getDatatypeValidator("IDREF" );
       if( idRefData != null ){
          IDREFDatatypeValidator refData = (IDREFDatatypeValidator) idRefData;
          refData.initialize( ((IDDatatypeValidator) idData).getTableIds());
          try {
             refData.validate( "a1", null );
             refData.validate( "a2", null );
             //refData.validate( "a3", null );//Should throw exception at validate()
             refData.validate();
          } catch( Exception ex ){
             ex.printStackTrace();
          }
       }
       

Version:
$Id: IDDatatypeValidator.java,v 1.4 2002/01/29 01:15:11 lehors Exp $
Author:
Jeffrey Rodriguez
See Also:
AbstractDatatypeValidator, DatatypeValidator, IDREFDatatypeValidator

Fields inherited from class org.apache.xerces.impl.dv.dtd.AbstractDatatypeValidator
fFacets
 
Fields inherited from interface org.apache.xerces.impl.dv.dtd.DatatypeValidator
FACET_DURATION, FACET_ENCODING, FACET_ENUMERATION, FACET_LENGTH, FACET_MAXEXCLUSIVE, FACET_MAXINCLUSIVE, FACET_MAXLENGTH, FACET_MINEXCLUSIVE, FACET_MININCLUSIVE, FACET_MINLENGTH, FACET_PATTERN, FACET_PERIOD, FACET_PRECISSION, FACET_SCALE, FACET_WHITESPACE, WHITESPACE_COLLAPSE, WHITESPACE_NONE, WHITESPACE_PRESERVE, WHITESPACE_REPLACE
 
Constructor Summary
IDDatatypeValidator()
           
IDDatatypeValidator(DatatypeValidator base, java.util.Hashtable facets, boolean derivedByList)
           
 
Method Summary
 java.lang.Object clone()
          Return a copy of this object.
 int compare(java.lang.String content1, java.lang.String content2)
          REVISIT Compares two Datatype for order
 java.util.Hashtable getFacets()
          getFacets
 java.lang.Object getInternalStateInformation()
          This method is unique to IDDatatypeValidator.
 void initialize(java.lang.Object tableOfIDs)
          Initializes internal table of IDs used by ID datatype validator to keep track of ID's.
 void setLocale(java.util.Locale locale)
          set the locate to be used for error messages
 void validate()
          A no-op method in this Datatype
 void validate(java.lang.String content, java.lang.Object state)
          Checks that "content" string is valid datatype.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDDatatypeValidator

public IDDatatypeValidator()
                    throws InvalidDatatypeFacetException

IDDatatypeValidator

public IDDatatypeValidator(DatatypeValidator base,
                           java.util.Hashtable facets,
                           boolean derivedByList)
                    throws InvalidDatatypeFacetException
Method Detail

validate

public void validate(java.lang.String content,
                     java.lang.Object state)
              throws InvalidDatatypeValueException
Checks that "content" string is valid datatype. If invalid a Datatype validation exception is thrown.
Overrides:
validate in class AbstractDatatypeValidator
Parameters:
content - A string containing the content to be validated
state - Generic Object state that can be use to pass Structures
Throws:
throws - InvalidDatatypeException if the content is invalid according to the rules for the validators
InvalidDatatypeValueException -  
See Also:
InvalidDatatypeValueException

validate

public void validate()
              throws InvalidDatatypeValueException
A no-op method in this Datatype
Specified by:
validate in interface StatefullDatatypeValidator

initialize

public void initialize(java.lang.Object tableOfIDs)
Initializes internal table of IDs used by ID datatype validator to keep track of ID's. This method is unique to IDDatatypeValidator.
Specified by:
initialize in interface StatefullDatatypeValidator
Parameters:
state - This is a dummy parameter.

compare

public int compare(java.lang.String content1,
                   java.lang.String content2)
REVISIT Compares two Datatype for order
Overrides:
compare in class AbstractDatatypeValidator
Parameters:
o1 -  
o2 -  
Returns:
0 if value1 and value2 are equal, a value less than 0 if value1 is less than value2, a value greater than 0 if value1 is greater than value2

getFacets

public java.util.Hashtable getFacets()
Description copied from class: AbstractDatatypeValidator
getFacets
Overrides:
getFacets in class AbstractDatatypeValidator
Following copied from class: org.apache.xerces.impl.dv.dtd.AbstractDatatypeValidator
Returns:
A Hashtable containing the facets for this datatype.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Return a copy of this object.
Overrides:
clone in class java.lang.Object

getInternalStateInformation

public java.lang.Object getInternalStateInformation()
This method is unique to IDDatatypeValidator. It returns a reference to the internal ID table. This method should be used by the IDREF datatype validator which needs read access to ID table.
Specified by:
getInternalStateInformation in interface StatefullDatatypeValidator
Returns:
internal state of the validator (in this case the ID table)

setLocale

public void setLocale(java.util.Locale locale)
set the locate to be used for error messages


Copyright © 1999-2001 Apache XML Project. All Rights Reserved.