org.apache.xerces.validators.datatype
Class DateTimeValidator

java.lang.Object
  |
  +--org.apache.xerces.validators.datatype.AbstractDatatypeValidator
        |
        +--org.apache.xerces.validators.datatype.AbstractNumericFacetValidator
              |
              +--org.apache.xerces.validators.datatype.DateTimeValidator
All Implemented Interfaces:
java.lang.Cloneable, DatatypeValidator
Direct Known Subclasses:
DateDatatypeValidator, DateTimeDatatypeValidator, DayDatatypeValidator, DurationDatatypeValidator, MonthDatatypeValidator, MonthDayDatatypeValidator, TimeDatatypeValidator, YearDatatypeValidator, YearMonthDatatypeValidator

public abstract class DateTimeValidator
extends AbstractNumericFacetValidator

This is the base class of all date/time datatype validators. It implements common code for parsing, validating and comparing datatypes. Classes that extend this class, must implement parse() method.

Version:
$Id: DateTimeValidator.java 317875 2001-11-05 13:10:19Z elena $
Author:
Elena Litani, Len Berman

Field Summary
protected static int CY
           
protected static int D
           
protected static int DAY
           
protected static short EQUAL
           
protected  java.lang.StringBuffer fBuffer
           
protected  int[] fDateValue
           
protected  int fEnd
           
protected  int fEnumSize
           
protected  int fStart
           
protected static short GREATER_THAN
           
protected static int h
           
protected static int hh
           
protected static short LESS_THAN
           
protected static int m
           
protected static int M
           
protected  java.lang.StringBuffer message
           
protected static int mm
           
protected static int MONTH
           
protected static int MONTH_SIZE
           
protected static int ms
           
protected static int s
           
protected  int[] timeZone
           
protected static int TOTAL_SIZE
           
protected static int utc
           
protected static int YEAR
           
 
Fields inherited from class org.apache.xerces.validators.datatype.AbstractNumericFacetValidator
fEnumeration, fMaxExclusive, fMaxInclusive, fMinExclusive, fMinInclusive, INDETERMINATE
 
Fields inherited from class org.apache.xerces.validators.datatype.AbstractDatatypeValidator
fBaseValidator, fFacetsDefined, fFlags, fLocale, fMessageProvider, fPattern, fRegex
 
Fields inherited from interface org.apache.xerces.validators.datatype.DatatypeValidator
COLLAPSE, FACET_DURATION, FACET_ENCODING, FACET_ENUMERATION, FACET_FIXED, FACET_FRACTIONDIGITS, FACET_LENGTH, FACET_MAXEXCLUSIVE, FACET_MAXINCLUSIVE, FACET_MAXLENGTH, FACET_MINEXCLUSIVE, FACET_MININCLUSIVE, FACET_MINLENGTH, FACET_PATTERN, FACET_PERIOD, FACET_TOTALDIGITS, FACET_WHITESPACE, PRESERVE, REPLACE
 
Constructor Summary
DateTimeValidator()
           
DateTimeValidator(DatatypeValidator base, java.util.Hashtable facets, boolean derivedByList)
           
 
Method Summary
protected  void assignAdditionalFacets(java.lang.String key, java.util.Hashtable facets)
           
protected  void checkContent(java.lang.String content, java.lang.Object State, java.util.Vector enum, boolean asBase)
           
 java.lang.Object clone()
           
 int compare(java.lang.String content1, java.lang.String content2)
          Compares content in the Domain value vs.
protected  short compareDates(int[] date1, int[] date2, boolean strict)
          Compare algorithm described in dateDime (3.2.7).
protected  short compareOrder(int[] date1, int[] date2)
          Given normalized values, determines order-relation between give date/time objects.
protected  int compareValues(java.lang.Object value1, java.lang.Object value2)
           
protected  java.lang.String dateToString(int[] date)
           
