sandygao 2002/11/18 15:10:12
Modified: java/src/org/apache/xerces/impl/dv ValidatedInfo.java
java/src/org/apache/xerces/impl/dv/util Base64.java
HexBin.java
java/src/org/apache/xerces/impl/dv/xs
AbstractDateTimeDV.java AnyURIDV.java
Base64BinaryDV.java BaseDVFactory.java DateDV.java
DateTimeDV.java DayDV.java DecimalDV.java
DoubleDV.java DurationDV.java FloatDV.java
HexBinaryDV.java ListDV.java MonthDV.java
MonthDayDV.java QNameDV.java
SchemaDVFactoryImpl.java TimeDV.java
TypeValidator.java XSSimpleTypeDecl.java
YearDV.java YearMonthDV.java
Added: java/src/org/apache/xerces/impl/dv/xs IntegerDV.java
Log:
1. Provide canonical representations of Schema datatypes;
2. Provide more accurate equality checking for union types.
Revision Changes Path
1.5 +12 -1 xml-xerces/java/src/org/apache/xerces/impl/dv/ValidatedInfo.java
Index: ValidatedInfo.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/ValidatedInfo.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ValidatedInfo.java 18 Sep 2002 21:55:41 -0000 1.4
+++ ValidatedInfo.java 18 Nov 2002 23:10:09 -0000 1.5
@@ -102,4 +102,15 @@
this.memberType = null;
this.memberTypes = null;
}
+
+ /**
+ * Return a string representation of the value. If there is an actual
+ * value, use toString; otherwise, use the normalized value.
+ */
+ public String stringValue() {
+ if (actualValue == null)
+ return normalizedValue;
+ else
+ return actualValue.toString();
+ }
}
1.7 +86 -92 xml-xerces/java/src/org/apache/xerces/impl/dv/util/Base64.java
Index: Base64.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/util/Base64.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Base64.java 9 Jul 2002 20:46:04 -0000 1.6
+++ Base64.java 18 Nov 2002 23:10:10 -0000 1.7
@@ -84,10 +84,10 @@
static private final int SIXBIT = 6;
static private final int FOURBYTE = 4;
static private final int SIGN = -128;
- static private final byte PAD = ( byte ) '=';
+ static private final char PAD = '=';
static private final boolean fDebug = false;
static final private byte [] base64Alphabet = new byte[BASELENGTH];
- static final private byte [] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];
+ static final private char [] lookUpBase64Alphabet = new char[LOOKUPLENGTH];
static {
@@ -109,31 +109,31 @@
base64Alphabet['/'] = 63;
for (int i = 0; i<=25; i++)
- lookUpBase64Alphabet[i] = (byte) ('A'+i );
+ lookUpBase64Alphabet[i] = (char)('A'+i);
for (int i = 26, j = 0; i<=51; i++, j++)
- lookUpBase64Alphabet[i] = (byte) ('a'+ j );
+ lookUpBase64Alphabet[i] = (char)('a'+ j);
for (int i = 52, j = 0; i<=61; i++, j++)
- lookUpBase64Alphabet[i] = (byte) ('0' + j );
- lookUpBase64Alphabet[62] = (byte) '+';
- lookUpBase64Alphabet[63] = (byte) '/';
+ lookUpBase64Alphabet[i] = (char)('0' + j);
+ lookUpBase64Alphabet[62] = (char)'+';
+ lookUpBase64Alphabet[63] = (char)'/';
}
- protected static boolean isWhiteSpace(byte octect) {
+ protected static boolean isWhiteSpace(char octect) {
return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
}
- protected static boolean isPad(byte octect) {
+ protected static boolean isPad(char octect) {
return (octect == PAD);
}
- protected static boolean isData(byte octect) {
+ protected static boolean isData(char octect) {
return (base64Alphabet[octect] != -1);
}
- protected static boolean isBase64(byte octect) {
+ protected static boolean isBase64(char octect) {
return (isWhiteSpace(octect) || isPad(octect) || isData(octect));
}
@@ -143,20 +143,23 @@
* @param binaryData Array containing binaryData
* @return Encoded Base64 array
*/
- public static byte[] encode(byte[] binaryData) {
+ public static String encode(byte[] binaryData) {
if (binaryData == null)
return null;
int lengthDataBits = binaryData.length*EIGHTBIT;
+ if (lengthDataBits == 0) {
+ return "";
+ }
+
int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP;
int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP;
- byte encodedData[] = null;
+ int numberQuartet = fewerThan24bits != 0 ? numberTriplets+1 :
numberTriplets;
+ int numberLines = (numberQuartet-1)/19+1;
+ char encodedData[] = null;
- if (fewerThan24bits != 0) //data not divisible by 24 bit
- encodedData = new byte[ (numberTriplets + 1 )*4 ];
- else // 16 or 8 bit
- encodedData = new byte[ numberTriplets*4 ];
+ encodedData = new char[numberQuartet*4+numberLines];
byte k=0, l=0, b1=0,b2=0,b3=0;
@@ -166,12 +169,45 @@
if (fDebug) {
System.out.println("number of triplets = " + numberTriplets );
}
- for (i = 0; i<numberTriplets; i++) {
- dataIndex = i*3;
- b1 = binaryData[dataIndex];
- b2 = binaryData[dataIndex + 1];
- b3 = binaryData[dataIndex + 2];
+ for (int line = 0; line < numberLines-1; line++) {
+ for (int quartet = 0; quartet < 19; quartet++) {
+ b1 = binaryData[dataIndex++];
+ b2 = binaryData[dataIndex++];
+ b3 = binaryData[dataIndex++];
+
+ if (fDebug) {
+ System.out.println( "b1= " + b1 +", b2= " + b2 + ", b3= " + b3
);
+ }
+
+ l = (byte)(b2 & 0x0f);
+ k = (byte)(b1 & 0x03);
+
+ byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0);
+
+ byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0);
+ byte val3 = ((b3 & SIGN)==0)?(byte)(b3>>6):(byte)((b3)>>6^0xfc);
+
+ if (fDebug) {
+ System.out.println( "val2 = " + val2 );
+ System.out.println( "k4 = " + (k<<4));
+ System.out.println( "vak = " + (val2 | (k<<4)));
+ }
+
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4
)];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ (l <<2 ) | val3
];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ b3 & 0x3f ];
+
+ i++;
+ }
+ encodedData[encodedIndex++] = 0xa;
+ }
+
+ for (; i<numberTriplets; i++) {
+ b1 = binaryData[dataIndex++];
+ b2 = binaryData[dataIndex++];
+ b3 = binaryData[dataIndex++];
if (fDebug) {
System.out.println( "b1= " + b1 +", b2= " + b2 + ", b3= " + b3 );
@@ -180,27 +216,24 @@
l = (byte)(b2 & 0x0f);
k = (byte)(b1 & 0x03);
- encodedIndex = i*4;
byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0);
byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0);
byte val3 = ((b3 & SIGN)==0)?(byte)(b3>>6):(byte)((b3)>>6^0xfc);
- encodedData[encodedIndex] = lookUpBase64Alphabet[ val1 ];
if (fDebug) {
System.out.println( "val2 = " + val2 );
System.out.println( "k4 = " + (k<<4));
System.out.println( "vak = " + (val2 | (k<<4)));
}
- encodedData[encodedIndex+1] = lookUpBase64Alphabet[ val2 | ( k<<4 )];
- encodedData[encodedIndex+2] = lookUpBase64Alphabet[ (l <<2 ) | val3 ];
- encodedData[encodedIndex+3] = lookUpBase64Alphabet[ b3 & 0x3f ];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4 )];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ (l <<2 ) | val3 ];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ b3 & 0x3f ];
}
// form integral number of 6-bit groups
- dataIndex = i*3;
- encodedIndex = i*4;
if (fewerThan24bits == EIGHTBIT) {
b1 = binaryData[dataIndex];
k = (byte) ( b1 &0x03 );
@@ -209,12 +242,11 @@
System.out.println("b1<<2 = " + (b1>>2) );
}
byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0);
- encodedData[encodedIndex] = lookUpBase64Alphabet[ val1 ];
- encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ k<<4 ];
- encodedData[encodedIndex + 2] = PAD;
- encodedData[encodedIndex + 3] = PAD;
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ k<<4 ];
+ encodedData[encodedIndex++] = PAD;
+ encodedData[encodedIndex++] = PAD;
} else if (fewerThan24bits == SIXTEENBIT) {
-
b1 = binaryData[dataIndex];
b2 = binaryData[dataIndex +1 ];
l = ( byte ) ( b2 &0x0f );
@@ -223,13 +255,15 @@
byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0);
byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0);
- encodedData[encodedIndex] = lookUpBase64Alphabet[ val1 ];
- encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ val2 | ( k<<4 )];
- encodedData[encodedIndex + 2] = lookUpBase64Alphabet[ l<<2 ];
- encodedData[encodedIndex + 3] = PAD;
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4 )];
+ encodedData[encodedIndex++] = lookUpBase64Alphabet[ l<<2 ];
+ encodedData[encodedIndex++] = PAD;
}
- return encodedData;
+ encodedData[encodedIndex] = 0xa;
+
+ return new String(encodedData);
}
/**
@@ -238,29 +272,28 @@
* @param binaryData Byte array containing Base64 data
* @return Array containind decoded data.
*/
- public static byte[] decode(byte[] base64Data) {
+ public static byte[] decode(String encoded) {
- if (base64Data == null)
+ if (encoded == null)
return null;
+ char[] base64Data = encoded.toCharArray();
// remove white spaces
- base64Data = removeWhiteSpace(base64Data);
+ int len = removeWhiteSpace(base64Data);
- if (base64Data.length%FOURBYTE != 0) {
+ if (len%FOURBYTE != 0) {
return null;//should be divisible by four
}
- int numberQuadruple = (base64Data.length/FOURBYTE );
+ int numberQuadruple = (len/FOURBYTE );
if (numberQuadruple == 0)
return new byte[0];
byte decodedData[] = null;
byte b1=0,b2=0,b3=0, b4=0, marker0=0, marker1=0;
- byte d1=0,d2=0,d3=0,d4=0;
+ char d1=0,d2=0,d3=0,d4=0;
- // Throw away anything not in normalizedBase64Data
- // Adjust size
int i = 0;
int encodedIndex = 0;
int dataIndex = 0;
@@ -328,61 +361,22 @@
}
/**
- * Decodes Base64 data into octects
- *
- * @param base64Data String containing Base64 data
- * @return string containing decoded data.
- */
- public static String decode(String base64Data) {
- if (base64Data == null)
- return null;
-
- byte[] decoded = null;
- try {
- decoded = decode(base64Data.getBytes("utf-8"));
- }
- catch(UnsupportedEncodingException e) {
- }
- finally {
- String retVal = null;
- try {
- retVal = decoded == null ? null : new String(decoded, "8859_1");
- } catch (UnsupportedEncodingException e) {
- }
- return retVal;
- }
- }
-
- /**
* remove WhiteSpace from MIME containing encoded Base64 data.
*
* @param data the byte array of base64 data (with WS)
- * @return the byte array of base64 data (without WS)
+ * @return the new length
*/
- protected static byte[] removeWhiteSpace(byte[] data) {
+ protected static int removeWhiteSpace(char[] data) {
if (data == null)
- return null;
+ return 0;
// count characters that's not whitespace
int newSize = 0;
int len = data.length;
for (int i = 0; i < len; i++) {
if (!isWhiteSpace(data[i]))
- newSize++;
- }
-
- // if no whitespace, just return the input array
- if (newSize == len)
- return data;
-
- // create the array to return
- byte[] newArray = new byte[newSize];
-
- int j = 0;
- for (int i = 0; i < len; i++) {
- if (!isWhiteSpace(data[i]))
- newArray[j++] = data[i];
+ data[newSize++] = data[i];
}
- return newArray;
+ return newSize;
}
}
1.7 +34 -55 xml-xerces/java/src/org/apache/xerces/impl/dv/util/HexBin.java
Index: HexBin.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/util/HexBin.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HexBin.java 9 Jul 2002 20:46:04 -0000 1.6
+++ HexBin.java 18 Nov 2002 23:10:10 -0000 1.7
@@ -69,7 +69,7 @@
static private final int BASELENGTH = 255;
static private final int LOOKUPLENGTH = 16;
static final private byte [] hexNumberTable = new byte[BASELENGTH];
- static final private byte [] lookUpHexAlphabet = new byte[LOOKUPLENGTH];
+ static final private char [] lookUpHexAlphabet = new char[LOOKUPLENGTH];
static {
@@ -87,81 +87,60 @@
}
for(int i = 0; i<10; i++ )
- lookUpHexAlphabet[i] = (byte) ('0'+i );
+ lookUpHexAlphabet[i] = (char)('0'+i);
for(int i = 10; i<=15; i++ )
- lookUpHexAlphabet[i] = (byte) ('A'+i -10);
+ lookUpHexAlphabet[i] = (char)('A'+i -10);
}
/**
- * byte to be tested if it is Base64 alphabet
+ * Encode a byte array to hex string
*
- * @param octect
- * @return
+ * @param binaryData array of byte to encode
+ * @return return encoded string
*/
- static boolean isHex(byte octect) {
- return (hexNumberTable[octect] != -1);
- }
-
- /**
- * array of byte to encode
- *
- * @param binaryData
- * @return return encode binary array
- */
- static public byte[] encode(byte[] binaryData) {
+ static public String encode(byte[] binaryData) {
if (binaryData == null)
return null;
int lengthData = binaryData.length;
int lengthEncode = lengthData * 2;
- byte[] encodedData = new byte[lengthEncode];
- for( int i = 0; i<lengthData; i++ ){
- encodedData[i*2] = lookUpHexAlphabet[ binaryData[i] >> 4];
- encodedData[i*2+1] = lookUpHexAlphabet[ binaryData[i] & 0xf];
+ char[] encodedData = new char[lengthEncode];
+ int temp;
+ for (int i = 0; i < lengthData; i++) {
+ temp = binaryData[i];
+ if (temp < 0)
+ temp += 256;
+ encodedData[i*2] = lookUpHexAlphabet[temp >> 4];
+ encodedData[i*2+1] = lookUpHexAlphabet[temp & 0xf];
}
- return encodedData;
+ return new String(encodedData);
}
- static public byte[] decode(byte[] binaryData) {
- if (binaryData == null)
+ /**
+ * Decode hex string to a byte array
+ *
+ * @param binaryData encoded string
+ * @return return array of byte to encode
+ */
+ static public byte[] decode(String encoded) {
+ if (encoded == null)
return null;
- int lengthData = binaryData.length;
+ int lengthData = encoded.length();
if (lengthData % 2 != 0)
return null;
+ char[] binaryData = encoded.toCharArray();
int lengthDecode = lengthData / 2;
byte[] decodedData = new byte[lengthDecode];
+ byte temp1, temp2;
for( int i = 0; i<lengthDecode; i++ ){
- if (!isHex(binaryData[i*2]) || !isHex(binaryData[i*2+1])) {
+ temp1 = hexNumberTable[binaryData[i*2]];
+ if (temp1 == -1)
return null;
- }
- decodedData[i] = (byte)((hexNumberTable[binaryData[i*2]] << 4) |
hexNumberTable[binaryData[i*2+1]]);
+ temp2 = hexNumberTable[binaryData[i*2+1]];
+ if (temp2 == -1)
+ return null;
+ decodedData[i] = (byte)((temp1 << 4) | temp2);
}
return decodedData;
- }
-
- /**
- * Decodes Hex data into octects
- *
- * @param binaryData String containing Hex data
- * @return string containing decoded data.
- */
- public static String decode(String binaryData) {
- if (binaryData == null)
- return null;
-
- byte[] decoded = null;
- try {
- decoded = decode(binaryData.getBytes("utf-8"));
- }
- catch(UnsupportedEncodingException e) {
- }
- finally {
- String retVal = null;
- try {
- retVal = decoded == null ? null : new String(decoded, "8859_1");
- } catch (UnsupportedEncodingException e) {
- }
- return retVal;
- }
}
}
1.7 +31 -9
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractDateTimeDV.java 20 Aug 2002 23:03:20 -0000 1.6
+++ AbstractDateTimeDV.java 18 Nov 2002 23:10:10 -0000 1.7
@@ -102,15 +102,9 @@
}//getAllowedFacets()
// the parameters are in compiled form (from getActualValue)
- public boolean isEqual(Object value1, Object value2){
- if (!(value1 instanceof int[]) || !(value2 instanceof int[]))
- return false;
- return compareDates((int[])value1,(int[])value2, true)==0;
- }//IsEqual()
-
- // the parameters are in compiled form (from getActualValue)
public int compare (Object value1, Object value2) {
- return compareDates((int[])value1, (int[])value2, true);
+ return compareDates(((DateTimeData)value1).data,
+ ((DateTimeData)value2).data, true);
}//compare()
/**
@@ -721,4 +715,32 @@
System.arraycopy(finalValue, 0, tempDate, 0, TOTAL_SIZE);
}
+ /**
+ * Represents date time data
+ */
+ static final class DateTimeData {
+ // actual data stored in an int array
+ final int[] data;
+ // a pointer to the type that was used go generate this data
+ // note that this is not the actual simple type, but one of the
+ // statically created XXXDV objects, so this won't cause any GC problem.
+ final AbstractDateTimeDV type;
+ private String canonical;
+ public DateTimeData(int[] data, AbstractDateTimeDV type) {
+ this.data = data;
+ this.type = type;
+ }
+ public boolean equals(Object obj) {
+ if (!(obj instanceof DateTimeData))
+ return false;
+ int[] odata = ((DateTimeData)obj).data;
+ return type.compareDates(data, odata, true)==0;
+ }
+ public synchronized String toString() {
+ if (canonical == null) {
+ canonical = type.dateToString(data);
+ }
+ return canonical;
+ }
+ }
}
1.4 +5 -6 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AnyURIDV.java
Index: AnyURIDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AnyURIDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AnyURIDV.java 18 Jul 2002 20:48:43 -0000 1.3
+++ AnyURIDV.java 18 Nov 2002 23:10:10 -0000 1.4
@@ -71,12 +71,14 @@
*/
public class AnyURIDV extends TypeValidator {
- private static URI BASE_URI = null;
+ private static final URI BASE_URI;
static {
+ URI uri = null;
try {
- BASE_URI = new URI("http://www.template.com");
+ uri = new URI("abc://def.ghi.jkl");
} catch (URI.MalformedURIException ex) {
}
+ BASE_URI = uri;
}
public short getAllowedFacets(){
@@ -101,8 +103,5 @@
// REVISIT: do we need to return the new URI object?
return content;
}
-
- // REVISIT: do we need to compare based on URI, or based on String?
- // public boolean isEqual(Object value1, Object value2);
} // class AnyURIDV
1.4 +42 -3
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java
Index: Base64BinaryDV.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Base64BinaryDV.java 18 Jul 2002 20:48:43 -0000 1.3
+++ Base64BinaryDV.java 18 Nov 2002 23:10:10 -0000 1.4
@@ -76,11 +76,50 @@
}
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
- String decoded = Base64.decode(content);
+ byte[] decoded = Base64.decode(content);
if (decoded == null)
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "base64Binary"});
- return decoded;
+ return new XBase64(decoded);
}
+ // length of a binary type is the number of bytes
+ public int getDataLength(Object value) {
+ return ((XBase64)value).length();
+ }
+
+ /**
+ * represent base64 data
+ */
+ private static final class XBase64 {
+ // actually data stored in a byte array
+ final byte[] data;
+ // canonical representation of the data
+ private String canonical;
+ public XBase64(byte[] data) {
+ this.data = data;
+ }
+ public synchronized String toString() {
+ if (canonical == null) {
+ canonical = Base64.encode(data);
+ }
+ return canonical;
+ }
+ public int length() {
+ return data.length;
+ }
+ public boolean equals(Object obj) {
+ if (!(obj instanceof XBase64))
+ return false;
+ byte[] odata = ((XBase64)obj).data;
+ int len = data.length;
+ if (len != odata.length)
+ return false;
+ for (int i = 0; i < len; i++) {
+ if (data[i] != odata[i])
+ return false;
+ }
+ return true;
+ }
+ }
} // class Base64BinaryDV
1.2 +2 -4
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/BaseDVFactory.java
Index: BaseDVFactory.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/BaseDVFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseDVFactory.java 30 Jul 2002 23:12:29 -0000 1.1
+++ BaseDVFactory.java 18 Nov 2002 23:10:10 -0000 1.2
@@ -206,9 +206,7 @@
types.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY,
XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true));
types.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH,
XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true));
- facets.fractionDigits = 0;
- XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER,
URI_SCHEMAFORSCHEMA, (short)0, false);
- integerDV.applyFacets1(facets , XSSimpleType.FACET_FRACTIONDIGITS,
(short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_INTEGER);
+ XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER,
XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true);
types.put(INTEGER, integerDV);
facets.maxInclusive = "0";
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DateDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ DateDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -72,7 +72,7 @@
public Object getActualValue(String content) throws
InvalidDatatypeValueException {
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "date"});
}
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DateTimeDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ DateTimeDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -72,7 +72,7 @@
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "dateTime"});
}
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DayDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ DayDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -74,7 +74,7 @@
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "gDay"});
}
1.6 +112 -34 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DecimalDV.java
Index: DecimalDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DecimalDV.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DecimalDV.java 25 Oct 2002 20:28:42 -0000 1.5
+++ DecimalDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -72,40 +72,34 @@
*/
public class DecimalDV extends TypeValidator {
- public short getAllowedFacets(){
+ public final short getAllowedFacets(){
return ( XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_WHITESPACE
| XSSimpleTypeDecl.FACET_ENUMERATION |XSSimpleTypeDecl.FACET_MAXINCLUSIVE
|XSSimpleTypeDecl.FACET_MININCLUSIVE | XSSimpleTypeDecl.FACET_MAXEXCLUSIVE |
XSSimpleTypeDecl.FACET_MINEXCLUSIVE | XSSimpleTypeDecl.FACET_TOTALDIGITS |
XSSimpleTypeDecl.FACET_FRACTIONDIGITS);
}
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try {
- return new MyDecimal(content);
+ return new XDecimal(content);
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "decimal"});
}
}
- public boolean isEqual(Object value1, Object value2) {
- if (!(value1 instanceof MyDecimal) || !(value2 instanceof MyDecimal))
- return false;
- return ((MyDecimal)value1).equals((MyDecimal)value2);
- }
-
- public int compare(Object value1, Object value2){
- return ((MyDecimal)value1).compareTo((MyDecimal)value2);
+ public final int compare(Object value1, Object value2){
+ return ((XDecimal)value1).compareTo((XDecimal)value2);
}
- public int getTotalDigits(Object value){
- return ((MyDecimal)value).totalDigits;
+ public final int getTotalDigits(Object value){
+ return ((XDecimal)value).totalDigits;
}
- public int getFractionDigits(Object value){
- return ((MyDecimal)value).fracDigits;
+ public final int getFractionDigits(Object value){
+ return ((XDecimal)value).fracDigits;
}
} // class DecimalDV
// Avoid using the heavy-weight java.math.BigDecimal
-class MyDecimal {
+class XDecimal {
// sign: 0 for vlaue 0; 1 for positive values; -1 for negative values
int sign = 1;
// total digits. >= 1
@@ -118,11 +112,19 @@
String ivalue = "";
// the string representing the fraction part
String fvalue = "";
+ // whether the canonical form contains decimal point
+ boolean integer = false;
- MyDecimal(String content) throws NumberFormatException {
- if (content.equals("0")) {
- int i = 0;
- }
+ XDecimal(String content) throws NumberFormatException {
+ initD(content);
+ }
+ XDecimal(String content, boolean integer) throws NumberFormatException {
+ if (integer)
+ initI(content);
+ else
+ initD(content);
+ }
+ void initD(String content) throws NumberFormatException {
int len = content.length();
if (len == 0)
throw new NumberFormatException();
@@ -198,28 +200,82 @@
}
}
}
- public boolean equals(MyDecimal val) {
- if (val == null)
- return false;
+ void initI(String content) throws NumberFormatException {
+ int len = content.length();
+ if (len == 0)
+ throw new NumberFormatException();
+
+ // these 2 variables are used to indicate where the integre start/end.
+ int intStart = 0, intEnd = 0;
+
+ // Deal with leading sign symbol if present
+ if (content.charAt(0) == '+') {
+ // skip '+', so intStart should be 1
+ intStart = 1;
+ }
+ else if (content.charAt(0) == '-') {
+ // keep '-', so intStart is stil 0
+ intStart = 1;
+ sign = -1;
+ }
+
+ // skip leading zeroes in integer part
+ int actualIntStart = intStart;
+ while (actualIntStart < len && content.charAt(actualIntStart) == '0') {
+ actualIntStart++;
+ }
+
+ // Find the ending position of the integer part
+ for (intEnd = actualIntStart;
+ intEnd < len && TypeValidator.isDigit(content.charAt(intEnd));
+ intEnd++);
+
+ // Not reached the end yet, error
+ if (intEnd < len)
+ throw new NumberFormatException();
+
+ // no integer part, error.
+ if (intStart == intEnd)
+ throw new NumberFormatException();
+
+ intDigits = intEnd - actualIntStart;
+ fracDigits = 0;
+ totalDigits = intDigits == 0 ? 1 : intDigits;
+
+ if (intDigits > 0) {
+ ivalue = content.substring(actualIntStart, intEnd);
+ }
+ else {
+ // "00", treat it as "0"
+ sign = 0;
+ }
+
+ integer = true;
+ }
+ public boolean equals(Object val) {
if (val == this)
return true;
+
+ if (!(val instanceof XDecimal))
+ return false;
+ XDecimal oval = (XDecimal)val;
- if (sign != val.sign)
+ if (sign != oval.sign)
return false;
if (sign == 0)
return true;
- return intDigits == val.intDigits && fracDigits == val.fracDigits &&
- ivalue.equals(val.ivalue) && fvalue.equals(val.fvalue);
+ return intDigits == oval.intDigits && fracDigits == oval.fracDigits &&
+ ivalue.equals(oval.ivalue) && fvalue.equals(oval.fvalue);
}
- public int compareTo(MyDecimal val) {
+ public int compareTo(XDecimal val) {
if (sign != val.sign)
return sign > val.sign ? 1 : -1;
if (sign == 0)
return 0;
return sign * intComp(val);
}
- private int intComp(MyDecimal val) {
+ private int intComp(XDecimal val) {
if (intDigits != val.intDigits)
return intDigits > val.intDigits ? 1 : -1;
int ret = ivalue.compareTo(val.ivalue);
@@ -228,9 +284,26 @@
ret = fvalue.compareTo(val.fvalue);
return ret == 0 ? 0 : (ret > 0 ? 1 : -1);
}
- public String toString() {
- if (sign == 0)
- return "0";
+ private String canonical;
+ public synchronized String toString() {
+ if (canonical == null) {
+ makeCanonical();
+ }
+ return canonical;
+ }
+
+ private void makeCanonical() {
+ if (sign == 0) {
+ if (integer)
+ canonical = "0";
+ else
+ canonical = "0.0";
+ return;
+ }
+ if (integer && sign > 0) {
+ canonical = ivalue;
+ return;
+ }
StringBuffer buffer = new StringBuffer(totalDigits+2);
if (sign == -1)
buffer.append('-');
@@ -238,10 +311,15 @@
buffer.append(ivalue);
else
buffer.append('0');
- if (fracDigits != 0) {
+ if (!integer) {
buffer.append('.');
- buffer.append(fvalue);
+ if (fracDigits != 0) {
+ buffer.append(fvalue);
+ }
+ else {
+ buffer.append('0');
+ }
}
- return buffer.toString();
+ canonical = buffer.toString();
}
}
1.4 +70 -41 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DoubleDV.java
Index: DoubleDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DoubleDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DoubleDV.java 18 Jul 2002 20:48:43 -0000 1.3
+++ DoubleDV.java 18 Nov 2002 23:10:10 -0000 1.4
@@ -77,57 +77,86 @@
//convert a String to Double form, we have to take care of cases specified in
spec like INF, -INF and NaN
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try{
- return dValueOf(content);
- } catch (Exception ex){
+ return new XDouble(content);
+ } catch (NumberFormatException ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "double"});
}
}//getActualValue()
// Can't call Double#compareTo method, because it's introduced in jdk 1.2
public int compare(Object value1, Object value2) {
- return compareDoubles((Double)value1, (Double)value2);
+ return ((XDouble)value1).compareTo((XDouble)value2);
}//compare()
- //
- // private methods
- //
- private static Double dValueOf(String s) throws NumberFormatException {
- Double d;
- try {
- d = Double.valueOf(s);
- }
- catch ( NumberFormatException nfe ) {
- if ( s.equals("INF") ) {
- d = new Double(Double.POSITIVE_INFINITY);
- }
- else if ( s.equals("-INF") ) {
- d = new Double (Double.NEGATIVE_INFINITY);
- }
- else if ( s.equals("NaN" ) ) {
- d = new Double (Double.NaN);
+ private static final class XDouble {
+ private double value;
+ public XDouble(String s) throws NumberFormatException {
+ try {
+ value = Double.parseDouble(s);
}
- else {
- throw nfe;
+ catch ( NumberFormatException nfe ) {
+ if ( s.equals("INF") ) {
+ value = Double.POSITIVE_INFINITY;
+ }
+ else if ( s.equals("-INF") ) {
+ value = Double.NEGATIVE_INFINITY;
+ }
+ else if ( s.equals("NaN" ) ) {
+ value = Double.NaN;
+ }
+ else {
+ throw nfe;
+ }
}
}
- return d;
- }//dValueOf()
- private int compareDoubles(Double value, Double anotherValue) {
- double thisVal = value.doubleValue();
- double anotherVal = anotherValue.doubleValue();
-
- if (thisVal < anotherVal)
- return -1; // Neither val is NaN, thisVal is smaller
- if (thisVal > anotherVal)
- return 1; // Neither val is NaN, thisVal is larger
-
- long thisBits = Double.doubleToLongBits(thisVal);
- long anotherBits = Double.doubleToLongBits(anotherVal);
-
- return (thisBits == anotherBits ? 0 : // Values are equal
- (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
- 1)); // (0.0, -0.0) or (NaN, !NaN)
- }
+ public boolean equals(Object val) {
+ if (val == this)
+ return true;
+
+ if (!(val instanceof XDouble))
+ return false;
+ XDouble oval = (XDouble)val;
+
+ if (value == oval.value)
+ return true;
+
+ if (value != value && oval.value != oval.value)
+ return true;
+
+ return false;
+ }
+ private int compareTo(XDouble val) {
+ double oval = val.value;
+
+ // this < other
+ if (value < oval)
+ return -1;
+ // this > other
+ if (value > oval)
+ return 1;
+
+ // get the bits
+ long bits = Double.doubleToLongBits(value);
+ long obits = Double.doubleToLongBits(oval);
+
+ // equal, or one is NaN, which is always smaller
+ return (bits == obits ? 0 :
+ (bits < obits ? -1 :
+ 1));
+ }
+ private String canonical;
+ public synchronized String toString() {
+ if (canonical == null) {
+ if (value == Double.POSITIVE_INFINITY)
+ canonical = "INF";
+ else if (value == Double.NEGATIVE_INFINITY)
+ canonical = "-INF";
+ else
+ canonical = Double.toString(value);
+ }
+ return canonical;
+ }
+ }
} // class DoubleDV
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DurationDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ DurationDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -85,7 +85,7 @@
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException{
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch (Exception ex) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "duration"});
}
1.4 +70 -39 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/FloatDV.java
Index: FloatDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/FloatDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FloatDV.java 18 Jul 2002 20:48:43 -0000 1.3
+++ FloatDV.java 18 Nov 2002 23:10:10 -0000 1.4
@@ -77,55 +77,86 @@
//convert a String to Float form, we have to take care of cases specified in
spec like INF, -INF and NaN
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try{
- return fValueOf(content);
- } catch (Exception ex){
+ return new XFloat(content);
+ } catch (NumberFormatException ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "float"});
}
}//getActualValue()
// Can't call Float#compareTo method, because it's introduced in jdk 1.2
public int compare(Object value1, Object value2){
- return compareFloats((Float)value1, (Float)value2);
+ return ((XFloat)value1).compareTo((XFloat)value2);
}//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);
+ private static final class XFloat {
+ private float value;
+ public XFloat(String s) throws NumberFormatException {
+ try {
+ value = Float.parseFloat(s);
}
- else if ( s.equals("NaN" ) ) {
- f = new Float (Float.NaN);
- }
- else {
- throw nfe;
+ catch ( NumberFormatException nfe ) {
+ if ( s.equals("INF") ) {
+ value = Float.POSITIVE_INFINITY;
+ }
+ else if ( s.equals("-INF") ) {
+ value = Float.NEGATIVE_INFINITY;
+ }
+ else if ( s.equals("NaN" ) ) {
+ value = Float.NaN;
+ }
+ else {
+ throw nfe;
+ }
}
}
- return f;
- }
- private int compareFloats(Float value, Float anotherValue){
- float thisVal = value.floatValue();
- float anotherVal = anotherValue.floatValue();
-
- if (thisVal < anotherVal)
- return -1; // Neither val is NaN, thisVal is smaller
- if (thisVal > anotherVal)
- return 1; // Neither val is NaN, thisVal is larger
-
- int thisBits = Float.floatToIntBits(thisVal);
- int anotherBits = Float.floatToIntBits(anotherVal);
-
- return (thisBits == anotherBits ? 0 : // Values are equal
- (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
- 1)); // (0.0, -0.0) or (NaN, !NaN)
- }
+ public boolean equals(Object val) {
+ if (val == this)
+ return true;
+
+ if (!(val instanceof XFloat))
+ return false;
+ XFloat oval = (XFloat)val;
+
+ if (value == oval.value)
+ return true;
+
+ if (value != value && oval.value != oval.value)
+ return true;
+ return false;
+ }
+
+ private int compareTo(XFloat val) {
+ float oval = val.value;
+
+ // this < other
+ if (value < oval)
+ return -1;
+ // this > other
+ if (value > oval)
+ return 1;
+
+ // get the bits
+ int bits = Float.floatToIntBits(value);
+ int obits = Float.floatToIntBits(oval);
+
+ // equal, or one is NaN, which is always smaller
+ return (bits == obits ? 0 :
+ (bits < obits ? -1 :
+ 1));
+ }
+ private String canonical;
+ public synchronized String toString() {
+ if (canonical == null) {
+ if (value == Float.POSITIVE_INFINITY)
+ canonical = "INF";
+ else if (value == Float.NEGATIVE_INFINITY)
+ canonical = "-INF";
+ else
+ canonical = Float.toString(value);
+ }
+ return canonical;
+ }
+ }
} // class FloatDV
1.4 +39 -3
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java
Index: HexBinaryDV.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HexBinaryDV.java 18 Jul 2002 20:48:43 -0000 1.3
+++ HexBinaryDV.java 18 Nov 2002 23:10:10 -0000 1.4
@@ -76,11 +76,47 @@
}
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
- String decoded = HexBin.decode(content);
+ byte[] decoded = HexBin.decode(content);
if (decoded == null)
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "hexBinary"});
- return decoded;
+ return new XHex(decoded);
}
+ // length of a binary type is the number of bytes
+ public int getDataLength(Object value) {
+ return ((XHex)value).length();
+ }
+
+ private static final class XHex {
+ // actually data stored in a byte array
+ final byte[] data;
+ // canonical representation of the data
+ private String canonical;
+ public XHex(byte[] data) {
+ this.data = data;
+ }
+ public synchronized String toString() {
+ if (canonical == null) {
+ canonical = HexBin.encode(data);
+ }
+ return canonical;
+ }
+ public int length() {
+ return data.length;
+ }
+ public boolean equals(Object obj) {
+ if (!(obj instanceof XHex))
+ return false;
+ byte[] odata = ((XHex)obj).data;
+ int len = data.length;
+ if (len != odata.length)
+ return false;
+ for (int i = 0; i < len; i++) {
+ if (data[i] != odata[i])
+ return false;
+ }
+ return true;
+ }
+ }
}
1.4 +48 -2 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/ListDV.java
Index: ListDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/ListDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ListDV.java 18 Jul 2002 20:48:43 -0000 1.3
+++ ListDV.java 18 Nov 2002 23:10:10 -0000 1.4
@@ -82,6 +82,52 @@
// length of a list type is the number of items in the list
public int getDataLength(Object value) {
- return ((Object[])value).length;
+ return ((ListData)value).length();
}
} // class ListDV
+
+final class ListData {
+ final Object[] data;
+ private String canonical;
+ public ListData(Object[] data) {
+ this.data = data;
+ }
+ public synchronized String toString() {
+ if (canonical == null) {
+ int len = data.length;
+ StringBuffer buf = new StringBuffer();
+ if (len > 0) {
+ buf.append(data[0].toString());
+ }
+ for (int i = 1; i < len; i++) {
+ buf.append(' ');
+ buf.append(data[i].toString());
+ }
+ canonical = buf.toString();
+ }
+ return canonical;
+ }
+ public int length() {
+ return data.length;
+ }
+ public Object item(int index) {
+ return data[index];
+ }
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ListData))
+ return false;
+ Object[] odata = ((ListData)obj).data;
+
+ int count = data.length;
+ if (count != odata.length)
+ return false;
+
+ for (int i = 0 ; i < count ; i++) {
+ if (!data[i].equals(odata[i]))
+ return false;
+ }//end of loop
+
+ //everything went fine.
+ return true;
+ }
+}
1.8 +2 -2 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MonthDV.java 20 Aug 2002 23:03:21 -0000 1.7
+++ MonthDV.java 18 Nov 2002 23:10:10 -0000 1.8
@@ -79,7 +79,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException{
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "gMonth"});
}
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MonthDayDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ MonthDayDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -82,7 +82,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "gMonthDay"});
}
1.5 +36 -3 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/QNameDV.java
Index: QNameDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/QNameDV.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- QNameDV.java 30 Aug 2002 02:53:04 -0000 1.4
+++ QNameDV.java 18 Nov 2002 23:10:10 -0000 1.5
@@ -105,14 +105,47 @@
if (prefix.length() > 0 && uri == null)
throw new InvalidDatatypeValueException("UndeclaredPrefix", new
Object[]{content, prefix});
- return new QName(prefix, context.getSymbol(localpart),
context.getSymbol(content), uri);
+ return new XQName(prefix, context.getSymbol(localpart),
context.getSymbol(content), uri);
}
// REVISIT: qname and notation shouldn't support length facets.
// now we just return the length of the rawname
public int getDataLength(Object value) {
- return ((QName)value).rawname.length();
+ return ((XQName)value).rawname.length();
}
+ /**
+ * represent QName data
+ */
+ private static final class XQName extends QName {
+ /** Constructs a QName with the specified values. */
+ public XQName(String prefix, String localpart, String rawname, String uri) {
+ setValues(prefix, localpart, rawname, uri);
+ } // <init>(String,String,String,String)
+
+ /** Returns true if the two objects are equal. */
+ public boolean equals(Object object) {
+ if (object instanceof QName) {
+ QName qname = (QName)object;
+ return uri == qname.uri && localpart == qname.localpart;
+ }
+ return false;
+ } // equals(Object):boolean
+
+ // canonical representation of the data
+ private String canonical;
+ public synchronized String toString() {
+ // REVISIT: what's the canonical form for QName?
+ if (canonical == null) {
+ if (prefix == null) {
+ canonical = localpart;
+ }
+ else {
+ canonical = prefix + ':' + localpart;
+ }
+ }
+ return canonical;
+ }
+ }
} // class QNameDVDV
1.10 +2 -4
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/SchemaDVFactoryImpl.java
Index: SchemaDVFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/SchemaDVFactoryImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SchemaDVFactoryImpl.java 8 Nov 2002 16:46:39 -0000 1.9
+++ SchemaDVFactoryImpl.java 18 Nov 2002 23:10:10 -0000 1.10
@@ -241,9 +241,7 @@
fBuiltInTypes.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY,
XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true));
fBuiltInTypes.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH,
XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true));
- facets.fractionDigits = 0;
- XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER,
URI_SCHEMAFORSCHEMA, (short)0, false);
- integerDV.applyFacets1(facets , XSSimpleType.FACET_FRACTIONDIGITS,
(short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_INTEGER);
+ XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER,
XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true);
fBuiltInTypes.put(INTEGER, integerDV);
facets.maxInclusive = "0";
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TimeDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ TimeDV.java 18 Nov 2002 23:10:10 -0000 1.6
@@ -78,7 +78,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException{
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "time"});
}
1.5 +2 -8
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TypeValidator.java
Index: TypeValidator.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TypeValidator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TypeValidator.java 18 Jul 2002 20:48:43 -0000 1.4
+++ TypeValidator.java 18 Nov 2002 23:10:10 -0000 1.5
@@ -61,7 +61,7 @@
import org.apache.xerces.impl.dv.ValidationContext;
/**
- * All primitive types plus ID/IDREF/ENTITY are derived from this abstract
+ * All primitive types plus ID/IDREF/ENTITY/INTEGER are derived from this abstract
* class. It provides extra information XSSimpleTypeDecl requires from each
* type: allowed facets, converting String to actual value, check equality,
* comparison, etc.
@@ -87,12 +87,6 @@
// checked to be valid with respect to both lexical representation and
// facets
public void checkExtraRules(Object value, ValidationContext context) throws
InvalidDatatypeValueException {
- }
-
- // whether two values are equal
- // the parameters are in compiled form (from getActualValue)
- public boolean isEqual(Object value1, Object value2) {
- return value1.equals(value2);
}
// the following methods might not be supported by every DV.
1.23 +62 -98
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
Index: XSSimpleTypeDecl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XSSimpleTypeDecl.java 4 Nov 2002 18:36:18 -0000 1.22
+++ XSSimpleTypeDecl.java 18 Nov 2002 23:10:10 -0000 1.23
@@ -106,8 +106,9 @@
static final short DV_ID = DV_NOTATION + 1;
static final short DV_IDREF = DV_NOTATION + 2;
static final short DV_ENTITY = DV_NOTATION + 3;
- static final short DV_LIST = DV_NOTATION + 4;
- static final short DV_UNION = DV_NOTATION + 5;
+ static final short DV_INTEGER = DV_NOTATION + 4;
+ static final short DV_LIST = DV_NOTATION + 5;
+ static final short DV_UNION = DV_NOTATION + 6;
static final TypeValidator[] fDVs = {
new AnySimpleDV(),
@@ -133,6 +134,7 @@
new IDDV(),
new IDREFDV(),
new EntityDV(),
+ new IntegerDV(),
new ListDV(),
new UnionDV()
};
@@ -164,6 +166,7 @@
NORMALIZE_TRIM, //IDDV(),
NORMALIZE_TRIM, //IDREFDV(),
NORMALIZE_TRIM, //EntityDV(),
+ NORMALIZE_TRIM, //IntegerDV(),
NORMALIZE_FULL, //ListDV(),
NORMALIZE_NONE, //UnionDV()
};
@@ -172,7 +175,6 @@
static final short SPECIAL_PATTERN_NMTOKEN = 1;
static final short SPECIAL_PATTERN_NAME = 2;
static final short SPECIAL_PATTERN_NCNAME = 3;
- static final short SPECIAL_PATTERN_INTEGER = 4;
static final String[] SPECIAL_PATTERN_STRING = {
"NONE", "NMTOKEN", "Name", "NCName", "integer"
@@ -259,7 +261,7 @@
// default constructor
public XSSimpleTypeDecl(){}
- //Create a new built-in primitive types (and id/idref/entity)
+ //Create a new built-in primitive types (and id/idref/entity/integer)
protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, short validateDV,
short ordered, boolean bounded,
boolean finite, boolean numeric, boolean
isImmutable) {
@@ -520,8 +522,10 @@
public short getPrimitiveKind() {
if (fVariety == VARIETY_ATOMIC && fValidationDV != DV_ANYSIMPLETYPE) {
- if (fVariety == DV_ID || fVariety == DV_IDREF || fVariety == DV_ENTITY)
+ if (fValidationDV == DV_ID || fValidationDV == DV_IDREF ||
fValidationDV == DV_ENTITY)
return DV_STRING;
+ else if (fValidationDV == DV_INTEGER)
+ return DV_DECIMAL;
else
return fValidationDV;
}
@@ -737,7 +741,7 @@
if (((fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMaxInclusive,
fBase.fMaxInclusive);
if ((fBase.fFixedFacet & FACET_MAXINCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"maxInclusive", getStringValue(fMaxInclusive),
getStringValue(fBase.fMaxInclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"maxInclusive", fMaxInclusive, fBase.fMaxInclusive});
}
if (result == 0) {
needCheckBase = false;
@@ -754,6 +758,7 @@
}
// maxExclusive
+ needCheckBase = true;
if ((presentFacet & FACET_MAXEXCLUSIVE) != 0) {
if ((allowedFacet & FACET_MAXEXCLUSIVE) == 0) {
reportError("cos-applicable-facets", new Object[]{"maxExclusive"});
@@ -771,7 +776,7 @@
if (((fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMaxExclusive,
fBase.fMaxExclusive);
if ((fBase.fFixedFacet & FACET_MAXEXCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"maxExclusive", facets.maxExclusive, getStringValue(fBase.fMaxExclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"maxExclusive", facets.maxExclusive, fBase.fMaxExclusive});
}
if (result == 0) {
needCheckBase = false;
@@ -787,6 +792,7 @@
}
}
// minExclusive
+ needCheckBase = true;
if ((presentFacet & FACET_MINEXCLUSIVE) != 0) {
if ((allowedFacet & FACET_MINEXCLUSIVE) == 0) {
reportError("cos-applicable-facets", new Object[]{"minExclusive"});
@@ -804,7 +810,7 @@
if (((fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMinExclusive,
fBase.fMinExclusive);
if ((fBase.fFixedFacet & FACET_MINEXCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"minExclusive", facets.minExclusive, getStringValue(fBase.fMinExclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"minExclusive", facets.minExclusive, fBase.fMinExclusive});
}
if (result == 0) {
needCheckBase = false;
@@ -820,6 +826,7 @@
}
}
// minInclusive
+ needCheckBase = true;
if ((presentFacet & FACET_MININCLUSIVE) != 0) {
if ((allowedFacet & FACET_MININCLUSIVE) == 0) {
reportError("cos-applicable-facets", new Object[]{"minInclusive"});
@@ -837,7 +844,7 @@
if (((fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMinInclusive,
fBase.fMinInclusive);
if ((fBase.fFixedFacet & FACET_MININCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"minInclusive", facets.minInclusive, getStringValue(fBase.fMinInclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"minInclusive", facets.minInclusive, fBase.fMinInclusive});
}
if (result == 0) {
needCheckBase = false;
@@ -913,26 +920,26 @@
if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined &
FACET_MININCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMinInclusive, fMaxInclusive);
if (result != -1 && result != 0)
- reportError("minInclusive-less-than-equal-to-maxInclusive", new
Object[]{getStringValue(fMinInclusive), getStringValue(fMaxInclusive)});
+ reportError("minInclusive-less-than-equal-to-maxInclusive", new
Object[]{fMinInclusive, fMaxInclusive});
}
// check 4.3.8.c2 must: minExclusive <= maxExclusive ??? minExclusive <
maxExclusive
if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined &
FACET_MINEXCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMinExclusive, fMaxExclusive);
if (result != -1 && result != 0)
- reportError( "minExclusive-less-than-equal-to-maxExclusive", new
Object[]{getStringValue(fMinExclusive), getStringValue(fMaxExclusive)});
+ reportError( "minExclusive-less-than-equal-to-maxExclusive", new
Object[]{fMinExclusive, fMaxExclusive});
}
// check 4.3.9.c2 must: minExclusive < maxInclusive
if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined &
FACET_MINEXCLUSIVE) != 0)) {
if (fDVs[fValidationDV].compare(fMinExclusive, fMaxInclusive) != -1)
- reportError( "minExclusive-less-than-maxInclusive", new
Object[]{getStringValue(fMinExclusive), getStringValue(fMaxInclusive)});
+ reportError( "minExclusive-less-than-maxInclusive", new
Object[]{fMinExclusive, fMaxInclusive});
}
// check 4.3.10.c1 must: minInclusive < maxExclusive
if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined &
FACET_MININCLUSIVE) != 0)) {
if (fDVs[fValidationDV].compare(fMinInclusive, fMaxExclusive) != -1)
- reportError( "minInclusive-less-than-maxExclusive", new
Object[]{getStringValue(fMinInclusive), getStringValue(fMaxExclusive)});
+ reportError( "minInclusive-less-than-maxExclusive", new
Object[]{fMinInclusive, fMaxExclusive});
}
// check 4.3.12.c1 must: fractionDigits <= totalDigits
@@ -1013,27 +1020,27 @@
if (((fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMaxInclusive,
fBase.fMaxInclusive);
if ((fBase.fFixedFacet & FACET_MAXINCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"maxInclusive", getStringValue(fMaxInclusive),
getStringValue(fBase.fMaxInclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"maxInclusive", fMaxInclusive), fBase.fMaxInclusive)});
}
if (result != -1 && result != 0) {
- reportError( "maxInclusive-valid-restriction.1", new
Object[]{getStringValue(fMaxInclusive), getStringValue(fBase.fMaxInclusive)});
+ reportError( "maxInclusive-valid-restriction.1", new
Object[]{fMaxInclusive), fBase.fMaxInclusive)});
}
}
if (((fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMaxExclusive)
!= -1){
- reportError( "maxInclusive-valid-restriction.1", new
Object[]{getStringValue(fMaxInclusive), getStringValue(fBase.fMaxExclusive)});
+ reportError( "maxInclusive-valid-restriction.1", new
Object[]{fMaxInclusive), fBase.fMaxExclusive)});
}
if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
result = fDVs[fValidationDV].compare(fMaxInclusive,
fBase.fMinInclusive);
if (result != 1 && result != 0) {
- reportError( "maxInclusive-valid-restriction.1", new
Object[]{getStringValue(fMaxInclusive), getStringValue(fBase.fMinInclusive)});
+ reportError( "maxInclusive-valid-restriction.1", new
Object[]{fMaxInclusive), fBase.fMinInclusive)});
}
}
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMinExclusive
) != 1)
- reportError( "maxInclusive-valid-restriction.1", new
Object[]{getStringValue(fMaxInclusive), getStringValue(fBase.fMinExclusive)});
+ reportError( "maxInclusive-valid-restriction.1", new
Object[]{fMaxInclusive), fBase.fMinExclusive)});
}
// check 4.3.8.c3 error:
@@ -1045,27 +1052,27 @@
if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) {
result= fDVs[fValidationDV].compare(fMaxExclusive,
fBase.fMaxExclusive);
if ((fBase.fFixedFacet & FACET_MAXEXCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"maxExclusive", getStringValue(fMaxExclusive),
getStringValue(fBase.fMaxExclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"maxExclusive", fMaxExclusive), fBase.fMaxExclusive)});
}
if (result != -1 && result != 0) {
- reportError( "maxExclusive-valid-restriction.1", new
Object[]{getStringValue(fMaxExclusive), getStringValue(fBase.fMaxExclusive)});
+ reportError( "maxExclusive-valid-restriction.1", new
Object[]{fMaxExclusive), fBase.fMaxExclusive)});
}
}
if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
result= fDVs[fValidationDV].compare(fMaxExclusive,
fBase.fMaxInclusive);
if (result != -1 && result != 0) {
- reportError( "maxExclusive-valid-restriction.2", new
Object[]{getStringValue(fMaxExclusive), getStringValue(fBase.fMaxInclusive)});
+ reportError( "maxExclusive-valid-restriction.2", new
Object[]{fMaxExclusive), fBase.fMaxInclusive)});
}
}
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMinExclusive
) != 1)
- reportError( "maxExclusive-valid-restriction.3", new
Object[]{getStringValue(fMaxExclusive), getStringValue(fBase.fMinExclusive)});
+ reportError( "maxExclusive-valid-restriction.3", new
Object[]{fMaxExclusive), fBase.fMinExclusive)});
if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMinInclusive)
!= 1)
- reportError( "maxExclusive-valid-restriction.4", new
Object[]{getStringValue(fMaxExclusive), getStringValue(fBase.fMinInclusive)});
+ reportError( "maxExclusive-valid-restriction.4", new
Object[]{fMaxExclusive), fBase.fMinInclusive)});
}
// check 4.3.9.c3 error:
@@ -1077,10 +1084,10 @@
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) {
result= fDVs[fValidationDV].compare(fMinExclusive,
fBase.fMinExclusive);
if ((fBase.fFixedFacet & FACET_MINEXCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"minExclusive", getStringValue(fMinExclusive),
getStringValue(fBase.fMinExclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"minExclusive", fMinExclusive), fBase.fMinExclusive)});
}
if (result != 1 && result != 0) {
- reportError( "minExclusive-valid-restriction.1", new
Object[]{getStringValue(fMinExclusive), getStringValue(fBase.fMinExclusive)});
+ reportError( "minExclusive-valid-restriction.1", new
Object[]{fMinExclusive), fBase.fMinExclusive)});
}
}
@@ -1088,7 +1095,7 @@
result=fDVs[fValidationDV].compare(fMinExclusive,
fBase.fMaxInclusive);
if (result != -1 && result != 0) {
- reportError( "minExclusive-valid-restriction.2", new
Object[]{getStringValue(fMinExclusive), getStringValue(fBase.fMaxInclusive)});
+ reportError( "minExclusive-valid-restriction.2", new
Object[]{fMinExclusive), fBase.fMaxInclusive)});
}
}
@@ -1096,13 +1103,13 @@
result = fDVs[fValidationDV].compare(fMinExclusive,
fBase.fMinInclusive);
if (result != 1 && result != 0) {
- reportError( "minExclusive-valid-restriction.3", new
Object[]{getStringValue(fMinExclusive), getStringValue(fBase.fMinInclusive)});
+ reportError( "minExclusive-valid-restriction.3", new
Object[]{fMinExclusive), fBase.fMinInclusive)});
}
}
if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMinExclusive, fBase.fMaxExclusive)
!= -1)
- reportError( "minExclusive-valid-restriction.4", new
Object[]{getStringValue(fMinExclusive), getStringValue(fBase.fMaxExclusive)});
+ reportError( "minExclusive-valid-restriction.4", new
Object[]{fMinExclusive), fBase.fMaxExclusive)});
}
// check 4.3.10.c2 error:
@@ -1115,24 +1122,24 @@
result = fDVs[fValidationDV].compare(fMinInclusive,
fBase.fMinInclusive);
if ((fBase.fFixedFacet & FACET_MININCLUSIVE) != 0 && result !=
0) {
- reportError( "FixedFacetValue", new
Object[]{"minInclusive", getStringValue(fMinInclusive),
getStringValue(fBase.fMinInclusive)});
+ reportError( "FixedFacetValue", new
Object[]{"minInclusive", fMinInclusive), fBase.fMinInclusive)});
}
if (result != 1 && result != 0) {
- reportError( "minInclusive-valid-restriction.1", new
Object[]{getStringValue(fMinInclusive), getStringValue(fBase.fMinInclusive)});
+ reportError( "minInclusive-valid-restriction.1", new
Object[]{fMinInclusive), fBase.fMinInclusive)});
}
}
if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
result=fDVs[fValidationDV].compare(fMinInclusive,
fBase.fMaxInclusive);
if (result != -1 && result != 0) {
- reportError( "minInclusive-valid-restriction.2", new
Object[]{getStringValue(fMinInclusive), getStringValue(fBase.fMaxInclusive)});
+ reportError( "minInclusive-valid-restriction.2", new
Object[]{fMinInclusive), fBase.fMaxInclusive)});
}
}
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMinInclusive, fBase.fMinExclusive
) != 1)
- reportError( "minInclusive-valid-restriction.3", new
Object[]{getStringValue(fMinInclusive), getStringValue(fBase.fMinExclusive)});
+ reportError( "minInclusive-valid-restriction.3", new
Object[]{fMinInclusive), fBase.fMinExclusive)});
if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) &&
fDVs[fValidationDV].compare(fMinInclusive, fBase.fMaxExclusive)
!= -1)
- reportError( "minInclusive-valid-restriction.4", new
Object[]{getStringValue(fMinInclusive), getStringValue(fBase.fMaxExclusive)});
+ reportError( "minInclusive-valid-restriction.4", new
Object[]{fMinInclusive), fBase.fMaxExclusive)});
}
*/
// check 4.3.11.c1 error: totalDigits > fBase.totalDigits
@@ -1362,7 +1369,7 @@
if ( ((fFacetsDefined & FACET_ENUMERATION) != 0 ) ) {
boolean present = false;
for (int i = 0; i < fEnumeration.size(); i++) {
- if (isEqual(ob, fEnumeration.elementAt(i))) {
+ if (fEnumeration.elementAt(i).equals(ob)) {
present = true;
break;
}
@@ -1441,19 +1448,20 @@
} else if (fVariety == VARIETY_LIST) {
- Object[] values = (Object[])ob;
+ ListData values = (ListData)ob;
+ int len = values.length();
if (fItemType.fVariety == VARIETY_UNION) {
XSSimpleTypeDecl[] memberTypes =
(XSSimpleTypeDecl[])validatedInfo.memberTypes;
XSSimpleType memberType = validatedInfo.memberType;
- for (int i = values.length-1; i >= 0; i--) {
- validatedInfo.actualValue = values[i];
+ for (int i = len-1; i >= 0; i--) {
+ validatedInfo.actualValue = values.item(i);
validatedInfo.memberType = memberTypes[i];
fItemType.checkExtraRules(context, validatedInfo);
}
validatedInfo.memberType = memberType;
} else { // (fVariety == VARIETY_ATOMIC)
- for (int i = values.length-1; i >= 0; i--) {
- validatedInfo.actualValue = values[i];
+ for (int i = len-1; i >= 0; i--) {
+ validatedInfo.actualValue = values.item(i);
fItemType.checkExtraRules(context, validatedInfo);
}
}
@@ -1508,12 +1516,6 @@
// PATTERN "[\\i-[:]][\\c-[:]]*"
seenErr = !XMLChar.isValidNCName(nvalue);
}
- else if (fPatternType == SPECIAL_PATTERN_INTEGER) {
- // REVISIT: the pattern is not published yet
- // we only need to worry about the period '.'
- // other parts are taken care of by the DecimalDV
- seenErr = nvalue.indexOf('.') >= 0;
- }
if (seenErr) {
throw new
InvalidDatatypeValueException("cvc-datatype-valid.1.2.1",
new Object[]{nvalue,
SPECIAL_PATTERN_STRING[fPatternType]});
@@ -1547,12 +1549,13 @@
memberTypes[i] = (XSSimpleTypeDecl)validatedInfo.memberType;
}
- validatedInfo.actualValue = avalue;
+ ListData v = new ListData(avalue);
+ validatedInfo.actualValue = v;
validatedInfo.memberType = null;
validatedInfo.memberTypes = memberTypes;
validatedInfo.normalizedValue = nvalue;
- return avalue;
+ return v;
} else { // (fVariety == VARIETY_UNION)
for(int i = 0 ; i < fMemberTypes.length; i++) {
@@ -1580,41 +1583,10 @@
}//getActualValue()
-
public boolean isEqual(Object value1, Object value2) {
-
- if (fVariety == VARIETY_ATOMIC)
- return fDVs[fValidationDV].isEqual(value1,value2);
-
- else if (fVariety == VARIETY_LIST) {
- if (!(value1 instanceof Object[]) || !(value2 instanceof Object[]))
- return false;
-
- Object[] v1 = (Object[])value1;
- Object[] v2 = (Object[])value2;
-
- int count = v1.length;
- if (count != v2.length)
- return false;
-
- for (int i = 0 ; i < count ; i++) {
- if (!fItemType.isEqual(v1[i], v2[i]))
- return false;
- }//end of loop
-
- //everything went fine.
- return true;
-
- } else if (fVariety == VARIETY_UNION) {
- for (int i = fMemberTypes.length-1; i >= 0; i--) {
- if (fMemberTypes[i].isEqual(value1,value2)){
- return true;
- }
- }
+ if (value1 == null)
return false;
- }
-
- return false;
+ return value1.equals(value2);
}//isEqual()
// normalize the string according to the whiteSpace facet
@@ -1734,17 +1706,6 @@
return WS_FACET_STRING[ws];
}
- public String getStringValue(Object value){
- if(value != null) {
- if (fDVs[fValidationDV] instanceof AbstractDateTimeDV)
- return
((AbstractDateTimeDV)fDVs[fValidationDV]).dateToString((int[])value);
- else
- return value.toString();
- } else {
- return null;
- }
- }
-
public short getOrdered() {
return fOrdered;
}
@@ -1788,13 +1749,13 @@
case FACET_WHITESPACE:
return WS_FACET_STRING[fWhiteSpace];
case FACET_MAXINCLUSIVE:
- return getStringValue(fMaxInclusive);
+ return fMaxInclusive.toString();
case FACET_MAXEXCLUSIVE:
- return getStringValue(fMaxExclusive);
+ return fMaxExclusive.toString();
case FACET_MINEXCLUSIVE:
- return getStringValue(fMinExclusive);
+ return fMinExclusive.toString();
case FACET_MININCLUSIVE:
- return getStringValue(fMinInclusive);
+ return fMinInclusive.toString();
case FACET_TOTALDIGITS:
return Integer.toString(fTotalDigits);
case FACET_FRACTIONDIGITS:
@@ -1811,7 +1772,7 @@
int size = fEnumeration.size();
String[] strs = new String[size];
for (int i = 0; i < size; i++)
- strs[i] = getStringValue(fEnumeration.elementAt(i));
+ strs[i] = fEnumeration.elementAt(i).toString();
return new StringListImpl(strs, size);
}
@@ -2008,7 +1969,10 @@
if (validationDV == DV_ID || validationDV == DV_IDREF || validationDV ==
DV_ENTITY){
return DV_STRING;
}
- else{
+ else if (validationDV == DV_INTEGER) {
+ return DV_DECIMAL;
+ }
+ else {
return validationDV;
}
1.6 +2 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- YearDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ YearDV.java 18 Nov 2002 23:10:11 -0000 1.6
@@ -79,7 +79,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException{
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "gYear"});
}
1.6 +2 -2
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- YearMonthDV.java 18 Jul 2002 20:48:43 -0000 1.5
+++ YearMonthDV.java 18 Nov 2002 23:10:11 -0000 1.6
@@ -78,7 +78,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException{
try{
- return parse(content);
+ return new DateTimeData(parse(content), this);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "gYearMonth"});
}
1.1 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/IntegerDV.java
Index: IntegerDV.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 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 [EMAIL PROTECTED]
*
* 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.dv.xs;
import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
import org.apache.xerces.impl.dv.ValidationContext;
/**
* Represent the schema type "integer"
*
* @author Sandy Gao, IBM
*
* @version $Id: IntegerDV.java,v 1.1 2002/11/18 23:10:10 sandygao Exp $
*/
public class IntegerDV extends DecimalDV {
public Object getActualValue(String content, ValidationContext context) throws
InvalidDatatypeValueException {
try {
return new XDecimal(content, true);
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new
Object[]{content, "integer"});
}
}
} // class EntityDV
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]