FileDocCategorySizeDatePackage
YearDV.javaAPI DocJava SE 5 API5344Fri Aug 26 14:55:48 BST 2005com.sun.org.apache.xerces.internal.impl.dv.xs

YearDV

public class YearDV extends AbstractDateTimeDV
Validator for datatype (W3C Schema Datatypes)
author
Elena Litani
author
Gopal Sharma, SUN Microsystem Inc.
version
$Id: YearDV.java,v 1.7 2003/01/16 18:34:04 sandygao Exp $

Fields Summary
Constructors Summary
Methods Summary
protected java.lang.StringdateToString(int[] date)
Converts year object representation to String

param
date year object
return
lexical representation of month: CCYY with optional time zone sign

        StringBuffer message = new StringBuffer(5);
        append(message, date[CY], 4);
        append(message, (char)date[utc], 0);
        return message.toString();
    
public java.lang.ObjectgetActualValue(java.lang.String content, com.sun.org.apache.xerces.internal.impl.dv.ValidationContext context)
Convert a string to a compiled form

param
content The lexical representation of time
return
a valid and normalized time object

        try{
            return new DateTimeData(parse(content), this);
        } catch(Exception ex){
            throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYear"});
        }
    
protected int[]parse(java.lang.String str)
Parses, validates and computes normalized version of gYear object

param
str The lexical representation of year object CCYY with possible time zone Z or (-),(+)hh:mm
param
date uninitialized date object
return
normalized date representation
exception
SchemaDateTimeException Invalid lexical representation

        int len = str.length();
        int[] date = new int[TOTAL_SIZE];
        int[] timeZone = new int[2];

        // check for preceding '-' sign
        int start = 0;
        if (str.charAt(0)=='-") {
            start = 1;
        }
        int sign = findUTCSign(str, start, len);
        if (sign == -1) {
            date[CY]=parseIntYear(str, len);
        }
        else {
            date[CY]=parseIntYear(str, sign);
            getTimeZone (str, date, sign, len, timeZone);
        }

        //initialize values
        date[M]=MONTH;
        date[D]=1;

        //validate and normalize
        validateDateTime(date, timeZone);

        if ( date[utc]!=0 && date[utc]!='Z" ) {
            normalize(date, timeZone);
        }
        return date;