protected  int findUTCSign(int start, int end)
          Return index of UTC char: 'Z', '+', '-'
protected  int fQuotient(int a, int b)
           
protected  int fQuotient(int temp, int low, int high)
           
protected  void getDate(int start, int end, int[] date)
          Parses date CCYY-MM-DD
protected  java.lang.String getMaxExclusive(boolean isBase)
           
protected  java.lang.String getMaxInclusive(boolean isBase)
           
protected  java.lang.String getMinExclusive(boolean isBase)
           
protected  java.lang.String getMinInclusive(boolean isBase)
           
protected  void getTime(int start, int end, int[] data)
          Parses time hh:mm:ss.sss and time zone if any
protected  void getTimeZone(int[] data, int sign)
          Parses time zone: 'Z' or {+,-} followed by hh:mm
protected  void getYearMonth(int start, int end, int[] date)
          Parses date CCYY-MM
protected  int indexOf(int start, int end, char ch)
          Computes index of given char within StringBuffer
protected  void initializeValues()
           
protected  int maxDayInMonthFor(int year, int month)
          Given {year,month} computes maximum number of days for given month
protected  int mod(int a, int b, int quotient)
           
protected  int modulo(int temp, int low, int high)
           
protected  void normalize(int[] date)
          normalize dateTime [E Adding durations to dateTimes] If timezone present - normalize to UTC If hour is 24 - normalize to start of following day
protected abstract  int[] parse(java.lang.String content, int[] date)
          Implemented by each subtype, calling appropriate function to parse given date/time
protected  int parseInt(int start, int end)
          Given start and end position, parses string value
protected  int parseIntYear(int end)
           
protected  void parseTimeZone(int end, int[] date)
          Shared code from Date and YearMonth datatypes.
protected  void reportError(java.lang.String msg, java.lang.String value)
          Use this function to report errors in constructor
protected  void resetBuffer(java.lang.String str)
          Resets fBuffer to store string representation of date/time
protected  void resetDateObj(int[] data)
          Resets object representation of date/time
protected  void setEnumeration(java.util.Vector enumeration)
           
protected  void setMaxExclusive(java.lang.String value)
           
protected  void setMaxInclusive(java.lang.String value)
           
protected  void setMinExclusive(java.lang.String value)
           
protected  void setMinInclusive(java.lang.String value)
           
 java.lang.Object validate(java.lang.String content, java.lang.Object state)
          Validate that a string is a W3C date/time type
protected  void validateDate(int[] date, java.lang.String content)
          Validates date object against facet and base datatype
protected  void validateDateTime(int[] data)
          Validates given date/time object accoring to W3C PR Schema [D.1 ISO 8601 Conventions]
 
Methods inherited from class org.apache.xerces.validators.datatype.AbstractNumericFacetValidator
checkBaseFacetConstraints, checkFacetConstraints, inheritAdditionalFacets
 
Methods inherited from class org.apache.xerces.validators.datatype.AbstractDatatypeValidator
getBaseValidator, getErrorString, getWSFacet, setLocale
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CY

protected static final int CY

M

protected static final int M

D

protected static final int D

h

protected static final int h

m

protected static final int m

s

protected static final int s

ms

protected static final int ms

utc

protected static final int utc

hh

protected static final int hh

mm

protected static final int mm

LESS_THAN

protected static final short LESS_THAN

EQUAL

protected static final short EQUAL

GREATER_THAN

protected static final short GREATER_THAN

TOTAL_SIZE

protected static final int TOTAL_SIZE

MONTH_SIZE

protected static final int MONTH_SIZE

YEAR

protected static final int YEAR

MONTH

protected static final int MONTH

DAY

protected static final int DAY

timeZone

protected int[] timeZone

fEnumSize

protected int fEnumSize

fEnd

protected int fEnd

fStart

protected int fStart

fBuffer

protected java.lang.StringBuffer fBuffer

fDateValue

protected int[] fDateValue

