You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/10/02 18:27:22 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes AbstractDateTimeDV.java AbstractStringDV.java Base64BinaryDV.java DateTimeDV.java DayDV.java FloatDV.java HexBinaryDV.java QNameDV.java StringDV.java
neilg 01/10/02 09:27:21
Added: java/src/org/apache/xerces/impl/v2/new_datatypes
AbstractDateTimeDV.java AbstractStringDV.java
Base64BinaryDV.java DateTimeDV.java DayDV.java
FloatDV.java HexBinaryDV.java QNameDV.java
StringDV.java
Log:
new datatype design code in the new package. Contributed by Neeraj Bajaj <ne...@sun.com> and Gopal Sharma <go...@sun.com>.
Revision Changes Path
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/AbstractDateTimeDV.java
Index: AbstractDateTimeDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
/**
* 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.
*
* @author Elena Litani
* @author Len Berman
* @author Gopal Sharma, SUN Microsystems Inc.
* @version $Id: AbstractDateTimeDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public abstract class AbstractDateTimeDV extends AbstractNumericDV {
//debugging
private static final boolean DEBUG=false;
//define shared variables for date/time
//To check order relation as per 3.2.7.3
public static final short INDETERMINATE=2;
//define constants
protected final static int CY = 0, M = 1, D = 2, h = 3,
m = 4, s = 5, ms = 6, utc=7, hh=0, mm=1;
//size for all objects must have the same fields:
//CCYY, MM, DD, h, m, s, ms + timeZone
protected final static int TOTAL_SIZE = 8;
//date obj size for gMonth datatype (without time zone): --09--
protected final static int MONTH_SIZE = 6;
//date obj must have at least 6 chars after year (without time zone): "-MM-DD"
private final static int YEARMONTH_SIZE = 7;
//define constants to be used in assigning default values for
//all date/time excluding duration
protected final static int YEAR=2001;
protected final static int MONTH=01;
protected final static int DAY = 15;
//obj to store timeZone for date/time object excluding duration
protected int[] timeZone;
//size of enumeration if any
protected int fEnumSize;
//size of string buffer
protected int fEnd;
protected int fStart;
//storage for string value of date/time object
protected StringBuffer fBuffer;
//obj to store all date/time objects with fields:
// {CY, M, D, h, m, s, ms, utc}
protected int[] fDateValue;
private int[] fTempDate;
//error message buffer
protected StringBuffer message;
protected void initializeValues(){
fDateValue = new int[TOTAL_SIZE];
fTempDate = new int[TOTAL_SIZE];
fEnd = 30;
fStart = 0;
message = new StringBuffer(TOTAL_SIZE);
fBuffer = new StringBuffer(fEnd);
timeZone = new int[2];
}
// the parameters are in compiled form (from getCompiledValue)
public boolean isEqual(Object value1, Object value2){
return compareDates((int[])value1,(int[])value2)==TypeValidator.COMPARE_EQUAL?true:false;
}//IsEqual()
// the parameters are in compiled form (from getCompiledValue)
public int compare (Object value1, Object value2) {
return compareDates((int[])value1, (int[])value2);
}//compare()
/**
* Implemented by each subtype, calling appropriate function to parse
* given date/time
*
* @param content String value of the date/time
* @param date Storage to represent date/time object.
* If null - new object will be created, otherwise
* date will be reset and reused
* @return updated date/time object
* @exception Exception
*/
abstract protected int[] parse (String content, int[] date) throws SchemaDateTimeException;
/**
* Compare algorithm described in dateDime (3.2.7).
* Duration datatype overwrites this method
*
* @param date1 normalized date representation of the first value
* @param date2 normalized date representation of the second value
* @param strict
* @return less, greater, less_equal, greater_equal, equal
*/
protected short compareDates(int[] date1, int[] date2) {
if ( date1[utc]==date2[utc] ) {
return compareOrder(date1, date2);
}
short c1, c2;
if ( date1[utc]=='Z' ) {
//compare date1<=date1<=(date2 with time zone -14)
//
cloneDate(date2); //clones date1 value to global temporary storage: fTempDate
timeZone[hh]=14;
timeZone[mm]=0;
fTempDate[utc]='+';
normalize(fTempDate);
c1 = compareOrder(date1, fTempDate);
//compare date1>=(date2 with time zone +14)
//
cloneDate(date2); //clones date1 value to global temporary storage: fTempDate
timeZone[hh]=14;
timeZone[mm]=0;
fTempDate[utc]='-';
normalize(fTempDate);
c2 = compareOrder(date1, fTempDate);
if ( (c1==TypeValidator.COMPARE_LESS && c2==TypeValidator.COMPARE_GREATER) ||
(c1==TypeValidator.COMPARE_GREATER && c2==TypeValidator.COMPARE_LESS) ) {
return INDETERMINATE;
}
//REVISIT: wait for clarification on this case from schema
return(c1!=INDETERMINATE)?c1:c2;
}
else if ( date2[utc]=='Z' ) {
//compare (date1 with time zone -14)<=date2
//
cloneDate(date1); //clones date1 value to global temporary storage: fTempDate
timeZone[hh]=14;
timeZone[mm]=0;
fTempDate[utc]='-';
if (DEBUG) {
System.out.println("fTempDate=" + dateToString(fTempDate));
}
normalize(fTempDate);
c1 = compareOrder(fTempDate, date2);
if (DEBUG) {
System.out.println("date=" + dateToString(date2));
System.out.println("fTempDate=" + dateToString(fTempDate));
}
//compare (date1 with time zone +14)<=date2
//
cloneDate(date1); //clones date1 value to global temporary storage: fTempDate
timeZone[hh]=14;
timeZone[mm]=0;
fTempDate[utc]='+';
normalize(fTempDate);
c2 = compareOrder(fTempDate, date2);
if (DEBUG) {
System.out.println("fTempDate=" + dateToString(fTempDate));
}
if ( (c1==TypeValidator.COMPARE_LESS && c2==TypeValidator.COMPARE_GREATER) ||
(c1==TypeValidator.COMPARE_GREATER && c2==TypeValidator.COMPARE_LESS) ) {
return INDETERMINATE;
}
//REVISIT: wait for clarification on this case from schema
return(c1!=INDETERMINATE)?c1:c2;
}
return INDETERMINATE;
}
/**
* Given normalized values, determines order-relation
* between give date/time objects.
*
* @param date1 date/time object
* @param date2 date/time object
* @return
*/
protected short compareOrder (int[] date1, int[] date2) {
for ( int i=0;i<TOTAL_SIZE;i++ ) {
if ( date1[i]<date2[i] ) {
return TypeValidator.COMPARE_LESS;
}
else if ( date1[i]>date2[i] ) {
return TypeValidator.COMPARE_GREATER;
}
}
return TypeValidator.COMPARE_EQUAL;
}
/**
* Parses time hh:mm:ss.sss and time zone if any
*
* @param start
* @param end
* @param data
* @return
* @exception Exception
*/
protected void getTime (int start, int end, int[] data) throws RuntimeException{
int stop = start+2;
//get hours (hh)
data[h]=parseInt(start,stop);
//get minutes (mm)
if (fBuffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
start = stop;
stop = stop+2;
data[m]=parseInt(start,stop);
//get seconds (ss)
if (fBuffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
start = stop;
stop = stop+2;
data[s]=parseInt(start,stop);
//get miliseconds (ms)
int milisec = indexOf(start, end, '.');
//find UTC sign if any
int sign = findUTCSign((milisec!=-1)?milisec:start, end);
//parse miliseconds
if ( milisec != -1 ) {
if ( sign<0 ) {
//get all digits after "."
data[ms]=parseInt(milisec+1,fEnd);
}
else {
//get ms before UTC sign
data[ms]=parseInt(milisec+1,sign);
}
}
//parse UTC time zone (hh:mm)
if ( sign>0 ) {
getTimeZone(data,sign);
}
}
/**
* Parses date CCYY-MM-DD
*
* @param start
* @param end
* @param data
* @return
* @exception Exception
*/
protected void getDate (int start, int end, int[] date) throws RuntimeException{
getYearMonth(start, end, date);
if (fBuffer.charAt(fStart++) !='-') {
throw new RuntimeException("CCYY-MM must be followed by '-' sign");
}
int stop = fStart + 2;
date[D]=parseInt(fStart, stop);
fStart = stop; //fStart points right after the Day
}
/**
* Parses date CCYY-MM
*
* @param start
* @param end
* @param data
* @return
* @exception Exception
*/
protected void getYearMonth (int start, int end, int[] date) throws RuntimeException{
if ( fBuffer.charAt(0)=='-' ) {
// REVISIT: date starts with preceding '-' sign
// do we have to do anything with it?
//
start++;
}
int i = indexOf(start, end, '-');
if ( i==-1 ) throw new RuntimeException("Year separator is missing or misplaced");
int length = i-start;
if (length<4) {
throw new RuntimeException("Year must have 'CCYY' format");
}
else if (length > 4 && fBuffer.charAt(start)=='0'){
throw new RuntimeException("Leading zeros are required if the year value would otherwise have fewer than four digits; otherwise they are forbidden");
}
date[CY]= parseIntYear(i);
if (fBuffer.charAt(i)!='-') {
throw new RuntimeException("CCYY must be followed by '-' sign");
}
start = ++i;
i = start +2;
date[M]=parseInt(start, i);
fStart = i; //fStart points right after the MONTH
}
/**
* Shared code from Date and YearMonth datatypes.
* Finds if time zone sign is present
*
* @param end
* @param date
* @return
* @exception Exception
*/
protected void parseTimeZone (int end, int[] date) throws RuntimeException{
//fStart points right after the date
if ( fStart<fEnd ) {
int sign = findUTCSign(fStart, fEnd);
if ( sign<0 ) {
throw new RuntimeException ("Error in month parsing");
}
else {
getTimeZone(date, sign);
}
}
}
/**
* Parses time zone: 'Z' or {+,-} followed by hh:mm
*
* @param data
* @param sign
* @return
*/
protected void getTimeZone (int[] data, int sign) throws RuntimeException{
data[utc]=fBuffer.charAt(sign);
if ( fBuffer.charAt(sign) == 'Z' ) {
if (fEnd>(++sign)) {
throw new RuntimeException("Error in parsing time zone");
}
return;
}
if ( sign<=(fEnd-6) ) {
//parse [hh]
int stop = ++sign+2;
timeZone[hh]=parseInt(sign, stop);
if (fBuffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
//parse [ss]
timeZone[mm]=parseInt(stop, stop+2);
if ( stop+2!=fEnd ) {
throw new RuntimeException("Error in parsing time zone");
}
}
else {
throw new RuntimeException("Error in parsing time zone");
}
if ( DEBUG ) {
System.out.println("time[hh]="+timeZone[hh] + " time[mm]=" +timeZone[mm]);
}
}
/**
* Computes index of given char within StringBuffer
*
* @param start
* @param end
* @param ch character to look for in StringBuffer
* @return index of ch within StringBuffer
*/
protected int indexOf (int start, int end, char ch) {
for ( int i=start;i<end;i++ ) {
if ( fBuffer.charAt(i) == ch ) {
return i;
}
}
return -1;
}
/**
* Validates given date/time object accoring to W3C PR Schema
* [D.1 ISO 8601 Conventions]
*
* @param data
* @return
*/
protected void validateDateTime (int[] data) {
//REVISIT: should we throw an exception for not valid dates
// or reporting an error message should be sufficient?
if ( data[CY]==0 ) {
throw new RuntimeException("The year \"0000\" is an illegal year value");
}
if ( data[M]<1 || data[M]>12 ) {
throw new RuntimeException("The month must have values 1 to 12");
}
//validate days
if ( data[D]>maxDayInMonthFor(data[CY], data[M]) || data[D]<1 ) {
throw new RuntimeException("The day must have values 1 to 31");
}
//validate hours
if ( data[h]>23 || data[h]<0 ) {
throw new RuntimeException("Hour must have values 0-23");
}
//validate
if ( data[m]>59 || data[m]<0 ) {
throw new RuntimeException("Minute must have values 0-59");
}
//validate
if ( data[s]>60 || data[s]<0 ) {
throw new RuntimeException("Second must have values 0-60");
}
//validate
if ( timeZone[hh]>14 || timeZone[hh]<-14 ) {
throw new RuntimeException("Time zone should have range -14..+14");
}
//validate
if ( timeZone[mm]>59 || timeZone[mm]<-59 ) {
throw new RuntimeException("Minute must have values 0-59");
}
}
/**
* Return index of UTC char: 'Z', '+', '-'
*
* @param start
* @param end
* @return
*/
protected int findUTCSign (int start, int end) {
int c;
for ( int i=start;i<end;i++ ) {
c=fBuffer.charAt(i);
if ( c == 'Z' || c=='+' || c=='-' ) {
return i;
}
}
return -1;
}
/**
* Given start and end position, parses string value
*
* @param value string to parse
* @param start Start position
* @param end end position
* @return return integer representation of characters
*/
protected int parseInt (int start, int end)
throws NumberFormatException{
//REVISIT: more testing on this parsing needs to be done.
int radix=10;
int result = 0;
int digit=0;
int limit = -Integer.MAX_VALUE;
int multmin = limit / radix;
int i = start;
do {
digit = Character.digit(fBuffer.charAt(i),radix);
if ( digit < 0 ) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
if ( result < multmin ) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
result *= radix;
if ( result < limit + digit ) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
result -= digit;
}while ( ++i < end );
return -result;
}
// parse Year differently to support negative value.
protected int parseIntYear (int end){
int radix=10;
int result = 0;
boolean negative = false;
int i=0;
int limit;
int multmin;
int digit=0;
if (fBuffer.charAt(0) == '-'){
negative = true;
limit = Integer.MIN_VALUE;
i++;
}
else{
limit = -Integer.MAX_VALUE;
}
multmin = limit / radix;
while (i < end)
{
digit = Character.digit(fBuffer.charAt(i++),radix);
if (digit < 0) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
if (result < multmin) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
result *= radix;
if (result < limit + digit) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
result -= digit;
}
if (negative)
{
if (i > 1) return result;
else throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
}
return -result;
}
/**
* If timezone present - normalize dateTime [E Adding durations to dateTimes]
*
* @param date CCYY-MM-DDThh:mm:ss+03
* @return CCYY-MM-DDThh:mm:ssZ
*/
protected void normalize (int[] date) {
// REVISIT: we have common code in addDuration() for durations
// should consider reorganizing it.
//
//add minutes (from time zone)
int negate = 1;
if (date[utc]=='+') {
negate = -1;
}
if ( DEBUG ) {
System.out.println("==>date[m]"+date[m]);
System.out.println("==>timeZone[mm]" +timeZone[mm]);
}
int temp = date[m] + negate*timeZone[mm];
int carry = fQuotient (temp, 60);
date[m]= mod(temp, 60, carry);
if ( DEBUG ) {
System.out.println("==>carry: " + carry);
}
//add hours
temp = date[h] + negate*timeZone[hh] + carry;
carry = fQuotient(temp, 24);
date[h]=mod(temp, 24, carry);
if ( DEBUG ) {
System.out.println("==>date[h]"+date[h]);
System.out.println("==>carry: " + carry);
}
date[D]=date[D]+carry;
while ( true ) {
temp=maxDayInMonthFor(date[CY], date[M]);
if (date[D]<1) {
date[D] = date[D] + maxDayInMonthFor(date[CY], date[M]-1);
carry=-1;
}
else if ( date[D]>temp ) {
date[D]=date[D]-temp;
carry=1;
}
else {
break;
}
temp=date[M]+carry;
date[M]=modulo(temp, 1, 13);
date[CY]=date[CY]+fQuotient(temp, 1, 13);
}
date[utc]='Z';
}
/**
* Resets fBuffer to store string representation of
* date/time
*
* @param str Lexical representation of date/time
*/
protected void resetBuffer (String str) {
fBuffer.setLength(0);
fStart=fEnd=0;
timeZone[hh]=timeZone[mm]=0;
fBuffer.append(str);
fEnd = fBuffer.length();
}
/**
* Resets object representation of date/time
*
* @param data date/time object
*/
protected void resetDateObj (int[] data) {
for ( int i=0;i<TOTAL_SIZE;i++ ) {
data[i]=0;
}
}
/**
* Given {year,month} computes maximum
* number of days for given month
*
* @param year
* @param month
* @return
*/
protected int maxDayInMonthFor(int year, int month) {
//validate days
if ( month==4 || month==6 || month==9 || month==11 ) {
return 30;
}
else if ( month==2 ) {
if ( isLeapYear(year) ) {
return 29;
}
else {
return 28;
}
}
else {
return 31;
}
}
private boolean isLeapYear(int year) {
//REVISIT: should we take care about Julian calendar?
return((year%4 == 0) && ((year%100 != 0) || (year%400 == 0)));
}
//
// help function described in W3C PR Schema [E Adding durations to dateTimes]
//
protected int mod (int a, int b, int quotient) {
//modulo(a, b) = a - fQuotient(a,b)*b
return (a - quotient*b) ;
}
//
// help function described in W3C PR Schema [E Adding durations to dateTimes]
//
protected int fQuotient (int a, int b) {
//fQuotient(a, b) = the greatest integer less than or equal to a/b
return (int)Math.floor((float)a/b);
}
//
// help function described in W3C PR Schema [E Adding durations to dateTimes]
//
protected int modulo (int temp, int low, int high) {
//modulo(a - low, high - low) + low
int a = temp - low;
int b = high - low;
return (mod (a, b, fQuotient(a, b)) + low) ;
}
//
// help function described in W3C PR Schema [E Adding durations to dateTimes]
//
protected int fQuotient (int temp, int low, int high) {
//fQuotient(a - low, high - low)
return fQuotient(temp - low, high - low);
}
protected String dateToString(int[] date) {
message.setLength(0);
message.append(date[CY]);
message.append('-');
message.append(date[M]);
message.append('-');
message.append(date[D]);
message.append('T');
message.append(date[h]);
message.append(':');
message.append(date[m]);
message.append(':');
message.append(date[s]);
message.append('.');
message.append(date[ms]);
message.append((char)date[utc]);
return message.toString();
}
/**
* Use this function to report errors in constructor
*
* @param msg
* @param value
*/
protected void reportError(String msg, String value) {
System.err.println("[Error]: " +msg+": Value '"+value+"' is not legal for current datatype");
}
//
//Private help functions
//
private void cloneDate (int[] finalValue) {
resetDateObj(fTempDate);
for ( int i=0;i<TOTAL_SIZE;i++ ) {
fTempDate[i]=finalValue[i];
}
}
}
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/AbstractStringDV.java
Index: AbstractStringDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
import java.util.Locale;
/**
* @version $Id: AbstractStringDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public abstract class AbstractStringDV implements TypeValidator{
protected DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
protected Locale fLocale = null;
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public abstract short getPrimitiveDV();
// return the facets allowed ; string, hexBinary, base64Binary, anyURI, Qname, Notation all have same set of factes allowed.
public short getAllowedFacets(){
return (XSSimpleTypeDecl.DEFINED_LENGTH | XSSimpleTypeDecl.DEFINED_MINLENGTH | XSSimpleTypeDecl.DEFINED_MAXLENGTH | XSSimpleTypeDecl.DEFINED_PATTERN | XSSimpleTypeDecl.DEFINED_ENUMERATION | XSSimpleTypeDecl.DEFINED_WHITESPACE );
}
// convert a string to a compiled form. for example,
// for number types (decimal, double, float, and types derived from them),
// get the BigDecimal, Double, Flout object.
// for some types (string and derived), they just return the string itself
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
return content;
}
// the parameters are in compiled form (from getCompiledValue)
public boolean isEqual(Object value1, Object value2){
return ((String)value1).equals((String)value2);
}
// the following methods might not be supported by every DV.
// but XSSimpleTypeDecl should know which type supports which methods,
// and it's an *internal* error if a method is called on a DV that
// doesn't support it.
public abstract int compare(Object value1, Object value2);
// the parameters are in compiled form (from getCompiledValue)
public int getDataLength(Object value){
return -1;
}
// the parameters are in compiled form (from getCompiledValue)
public int getTotalDigits(Object value){
return -1;
}
// the parameters are in compiled form (from getCompiledValue)
public int getFractionDigits(Object value){
return -1;
}
protected String getErrorString(String key, Object args[]) {
try {
return fMessageProvider.formatMessage(fLocale, key, args);
}
catch ( Exception e ) {
return "Illegal Errorcode "+key;
}
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
fLocale = locale;
}
} // class AbstractStringDV
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/Base64BinaryDV.java
Index: Base64BinaryDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
//internal imports
import org.apache.xerces.impl.v2.util.Base64;
//java imports
import java.io.UnsupportedEncodingException;
/**
* @version $Id: Base64BinaryDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class Base64BinaryDV extends AbstractStringDV{
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_BASE64BINARY;
}
// convert a string to a compiled form. for example,
// for number types (decimal, double, float, and types derived from them),
// get the BigDecimal, Double, Flout object.
// for some types (string and derived), they just return the string itself
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
if (getDataLength(content) < 0) {
throw new InvalidDatatypeValueException( "Value '"+content+"' is not encoded in Hex" );
}
return content;
}
// the parameters are in compiled form (from getCompiledValue)
public boolean isEqual(Object value1, Object value2){
return compare(value1,value2) == 0 ? true : false;
}//isEqual()
// the following methods might not be supported by every DV.
// but XSSimpleTypeDecl should know which type supports which methods,
// and it's an *internal* error if a method is called on a DV that
// doesn't support it.
//compiled value is string in this case ,as we return string for all derived by string.
public int compare(Object value1, Object value2){
String str1 = (String)value1;
String str2 = (String)value2;
if (str1 == null || str2 == null)
return -1;
if (str1 == str2 || str1.equals(str2))
return 0;
byte[] data1= Base64.decode(str1.getBytes());
byte[] data2= Base64.decode(str2.getBytes());
if (data1 == null || data2 == null)
return -1;
for (int i = 0; i < Math.min(data1.length, data2.length); i++){
if (data1[i] < data2[i])
return -1;
else if (data1[i] > data2[i])
return 1;
}
if (data1.length == data2.length)
return 0;
return data1.length > data2.length ? 1 : -1;
}//compare()
//compiled value is string in this case ,as we return string for all derived by string.
//for base64 length is measured in octets of binary data.
public int getDataLength(Object value){
int x = -1;
String content = (String)value;
try {
x = Base64.getDecodedDataLength(content.getBytes("utf-8"));
}
catch (UnsupportedEncodingException e) {
}
finally {
return x;
}
}//getDataLength()
} // class Base64BinaryDV
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/DateTimeDV.java
Index: DateTimeDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
/**
* Validator for <dateTime> datatype (W3C Schema Datatypes)
*
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
* @version $Id: DateTimeDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class DateTimeDV extends AbstractDateTimeDV {
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_DATETIME;
}
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
int[] date;
try{
date= parse(content, null);
}catch(Exception ex){
}
return date;
}
/**
* Parses, validates and computes normalized version of dateTime object
*
* @param str The lexical representation of dateTime object CCYY-MM-DDThh:mm:ss.sss
* with possible time zone Z or (-),(+)hh:mm
* @param date uninitialized date object
* @return normalized dateTime representation
* @exception Exception Invalid lexical representation
*/
protected int[] parse(String str, int[] date) throws SchemaDateTimeException{
resetBuffer(str);
//create structure to hold an object
if ( date == null ) {
date = new int[TOTAL_SIZE];
}
resetDateObj(date);
int end = indexOf (fStart, fEnd, 'T');
// both time and date
getDate(fStart, end, date);
getTime(end+1, fEnd, date);
//validate and normalize
//REVISIT: do we need SchemaDateTimeException?
validateDateTime(date);
if ( date[utc]!=0 && date[utc]!='Z') {
normalize(date);
}
return date;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/DayDV.java
Index: DayDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
/**
* Validator for <gDay> datatype (W3C Schema datatypes)
*
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
* @version $Id: DayDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class DayDV extends AbstractDateTimeDV{
//size without time zone: ---09
private final static int DAY_SIZE=5;
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_GDAY;
}
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
int[] date;
try{
date= parse(content, null);
}catch(Exception ex){
}
return date;
}
/**
* Parses, validates and computes normalized version of gDay object
*
* @param str The lexical representation of gDay object ---DD
* with possible time zone Z or (-),(+)hh:mm
* Pattern: ---(\\d\\d)(Z|(([-+])(\\d\\d)(:(\\d\\d))?
* @param date uninitialized date object
* @return normalized date representation
* @exception Exception Invalid lexical representation
*/
protected int[] parse(String str, int[] date) throws SchemaDateTimeException{
resetBuffer(str);
//create structure to hold an object
if ( date== null ) {
date=new int[TOTAL_SIZE];
}
resetDateObj(date);
if (fBuffer.charAt(0)!='-' || fBuffer.charAt(1)!='-' || fBuffer.charAt(2)!='-') {
throw new SchemaDateTimeException ("Error in day parsing");
}
//initialize values
date[CY]=YEAR;
date[M]=MONTH;
date[D]=parseInt(fStart+3,fStart+5);
if ( DAY_SIZE<fEnd ) {
int sign = findUTCSign(DAY_SIZE, fEnd);
if ( sign<0 ) {
throw new SchemaDateTimeException ("Error in day parsing");
}
else {
getTimeZone(date, sign);
}
}
//validate and normalize
validateDateTime(date);
if ( date[utc]!=0 && date[utc]!='Z' ) {
normalize(date);
}
return date;
}
/**
* Converts gDay object representation to String
*
* @param date gDay object
* @return lexical representation of gDay: ---DD with an optional time zone sign
*/
protected String dateToString(int[] date) {
message.setLength(0);
message.append('-');
message.append('-');
message.append('-');
message.append(date[D]);
message.append((char)date[utc]);
return message.toString();
}
}
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/FloatDV.java
Index: FloatDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
//internal imports
import org.apache.xerces.impl.v2.XSSimpleTypeDecl;
//java import
/**
* @version $Id: FloatDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class FloatDV extends AbstractNumericDV{
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_FLOAT;
}
//convert a String to Float form, we have to take care of cases specified in spec like INF, -INF and NaN
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
Float compiledValue = null;
try{
compiledValue = fValueOf(content);
}catch(Exception ex){
String msg = getErrorString(
DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.NOT_FLOAT ],
new Object[] { "'" + content +"'"});
throw new InvalidDatatypeValueException(msg);
}
return compiledValue;
}//getCompiledValue()
// Float equals method takes care of cases specified for Float in schema spec.
public boolean isEqual(Object value1, Object value2){
if(value1 instanceof Float && value2 instanceof Float)
return ((Float)value1).equals((Float)value2);
else //REVISIT: should we throw error for not getting right object or to be taken care in XSSimpleTypeDecl.
return false;
}//isEqual()
// the following methods might not be supported by every DV.
// but XSSimpleTypeDecl should know which type supports which methods,
// and it's an *internal* error if a method is called on a DV that
// doesn't support it.
// Float compareTo method takes care of cases specified for Float in schema spec.
public int compare(Object value1, Object value2){
if(value1 instanceof Float && value2 instanceof Float)
return ((Float)value1).compareTo((Float)value2) ;
else
return -1;
}//compare()
//takes care of special values positive, negative infinity and Not a Number as per the spec.
private static Float fValueOf(String s) throws NumberFormatException {
Float f=null;
try {
f = Float.valueOf(s);
}
catch ( NumberFormatException nfe ) {
if ( s.equals("INF") ) {
f = new Float(Float.POSITIVE_INFINITY);
}
else if ( s.equals("-INF") ) {
f = new Float (Float.NEGATIVE_INFINITY);
}
else if ( s.equals("NaN" ) ) {
f = new Float (Float.NaN);
}
else {
throw nfe;
}
}
return f;
}
} // class FloatDV
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/HexBinaryDV.java
Index: HexBinaryDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
//internal imports
import org.apache.xerces.impl.v2.util.HexBin;
//java imports
import java.io.UnsupportedEncodingException;
/**
* @version $Id: HexBinaryDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class HexBinaryDV extends AbstractStringDV{
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_HEXBINARY;
}
// convert a string to a compiled form. for example,
// for number types (decimal, double, float, and types derived from them),
// get the BigDecimal, Double, Flout object.
// for some types (string and derived), they just return the string itself
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
if (getDataLength(content) < 0) {
throw new InvalidDatatypeValueException( "Value '"+content+"' is not encoded in Hex" );
}
return content;
}
// the parameters are in compiled form (from getCompiledValue)
public boolean isEqual(Object value1, Object value2){
return compare(value1,value2) == 0 ? true : false;
}//isEqual()
// the following methods might not be supported by every DV.
// but XSSimpleTypeDecl should know which type supports which methods,
// and it's an *internal* error if a method is called on a DV that
// doesn't support it.
//compiled value is string in this case ,as we return string for all derived by string.
public int compare(Object value1, Object value2){
String str1 = (String)value1;
String str2 = (String)value2;
if (str1 == null || str2 == null)
return -1;
if (str1 == str2 || str1.equals(str2))
return 0;
byte[] data1=HexBin.decode(str1.getBytes());
byte[] data2=HexBin.decode(str2.getBytes());
if (data1 == null || data2 == null)
return -1;
for (int i = 0; i < Math.min(data1.length, data2.length); i++){
if (data1[i] < data2[i])
return -1;
else if (data1[i] > data2[i])
return 1;
}
if (data1.length == data2.length)
return 0;
return data1.length > data2.length ? 1 : -1;
}//compare()
//compiled value is string in this case ,as we return string for all derived by string.
//for hex bin length is measured in octets of binary data.
public int getDataLength(Object value){
int x = -1;
String content = (String)value;
try {
x = HexBin.getDecodedDataLength(content.getBytes("utf-8"));
}
catch (UnsupportedEncodingException e) {
}
finally {
return x;
}
}//getDataLength()
} // class AbstractStringDV
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/QNameDV.java
Index: QNameDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
//internal imports
import org.apache.xerces.util.XMLChar;
import java.util.Locale;
import java.text.Collator;
/**
* @version $Id: QNameDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class QNameDV extends AbstractStringDV{
protected DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
protected Locale fLocale = null;
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_QNAME;
}
// convert a string to a compiled form. for example,
// for number types (decimal, double, float, and types derived from them),
// get the BigDecimal, Double, Flout object.
// for some types (string and derived), they just return the string itself
public Object getCompiledValue(String content) throws InvalidDatatypeValueException{
//NCNames check should be done here.
boolean NCName = false;
int posColon = content.indexOf(':');
if (posColon >= 0){
if( !XMLChar.isValidNCName(content.substring(0,posColon)) ||
!XMLChar.isValidNCName(content.substring(posColon+1))){
NCName = false;
}
}
if(!NCName)
throw new InvalidDatatypeValueException("Value '"+content+"' is not a valid QName");
return content;
}//getCompiledValue()
// the parameters are in compiled form (from getCompiledValue)
public boolean isEqual(Object value1, Object value2){
return ((String)value1).equals((String)value2);
}
// the following methods might not be supported by every DV.
// but XSSimpleTypeDecl should know which type supports which methods,
// and it's an *internal* error if a method is called on a DV that
// doesn't support it.
public int compare(Object value1, Object value2) {
Locale loc = Locale.getDefault();
Collator collator = Collator.getInstance( loc );
return collator.compare( (String)value1 , (String)value2 );
}
} // class QNameDVDV
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/StringDV.java
Index: StringDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
/**
* @version $Id: StringDV.java,v 1.1 2001/10/02 16:27:20 neilg Exp $
*/
public class StringDV extends AbstractStringDV{
// for most DV classes, this is the same as the DV_?? value defined
// in XSSimpleTypeDecl that's corresponding to that class. But for
// ID/IDREF/ENTITY, the privitivaDV is DV_STRING.
public short getPrimitiveDV(){
return XSSimpleTypeDecl.DV_STRING;
}//getPrimitiveDV()
// the following methods might not be supported by every DV.
// but XSSimpleTypeDecl should know which type supports which methods,
// and it's an *internal* error if a method is called on a DV that
// doesn't support it.
public int compare(Object value1, Object value2){
return ((String)value1).equals((String)value2) ? 0 :-1 ;
}
} // class StringDV
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org