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

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

public class IDREFDatatypeValidator
extends AbstractDatatypeValidator
implements StatefullDatatypeValidator

IDREFDatatypeValidator - represents the IDREFS attribute type from XML 1.0 recommendation. The Value Space of IDREF is the set of all strings that match the NCName production and have been used in an XML Document as the value of an element or attribute of Type ID. The Lexical space of IDREF is the set of strings that match the NCName production.

The Value space of IDREF is scoped to a specific instance document

This datatatype checks the following constraint: An IDREF must match the value of an ID in the XML document in which it occurs.

The following snippet shows typical use of the the IDDatatype:

       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: IDREFDatatypeValidator.java,v 1.4 2002/01/29 01:15:11 lehors Exp $
Author:
Jeffrey Rodriguez-
See Also:
IDDatatypeValidator, DatatypeValidator, DatatypeValidator

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
IDREFDatatypeValidator()
           
IDREFDatatypeValidator(DatatypeValidator base, java.util.Hashtable facets, boolean derivedByList)
           
 
Method Summary
 void checkIdRefs(java.util.Hashtable idrefs, java.util.Hashtable ids)
          Private method used to check the IDREF valid ID constraint
 java.lang.Object clone()
          Returns 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()
          A no-op method in this validator
 void initialize(java.lang.Object tableOfIDs)
          This method is unique to IDREFDatatypeValidator
 void setLocale(java.util.Locale locale)
          set the locate to be used for error messages
 void validate()
          This method is unique to IDREFDatatypeValidator
 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

IDREFDatatypeValidator

public IDREFDatatypeValidator()
                       throws InvalidDatatypeFacetException

IDREFDatatypeValidator

public IDREFDatatypeValidator(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
derivedBylist - Flag which is true when type is derived by list otherwise it it is derived by extension.
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

This method is unique to IDREFDatatypeValidator

Validator should call this method at the EndDocument call to start IDREF constraint validation. This validation rule checks IDREF values accumulated in internal table against read table passed to IDREF validator at instantiation time.

Caveats -

  • Do not call this validator method until you are sure that all ID values have been found since this method contains a live reference to an internal ID table which the ID validator could still be updating.
  • Do not call this method before the initialize method since the initialize method will set the reference to ID table used by this method to validate the IDREFs.
  • Specified by:
    validate in interface StatefullDatatypeValidator
    Throws:
    InvalidDatatypeValueException -  

    initialize

    public void initialize(java.lang.Object tableOfIDs)

    This method is unique to IDREFDatatypeValidator

    This method initializes the internal reference to the ID table of ID's and IDREF internal table of IDREFs.

    This method should be called before the valid() method

    Specified by:
    initialize in interface StatefullDatatypeValidator
    Parameters:
    tableOfIDs -  

    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
    Returns a copy of this object.
    Overrides:
    clone in class java.lang.Object

    checkIdRefs

    public void checkIdRefs(java.util.Hashtable idrefs,
                            java.util.Hashtable ids)
                     throws InvalidDatatypeValueException

    Private method used to check the IDREF valid ID constraint

    Throws:
    InvalidDatatypeValueException -  

    setLocale

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

    getInternalStateInformation

    public java.lang.Object getInternalStateInformation()
    A no-op method in this validator
    Specified by:
    getInternalStateInformation in interface StatefullDatatypeValidator


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