message

protected java.lang.StringBuffer message
Constructor Detail

DateTimeValidator

public DateTimeValidator()
                  throws InvalidDatatypeFacetException

DateTimeValidator

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

initializeValues

protected void initializeValues()
Overrides:
initializeValues in class AbstractNumericFacetValidator

assignAdditionalFacets

protected void assignAdditionalFacets(java.lang.String key,
                                      java.util.Hashtable facets)
                               throws InvalidDatatypeFacetException
Overrides:
assignAdditionalFacets in class AbstractNumericFacetValidator

compareValues

protected int compareValues(java.lang.Object value1,
                            java.lang.Object value2)
Overrides:
compareValues in class AbstractNumericFacetValidator

setMaxInclusive

protected void setMaxInclusive(java.lang.String value)
Overrides:
setMaxInclusive in class AbstractNumericFacetValidator

setMinInclusive

protected void setMinInclusive(java.lang.String value)
Overrides:
setMinInclusive in class AbstractNumericFacetValidator

setMaxExclusive

protected void setMaxExclusive(java.lang.String value)
Overrides:
setMaxExclusive in class AbstractNumericFacetValidator

setMinExclusive

protected void setMinExclusive(java.lang.String value)
Overrides:
setMinExclusive in class AbstractNumericFacetValidator

setEnumeration

protected void setEnumeration(java.util.Vector enumeration)
                       throws InvalidDatatypeValueException
Overrides:
setEnumeration in class AbstractNumericFacetValidator

getMaxInclusive

protected java.lang.String getMaxInclusive(boolean isBase)
Overrides:
getMaxInclusive in class AbstractNumericFacetValidator

getMinInclusive

protected java.lang.String getMinInclusive(boolean isBase)
Overrides:
getMinInclusive in class AbstractNumericFacetValidator

getMaxExclusive

protected java.lang.String getMaxExclusive(boolean isBase)
Overrides:
getMaxExclusive in class AbstractNumericFacetValidator

getMinExclusive

protected java.lang.String getMinExclusive(boolean isBase)
Overrides:
getMinExclusive in class AbstractNumericFacetValidator

checkContent

protected void checkContent(java.lang.String content,
                            java.lang.Object State,
                            java.util.Vector enum,
                            boolean asBase)
                     throws InvalidDatatypeValueException

parse

protected abstract int[] parse(java.lang.String content,
                               int[] date)
                        throws SchemaDateTimeException
Implemented by each subtype, calling appropriate function to parse given date/time
Parameters:
content - String value of the date/time
date - Storage to represent date/time object. If null - new object will be created, otherwise date will be reset and reused
Returns:
updated date/time object
Throws:
java.lang.Exception -  

validate

public java.lang.Object validate(java.lang.String content,
                                 java.lang.Object state)
                          throws InvalidDatatypeValueException
Validate that a string is a W3C date/time type
Overrides:
validate in class AbstractDatatypeValidator
Parameters:
content - string value of date/time
state -  
Returns:
 
Throws:
InvalidDatatypeValueException -  

validateDate

protected void validateDate(int[] date,
                            java.lang.String content)
                     throws InvalidDatatypeValueException
Validates date object against facet and base datatype
Parameters:
date - represents date/time obj
content - lexical representation of date/time obj
Throws:
InvalidDatatypeValueException -  

compare

public int compare(java.lang.String content1,
                   java.lang.String content2)
Description copied from interface: DatatypeValidator
Compares content in the Domain value vs. lexical value. e.g. If type is a float then 1.0 may be equivalent to 1 even tough both are lexically different.
Following copied from interface: org.apache.xerces.validators.datatype.DatatypeValidator
Parameters:
value1 -  
valu2 -  
Returns:
 

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class AbstractDatatypeValidator

compareDates

protected short compareDates(int[] date1,
                             int[] date2,
                             boolean strict)
