You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2002/04/26 22:33:50 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv/xs AbstractDateTimeDV.java DateDV.java DateTimeDV.java DayDV.java DurationDV.java MonthDV.java MonthDayDV.java TimeDV.java YearDV.java YearMonthDV.java
sandygao 02/04/26 13:33:49
Modified: java/src/org/apache/xerces/impl/dv/xs
AbstractDateTimeDV.java DateDV.java DateTimeDV.java
DayDV.java DurationDV.java MonthDV.java
MonthDayDV.java TimeDV.java YearDV.java
YearMonthDV.java
Log:
1. only #x30~#x39 are allowed in data&time values.
2. remove instance variables, so that the simple type objects can be safely
used in multiple-thread environment.
Revision Changes Path
1.5 +83 -162 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java
Index: AbstractDateTimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractDateTimeDV.java 21 Mar 2002 17:07:38 -0000 1.4
+++ AbstractDateTimeDV.java 26 Apr 2002 20:33:49 -0000 1.5
@@ -74,7 +74,7 @@
* @author Len Berman
* @author Gopal Sharma, SUN Microsystems Inc.
*
- * @version $Id: AbstractDateTimeDV.java,v 1.4 2002/03/21 17:07:38 sandygao Exp $
+ * @version $Id: AbstractDateTimeDV.java,v 1.5 2002/04/26 20:33:49 sandygao Exp $
*/
public abstract class AbstractDateTimeDV extends TypeValidator {
@@ -94,55 +94,16 @@
//date obj size for gMonth datatype (without time zone): --09
protected final static int MONTH_SIZE = 4;
- //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 YEAR=2000;
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;
-
- public AbstractDateTimeDV(){
- initializeValues();
- }
-
- 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];
- }
-
public short getAllowedFacets(){
return ( XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_WHITESPACE | XSSimpleTypeDecl.FACET_ENUMERATION |XSSimpleTypeDecl.FACET_MAXINCLUSIVE |XSSimpleTypeDecl.FACET_MININCLUSIVE | XSSimpleTypeDecl.FACET_MAXEXCLUSIVE | XSSimpleTypeDecl.FACET_MINEXCLUSIVE );
}//getAllowedFacets()
-
// the parameters are in compiled form (from getActualValue)
public boolean isEqual(Object value1, Object value2){
if (!(value1 instanceof int[]) || !(value2 instanceof int[]))
@@ -156,19 +117,6 @@
}//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 SchemaDateTimeException
- */
- abstract protected int[] parse (String content, int[] date) throws SchemaDateTimeException;
-
- /**
* Compare algorithm described in dateDime (3.2.7).
* Duration datatype overwrites this method
*
@@ -182,26 +130,29 @@
return compareOrder(date1, date2);
}
short c1, c2;
+
+ int[] tempDate = new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
if ( date1[utc]=='Z' ) {
//compare date1<=date1<=(date2 with time zone -14)
//
- cloneDate(date2); //clones date1 value to global temporary storage: fTempDate
+ cloneDate(date2, tempDate); //clones date1 value to global temporary storage: fTempDate
timeZone[hh]=14;
timeZone[mm]=0;
- fTempDate[utc]='+';
- normalize(fTempDate);
- c1 = compareOrder(date1, fTempDate);
+ tempDate[utc]='+';
+ normalize(tempDate, timeZone);
+ c1 = compareOrder(date1, tempDate);
//compare date1>=(date2 with time zone +14)
//
- cloneDate(date2); //clones date1 value to global temporary storage: fTempDate
+ cloneDate(date2, tempDate); //clones date1 value to global temporary storage: tempDate
timeZone[hh]=14;
timeZone[mm]=0;
- fTempDate[utc]='-';
- normalize(fTempDate);
- c2 = compareOrder(date1, fTempDate);
+ tempDate[utc]='-';
+ normalize(tempDate, timeZone);
+ c2 = compareOrder(date1, tempDate);
if ( (c1 < 0 && c2 > 0) ||
(c1 == 0 && c2 == 0) ) {
@@ -214,30 +165,30 @@
//compare (date1 with time zone -14)<=date2
//
- cloneDate(date1); //clones date1 value to global temporary storage: fTempDate
+ cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate
timeZone[hh]=14;
timeZone[mm]=0;
- fTempDate[utc]='-';
+ tempDate[utc]='-';
if (DEBUG) {
- System.out.println("fTempDate=" + dateToString(fTempDate));
+ System.out.println("tempDate=" + dateToString(tempDate));
}
- normalize(fTempDate);
- c1 = compareOrder(fTempDate, date2);
+ normalize(tempDate, timeZone);
+ c1 = compareOrder(tempDate, date2);
if (DEBUG) {
System.out.println("date=" + dateToString(date2));
- System.out.println("fTempDate=" + dateToString(fTempDate));
+ System.out.println("tempDate=" + dateToString(tempDate));
}
//compare (date1 with time zone +14)<=date2
//
- cloneDate(date1); //clones date1 value to global temporary storage: fTempDate
+ cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate
timeZone[hh]=14;
timeZone[mm]=0;
- fTempDate[utc]='+';
- normalize(fTempDate);
- c2 = compareOrder(fTempDate, date2);
+ tempDate[utc]='+';
+ normalize(tempDate, timeZone);
+ c2 = compareOrder(tempDate, date2);
if (DEBUG) {
- System.out.println("fTempDate=" + dateToString(fTempDate));
+ System.out.println("tempDate=" + dateToString(tempDate));
}
if ( (c1 < 0 && c2 > 0) ||
(c1 == 0 && c2 == 0) ) {
@@ -279,35 +230,35 @@
* @param data
* @exception RuntimeException
*/
- protected void getTime (int start, int end, int[] data) throws RuntimeException{
+ protected void getTime (String buffer, int start, int end, int[] data, int[] timeZone) throws RuntimeException{
int stop = start+2;
//get hours (hh)
- data[h]=parseInt(start,stop);
+ data[h]=parseInt(buffer, start,stop);
//get minutes (mm)
- if (fBuffer.charAt(stop++)!=':') {
+ if (buffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
start = stop;
stop = stop+2;
- data[m]=parseInt(start,stop);
+ data[m]=parseInt(buffer, start,stop);
//get seconds (ss)
- if (fBuffer.charAt(stop++)!=':') {
+ if (buffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
start = stop;
stop = stop+2;
- data[s]=parseInt(start,stop);
+ data[s]=parseInt(buffer, start,stop);
//get miliseconds (ms)
- int milisec = indexOf(start, end, '.');
+ int milisec = indexOf(buffer, start, end, '.');
//find UTC sign if any
- int sign = findUTCSign((milisec!=-1)?milisec:start, end);
+ int sign = findUTCSign(buffer, (milisec!=-1)?milisec:start, end);
//parse miliseconds
if ( milisec != -1 ) {
@@ -315,19 +266,19 @@
if ( sign<0 ) {
//get all digits after "."
- data[ms]=parseInt(milisec+1,fEnd);
+ data[ms]=parseInt(buffer, milisec+1, buffer.length());
}
else {
//get ms before UTC sign
- data[ms]=parseInt(milisec+1,sign);
+ data[ms]=parseInt(buffer, milisec+1,sign);
}
}
//parse UTC time zone (hh:mm)
if ( sign>0 ) {
- getTimeZone(data,sign);
+ getTimeZone(buffer, data, sign, end, timeZone);
}
}
@@ -339,16 +290,16 @@
* @param data
* @exception RuntimeException
*/
- protected void getDate (int start, int end, int[] date) throws RuntimeException{
+ protected int getDate (String buffer, int start, int end, int[] date) throws RuntimeException{
- getYearMonth(start, end, date);
+ start = getYearMonth(buffer, start, end, date);
- if (fBuffer.charAt(fStart++) !='-') {
+ if (buffer.charAt(start++) !='-') {
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
+ int stop = start + 2;
+ date[D]=parseInt(buffer, start, stop);
+ return stop;
}
/**
@@ -359,31 +310,31 @@
* @param data
* @exception RuntimeException
*/
- protected void getYearMonth (int start, int end, int[] date) throws RuntimeException{
+ protected int getYearMonth (String buffer, int start, int end, int[] date) throws RuntimeException{
- if ( fBuffer.charAt(0)=='-' ) {
+ if ( buffer.charAt(0)=='-' ) {
// REVISIT: date starts with preceding '-' sign
// do we have to do anything with it?
//
start++;
}
- int i = indexOf(start, end, '-');
+ int i = indexOf(buffer, 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'){
+ else if (length > 4 && buffer.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)!='-') {
+ date[CY]= parseIntYear(buffer, i);
+ if (buffer.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
+ date[M]=parseInt(buffer, start, i);
+ return i; //fStart points right after the MONTH
}
/**
@@ -394,17 +345,17 @@
* @param date
* @exception RuntimeException
*/
- protected void parseTimeZone (int end, int[] date) throws RuntimeException{
+ protected void parseTimeZone (String buffer, int start, int end, int[] date, int[] timeZone) throws RuntimeException{
//fStart points right after the date
- if ( fStart<fEnd ) {
- int sign = findUTCSign(fStart, fEnd);
+ if ( start<end ) {
+ int sign = findUTCSign(buffer, start, end);
if ( sign<0 ) {
throw new RuntimeException ("Error in month parsing");
}
else {
- getTimeZone(date, sign);
+ getTimeZone(buffer, date, sign, end, timeZone);
}
}
}
@@ -416,28 +367,28 @@
* @param sign
* @exception RuntimeException
*/
- protected void getTimeZone (int[] data, int sign) throws RuntimeException{
- data[utc]=fBuffer.charAt(sign);
+ protected void getTimeZone (String buffer, int[] data, int sign, int end, int[] timeZone) throws RuntimeException{
+ data[utc]=buffer.charAt(sign);
- if ( fBuffer.charAt(sign) == 'Z' ) {
- if (fEnd>(++sign)) {
+ if ( buffer.charAt(sign) == 'Z' ) {
+ if (end>(++sign)) {
throw new RuntimeException("Error in parsing time zone");
}
return;
}
- if ( sign<=(fEnd-6) ) {
+ if ( sign<=(end-6) ) {
//parse [hh]
int stop = ++sign+2;
- timeZone[hh]=parseInt(sign, stop);
- if (fBuffer.charAt(stop++)!=':') {
+ timeZone[hh]=parseInt(buffer, sign, stop);
+ if (buffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
//parse [ss]
- timeZone[mm]=parseInt(stop, stop+2);
+ timeZone[mm]=parseInt(buffer, stop, stop+2);
- if ( stop+2!=fEnd ) {
+ if ( stop+2!=end ) {
throw new RuntimeException("Error in parsing time zone");
}
@@ -458,9 +409,9 @@
* @param ch character to look for in StringBuffer
* @return index of ch within StringBuffer
*/
- protected int indexOf (int start, int end, char ch) {
+ protected int indexOf (String buffer, int start, int end, char ch) {
for ( int i=start;i<end;i++ ) {
- if ( fBuffer.charAt(i) == ch ) {
+ if ( buffer.charAt(i) == ch ) {
return i;
}
}
@@ -473,7 +424,7 @@
*
* @param data
*/
- protected void validateDateTime (int[] data) {
+ protected void validateDateTime (int[] data, int[] timeZone) {
//REVISIT: should we throw an exception for not valid dates
// or reporting an error message should be sufficient?
@@ -526,10 +477,10 @@
* @param end
* @return index of the UTC character that was found
*/
- protected int findUTCSign (int start, int end) {
+ protected int findUTCSign (String buffer, int start, int end) {
int c;
for ( int i=start;i<end;i++ ) {
- c=fBuffer.charAt(i);
+ c=buffer.charAt(i);
if ( c == 'Z' || c=='+' || c=='-' ) {
return i;
}
@@ -546,7 +497,7 @@
* @param end end position
* @return return integer representation of characters
*/
- protected int parseInt (int start, int end)
+ protected int parseInt (String buffer, int start, int end)
throws NumberFormatException{
//REVISIT: more testing on this parsing needs to be done.
int radix=10;
@@ -556,11 +507,11 @@
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");
+ digit = getDigit(buffer.charAt(i));
+ if ( digit < 0 ) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ if ( result < multmin ) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result *= radix;
- if ( result < limit + digit ) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
+ if ( result < limit + digit ) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result -= digit;
}while ( ++i < end );
@@ -568,7 +519,7 @@
}
// parse Year differently to support negative value.
- protected int parseIntYear (int end){
+ protected int parseIntYear (String buffer, int end){
int radix=10;
int result = 0;
boolean negative = false;
@@ -577,7 +528,7 @@
int multmin;
int digit=0;
- if (fBuffer.charAt(0) == '-'){
+ if (buffer.charAt(0) == '-'){
negative = true;
limit = Integer.MIN_VALUE;
i++;
@@ -589,18 +540,18 @@
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");
+ digit = getDigit(buffer.charAt(i++));
+ if (digit < 0) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ if (result < multmin) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result *= radix;
- if (result < limit + digit) throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
+ if (result < limit + digit) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result -= digit;
}
if (negative)
{
if (i > 1) return result;
- else throw new NumberFormatException("'"+fBuffer.toString()+"' has wrong format");
+ else throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
}
return -result;
@@ -612,7 +563,7 @@
* @param date CCYY-MM-DDThh:mm:ss+03
* @return CCYY-MM-DDThh:mm:ssZ
*/
- protected void normalize (int[] date) {
+ protected void normalize (int[] date, int[] timeZone) {
// REVISIT: we have common code in addDuration() for durations
// should consider reorganizing it.
@@ -667,21 +618,6 @@
/**
- * 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
@@ -762,7 +698,7 @@
protected String dateToString(int[] date) {
- message.setLength(0);
+ StringBuffer message = new StringBuffer(25);
message.append(date[CY]);
message.append('-');
message.append(date[M]);
@@ -780,27 +716,12 @@
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];
- }
+ private void cloneDate (int[] finalValue, int[] tempDate) {
+ System.arraycopy(finalValue, 0, tempDate, 0, TOTAL_SIZE);
}
}
1.4 +10 -17 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateDV.java
Index: DateDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DateDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ DateDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -66,13 +66,13 @@
* @author Elena Litani
* @Gopal Sharma, SUN Microsystems Inc.
*
- * @version $Id: DateDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: DateDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class DateDV extends DateTimeDV {
public Object getActualValue(String content) throws InvalidDatatypeValueException {
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "date"});
}
@@ -87,29 +87,22 @@
* @return normalized dateTime representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str, int[] date) throws SchemaDateTimeException{
- resetBuffer(str);
- //create structure to hold an object
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date = new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
- if ( date == null ) {
- date = new int[TOTAL_SIZE];
- }
- resetDateObj(date);
- // get date
-
- getDate(fStart, fEnd, date);
- parseTimeZone (fEnd, date);
+ int end = getDate(str, 0, len, date);
+ parseTimeZone (str, end, len, date, timeZone);
//validate and normalize
//REVISIT: do we need SchemaDateTimeException?
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z' ) {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
}
-
-
1.4 +11 -16 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDV.java
Index: DateTimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DateTimeDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ DateTimeDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -66,13 +66,13 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: DateTimeDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: DateTimeDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class DateTimeDV extends AbstractDateTimeDV {
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dateTime"});
}
@@ -87,31 +87,26 @@
* @return normalized dateTime representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str, int[] date) throws SchemaDateTimeException {
- resetBuffer(str);
+ protected int[] parse(String str) throws SchemaDateTimeException {
+ int len = str.length();
+ int[] date = new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
- //create structure to hold an object
- if ( date == null ) {
- date = new int[TOTAL_SIZE];
- }
- resetDateObj(date);
- int end = indexOf (fStart, fEnd, 'T');
+ int end = indexOf (str, 0, len, 'T');
// both time and date
- getDate(fStart, end, date);
- getTime(end+1, fEnd, date);
+ getDate(str, 0, end, date);
+ getTime(str, end+1, len, date, timeZone);
//validate and normalize
//REVISIT: do we need SchemaDateTimeException?
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z') {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
}
-
-
1.4 +14 -19 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DayDV.java
Index: DayDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DayDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DayDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ DayDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -65,7 +65,7 @@
*
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
- * @version $Id: DayDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: DayDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class DayDV extends AbstractDateTimeDV {
@@ -74,7 +74,7 @@
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gDay"});
}
@@ -90,16 +90,12 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str, int[] date) throws SchemaDateTimeException {
+ protected int[] parse(String str) throws SchemaDateTimeException {
+ int len = str.length();
+ int[] date=new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
- 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)!='-') {
+ if (str.charAt(0)!='-' || str.charAt(1)!='-' || str.charAt(2)!='-') {
throw new SchemaDateTimeException ("Error in day parsing");
}
@@ -107,24 +103,23 @@
date[CY]=YEAR;
date[M]=MONTH;
- date[D]=parseInt(fStart+3,fStart+5);
-
+ date[D]=parseInt(str, 3,5);
- if ( DAY_SIZE<fEnd ) {
- int sign = findUTCSign(DAY_SIZE, fEnd);
+ if ( DAY_SIZE<len ) {
+ int sign = findUTCSign(str, DAY_SIZE, len);
if ( sign<0 ) {
throw new SchemaDateTimeException ("Error in day parsing");
}
else {
- getTimeZone(date, sign);
+ getTimeZone(str, date, sign, len, timeZone);
}
}
//validate and normalize
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z' ) {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
@@ -136,7 +131,7 @@
* @return lexical representation of gDay: ---DD with an optional time zone sign
*/
protected String dateToString(int[] date) {
- message.setLength(0);
+ StringBuffer message = new StringBuffer(6);
message.append('-');
message.append('-');
message.append('-');
1.4 +35 -42 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DurationDV.java
Index: DurationDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DurationDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DurationDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ DurationDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -65,7 +65,7 @@
*
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
- * @version $Id: DurationDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: DurationDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class DurationDV extends AbstractDateTimeDV {
@@ -85,7 +85,7 @@
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return parse(content, null);
+ return parse(content);
} catch (Exception ex) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "duration"});
}
@@ -99,25 +99,18 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str, int[] date) throws SchemaDateTimeException{
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date=new int[TOTAL_SIZE];
- //PnYn MnDTnH nMnS: -P1Y2M3DT10H30M
- resetBuffer(str);
-
- //create structure to hold an object
- if ( date== null ) {
- date=new int[TOTAL_SIZE];
- }
- resetDateObj(date);
-
-
- char c=fBuffer.charAt(fStart++);
+ int start = 0;
+ char c=str.charAt(start++);
if ( c!='P' && c!='-' ) {
throw new SchemaDateTimeException();
}
else {
date[utc]=(c=='-')?'-':0;
- if ( c=='-' && fBuffer.charAt(fStart++)!='P' ) {
+ if ( c=='-' && str.charAt(start++)!='P' ) {
throw new SchemaDateTimeException();
}
}
@@ -131,77 +124,77 @@
//at least one number and designator must be seen after P
boolean designator = false;
- int endDate = indexOf (fStart, fEnd, 'T');
+ int endDate = indexOf (str, start, len, 'T');
if ( endDate == -1 ) {
- endDate = fEnd;
+ endDate = len;
}
//find 'Y'
- int end = indexOf (fStart, endDate, 'Y');
+ int end = indexOf (str, start, endDate, 'Y');
if ( end!=-1 ) {
//scan year
- date[CY]=negate * parseInt(fStart,end);
- fStart = end+1;
+ date[CY]=negate * parseInt(str,start,end);
+ start = end+1;
designator = true;
}
- end = indexOf (fStart, endDate, 'M');
+ end = indexOf (str, start, endDate, 'M');
if ( end!=-1 ) {
//scan month
- date[M]=negate * parseInt(fStart,end);
- fStart = end+1;
+ date[M]=negate * parseInt(str,start,end);
+ start = end+1;
designator = true;
}
- end = indexOf (fStart, endDate, 'D');
+ end = indexOf (str, start, endDate, 'D');
if ( end!=-1 ) {
//scan day
- date[D]=negate * parseInt(fStart,end);
- fStart = end+1;
+ date[D]=negate * parseInt(str,start,end);
+ start = end+1;
designator = true;
}
- if ( fEnd == endDate && fStart!=fEnd ) {
+ if ( len == endDate && start!=len ) {
throw new SchemaDateTimeException();
}
- if ( fEnd !=endDate ) {
+ if ( len !=endDate ) {
//scan hours, minutes, seconds
//REVISIT: can any item include a decimal fraction or only seconds?
//
- end = indexOf (++fStart, fEnd, 'H');
+ end = indexOf (str, ++start, len, 'H');
if ( end!=-1 ) {
//scan hours
- date[h]=negate * parseInt(fStart,end);
- fStart=end+1;
+ date[h]=negate * parseInt(str,start,end);
+ start=end+1;
designator = true;
}
- end = indexOf (fStart, fEnd, 'M');
+ end = indexOf (str, start, len, 'M');
if ( end!=-1 ) {
//scan min
- date[m]=negate * parseInt(fStart,end);
- fStart=end+1;
+ date[m]=negate * parseInt(str,start,end);
+ start=end+1;
designator = true;
}
- end = indexOf (fStart, fEnd, 'S');
+ end = indexOf (str, start, len, 'S');
if ( end!=-1 ) {
//scan seconds
- int mlsec = indexOf (fStart, end, '.');
+ int mlsec = indexOf (str, start, end, '.');
if ( mlsec >0 ) {
- date[s] = negate * parseInt (fStart, mlsec);
- date[ms] = negate * parseInt (mlsec+1, end);
+ date[s] = negate * parseInt (str, start, mlsec);
+ date[ms] = negate * parseInt (str, mlsec+1, end);
}
else {
- date[s]=negate * parseInt(fStart,end);
+ date[s]=negate * parseInt(str, start,end);
}
- fStart=end+1;
+ start=end+1;
designator = true;
}
// no additional data shouls appear after last item
// P1Y1M1DT is illigal value as well
- if ( fStart != fEnd || fBuffer.charAt(--fStart)=='T' ) {
+ if ( start != len || str.charAt(--start)=='T' ) {
throw new SchemaDateTimeException();
}
}
@@ -352,7 +345,7 @@
}
protected String dateToString(int[] date) {
- message.setLength(0);
+ StringBuffer message = new StringBuffer(30);
int negate = 1;
if ( date[CY]<0 ) {
message.append('-');
1.5 +15 -21 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDV.java
Index: MonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDV.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MonthDV.java 21 Mar 2002 17:07:38 -0000 1.4
+++ MonthDV.java 26 Apr 2002 20:33:49 -0000 1.5
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: MonthDV.java,v 1.4 2002/03/21 17:07:38 sandygao Exp $
+ * @version $Id: MonthDV.java,v 1.5 2002/04/26 20:33:49 sandygao Exp $
*/
public class MonthDV extends AbstractDateTimeDV {
@@ -79,7 +79,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gMonth"});
}
@@ -94,39 +94,34 @@
* @return normalized date representation
* @exception SchemaDateTimeException 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);
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date=new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
//set constants
date[CY]=YEAR;
date[D]=DAY;
- if (fBuffer.charAt(0)!='-' || fBuffer.charAt(1)!='-') {
+ if (str.charAt(0)!='-' || str.charAt(1)!='-') {
throw new SchemaDateTimeException("Invalid format for gMonth: "+str);
}
- int stop = fStart +4;
- date[M]=parseInt(fStart+2,stop);
+ int stop = 4;
+ date[M]=parseInt(str,2,stop);
- if ( MONTH_SIZE<fEnd ) {
- int sign = findUTCSign(MONTH_SIZE, fEnd);
+ if ( MONTH_SIZE<len ) {
+ int sign = findUTCSign(str, MONTH_SIZE, len);
if ( sign<0 ) {
throw new SchemaDateTimeException ("Error in month parsing: "+str);
}
else {
- getTimeZone(date, sign);
+ getTimeZone(str, date, sign, len, timeZone);
}
}
//validate and normalize
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z' ) {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
@@ -180,8 +175,7 @@
* @return lexical representation of month: --MM with an optional time zone sign
*/
protected String dateToString(int[] date) {
-
- message.setLength(0);
+ StringBuffer message = new StringBuffer(5);
message.append('-');
message.append('-');
message.append(date[M]);
1.4 +17 -22 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDayDV.java
Index: MonthDayDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDayDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MonthDayDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ MonthDayDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: MonthDayDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: MonthDayDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class MonthDayDV extends AbstractDateTimeDV {
@@ -82,7 +82,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gMonthDay"});
}
@@ -97,46 +97,41 @@
* @return normalized date representation
* @exception SchemaDateTimeException 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);
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date=new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
//initialize
date[CY]=YEAR;
- if (fBuffer.charAt(0)!='-' || fBuffer.charAt(1)!='-') {
+ if (str.charAt(0)!='-' || str.charAt(1)!='-') {
throw new SchemaDateTimeException("Invalid format for gMonthDay: "+str);
}
- date[M]=parseInt(fStart+2,fStart+4);
- fStart+=4;
+ date[M]=parseInt(str, 2, 4);
+ int start=4;
- if (fBuffer.charAt(fStart++)!='-') {
+ if (str.charAt(start++)!='-') {
throw new SchemaDateTimeException("Invalid format for gMonthDay: " + str);
}
- date[D]=parseInt(fStart, fStart+2);
+ date[D]=parseInt(str, start, start+2);
- if ( MONTHDAY_SIZE<fEnd ) {
- int sign = findUTCSign(MONTHDAY_SIZE, fEnd);
+ if ( MONTHDAY_SIZE<len ) {
+ int sign = findUTCSign(str, MONTHDAY_SIZE, len);
if ( sign<0 ) {
throw new SchemaDateTimeException ("Error in month parsing:" +str);
}
else {
- getTimeZone(date, sign);
+ getTimeZone(str, date, sign, len, timeZone);
}
}
//validate and normalize
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z' ) {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
@@ -148,7 +143,7 @@
* @return lexical representation of month: --MM-DD with an optional time zone sign
*/
protected String dateToString(int[] date) {
- message.setLength(0);
+ StringBuffer message = new StringBuffer(8);
message.append('-');
message.append('-');
message.append(date[M]);
1.4 +11 -16 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDV.java
Index: TimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TimeDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ TimeDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: TimeDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: TimeDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class TimeDV extends AbstractDateTimeDV {
@@ -78,7 +78,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "time"});
}
@@ -94,31 +94,26 @@
* @return normalized time representation
* @exception SchemaDateTimeException 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);
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date = new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
// time
// initialize to default values
date[CY]=YEAR;
date[M]=MONTH;
date[D]=DAY;
- getTime(fStart, fEnd, date);
+ getTime(str, 0, len, date, timeZone);
//validate and normalize
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 ) {
- normalize(date);
+ normalize(date, timeZone);
}
- return date;
+ return date;
}
/**
@@ -128,7 +123,7 @@
* @return lexical representation of time: hh:mm:ss.sss with an optional time zone sign
*/
protected String dateToString(int[] date) {
- message.setLength(0);
+ StringBuffer message = new StringBuffer(16);
message.append(date[h]);
message.append(':');
message.append(date[m]);
1.4 +14 -19 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearDV.java
Index: YearDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- YearDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ YearDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: YearDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: YearDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class YearDV extends AbstractDateTimeDV {
@@ -79,7 +79,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYear"});
}
@@ -94,27 +94,23 @@
* @return normalized date representation
* @exception SchemaDateTimeException 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);
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date = new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
// check for preceding '-' sign
int start = 0;
- if (fBuffer.charAt(0)=='-') {
+ if (str.charAt(0)=='-') {
start = 1;
}
- int sign = findUTCSign(start, fEnd);
+ int sign = findUTCSign(str, start, len);
if (sign == -1) {
- date[CY]=parseIntYear(fEnd);
+ date[CY]=parseIntYear(str, len);
}
else {
- date[CY]=parseIntYear(sign);
- getTimeZone (date, sign);
+ date[CY]=parseIntYear(str, sign);
+ getTimeZone (str, date, sign, len, timeZone);
}
//initialize values
@@ -122,10 +118,10 @@
date[D]=1;
//validate and normalize
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z' ) {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
@@ -137,8 +133,7 @@
* @return lexical representation of month: CCYY with optional time zone sign
*/
protected String dateToString(int[] date) {
-
- message.setLength(0);
+ StringBuffer message = new StringBuffer(5);
message.append(date[CY]);
message.append((char)date[utc]);
return message.toString();
1.4 +10 -14 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearMonthDV.java
Index: YearMonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearMonthDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- YearMonthDV.java 29 Jan 2002 01:15:12 -0000 1.3
+++ YearMonthDV.java 26 Apr 2002 20:33:49 -0000 1.4
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: YearMonthDV.java,v 1.3 2002/01/29 01:15:12 lehors Exp $
+ * @version $Id: YearMonthDV.java,v 1.4 2002/04/26 20:33:49 sandygao Exp $
*/
public class YearMonthDV extends AbstractDateTimeDV{
@@ -78,7 +78,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return parse(content, null);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYearMonth"});
}
@@ -93,26 +93,22 @@
* @return normalized date representation
* @exception SchemaDateTimeException 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);
+ protected int[] parse(String str) throws SchemaDateTimeException{
+ int len = str.length();
+ int[] date = new int[TOTAL_SIZE];
+ int[] timeZone = new int[2];
// get date
- getYearMonth(fStart, fEnd, date);
+ int end = getYearMonth(str, 0, len, date);
date[D] = DAY;
- parseTimeZone (fEnd, date);
+ parseTimeZone (str, end, len, date, timeZone);
//validate and normalize
- validateDateTime(date);
+ validateDateTime(date, timeZone);
if ( date[utc]!=0 && date[utc]!='Z' ) {
- normalize(date);
+ normalize(date, timeZone);
}
return date;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org