Compare algorithm described in dateDime (3.2.7). Duration datatype overwrites this method
Parameters:
date1 - normalized date representation of the first value
date2 - normalized date representation of the second value
strict -  
Returns:
less, greater, less_equal, greater_equal, equal

compareOrder

protected short compareOrder(int[] date1,
                             int[] date2)
Given normalized values, determines order-relation between give date/time objects.
Parameters:
date1 - date/time object
date2 - date/time object
Returns:
 

getTime

protected void getTime(int start,
                       int end,
                       int[] data)
                throws java.lang.RuntimeException
Parses time hh:mm:ss.sss and time zone if any
Parameters:
start -  
end -  
data -  
Returns:
 
Throws:
java.lang.Exception -  

getDate

protected void getDate(int start,
                       int end,
                       int[] date)
                throws java.lang.RuntimeException
Parses date CCYY-MM-DD
Parameters:
start -  
end -  
data -  
Returns:
 
Throws:
java.lang.Exception -  

getYearMonth

protected void getYearMonth(int start,
                            int end,
                            int[] date)
                     throws java.lang.RuntimeException
Parses date CCYY-MM
Parameters:
start -  
end -  
data -  
Returns:
 
Throws:
java.lang.Exception -  

parseTimeZone

protected void parseTimeZone(int end,
                             int[] date)
                      throws java.lang.RuntimeException
Shared code from Date and YearMonth datatypes. Finds if time zone sign is present
Parameters:
end -  
date -  
Returns:
 
Throws:
java.lang.Exception -  

getTimeZone

protected void getTimeZone(int[] data,
                           int sign)
                    throws java.lang.RuntimeException
Parses time zone: 'Z' or {+,-} followed by hh:mm
Parameters:
data -  
sign -  
Returns:
 

indexOf

protected int indexOf(int start,
                      int end,
                      char ch)
Computes index of given char within StringBuffer
Parameters:
start -  
end -  
ch - character to look for in StringBuffer
Returns:
index of ch within StringBuffer

validateDateTime

protected void validateDateTime(int[] data)
Validates given date/time object accoring to W3C PR Schema [D.1 ISO 8601 Conventions]
Parameters:
data -  
Returns:
 

findUTCSign

protected int findUTCSign(int start,
                          int end)
Return index of UTC char: 'Z', '+', '-'
Parameters:
start -  
end -  
Returns:
 

parseInt

protected int parseInt(int start,
                       int end)
                throws java.lang.NumberFormatException
Given start and end position, parses string value
Parameters:
value - string to parse
start - Start position
end - end position
Returns:
return integer representation of characters

parseIntYear

protected int parseIntYear(int end)

normalize

protected void normalize(int[] date)
normalize dateTime [E Adding durations to dateTimes] If timezone present - normalize to UTC If hour is 24 - normalize to start of following day
Parameters:
date - CCYY-MM-DDThh:mm:ss+03
Returns:
CCYY-MM-DDThh:mm:ssZ

resetBuffer

protected void resetBuffer(java.lang.String str)
Resets fBuffer to store string representation of date/time
Parameters:
str - Lexical representation of date/time

resetDateObj

protected void resetDateObj(int[] data)
Resets object representation of date/time
Parameters:
data - date/time object

maxDayInMonthFor

protected int maxDayInMonthFor(int year,
                               int month)
Given {year,month} computes maximum number of days for given month
Parameters:
year -  
month -  
Returns:
 

mod

protected int mod(int a,
                  int b,
                  int quotient)

fQuotient

protected int fQuotient(int a,
                        int b)

modulo

protected int modulo(int temp,
                     int low,
                     int high)

fQuotient

protected int fQuotient(int temp,
                        int low,
                        int high)

dateToString

protected java.lang.String dateToString(int[] date)

reportError

protected void reportError(java.lang.String msg,
                           java.lang.String value)
Use this function to report errors in constructor
Parameters:
msg -  
value -  


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