You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2018/05/04 09:03:21 UTC
[20/24] jena git commit: JENA-1537: Remove dependency on Xerces.
Import needed code
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AbstractDateTimeDV.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AbstractDateTimeDV.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AbstractDateTimeDV.java
new file mode 100644
index 0000000..e91c639
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AbstractDateTimeDV.java
@@ -0,0 +1,1107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import java.math.BigDecimal;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.jena.ext.xerces.DatatypeFactoryInst;
+import org.apache.jena.ext.xerces.impl.Constants;
+import org.apache.jena.ext.xerces.xs.datatypes.XSDateTime;
+
+/**
+ * This is the base class of all date/time datatype validators.
+ * It implements common code for parsing, validating and comparing datatypes.
+ * Classes that extend this class, must implement parse() method.
+ *
+ * REVISIT: There are many instance variables, which would cause problems
+ * when we support grammar caching. A grammar is possibly used by
+ * two parser instances at the same time, then the same simple type
+ * decl object can be used to validate two strings at the same time.
+ * -SG
+ *
+ * @xerces.internal
+ *
+ * @author Elena Litani
+ * @author Len Berman
+ * @author Gopal Sharma, SUN Microsystems Inc.
+ *
+ * @version $Id: AbstractDateTimeDV.java 965250 2010-07-18 16:04:58Z mrglavas $
+ */
+@SuppressWarnings("all")
+public abstract class AbstractDateTimeDV extends TypeValidator {
+
+ //debugging
+ private static final boolean DEBUG=false;
+
+ //define shared variables for date/time
+
+
+ //define constants to be used in assigning default values for
+ //all date/time excluding duration
+ protected final static int YEAR=2000;
+ protected final static int MONTH=01;
+ protected final static int DAY = 01;
+
+ protected static final DatatypeFactory datatypeFactory = DatatypeFactoryInst.newDatatypeFactory();
+
+ 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()
+
+
+ // distinguishes between identity and equality for date/time values
+ // ie: two values representing the same "moment in time" but with different
+ // remembered timezones are now equal but not identical.
+ public boolean isIdentical (Object value1, Object value2) {
+ if (!(value1 instanceof DateTimeData) || !(value2 instanceof DateTimeData)) {
+ return false;
+ }
+
+ DateTimeData v1 = (DateTimeData)value1;
+ DateTimeData v2 = (DateTimeData)value2;
+
+ // original timezones must be the same in addition to date/time values
+ // being 'equal'
+ if ((v1.timezoneHr == v2.timezoneHr) && (v1.timezoneMin == v2.timezoneMin)) {
+ return v1.equals(v2);
+ }
+
+ return false;
+ }//isIdentical()
+
+ // the parameters are in compiled form (from getActualValue)
+ public int compare (Object value1, Object value2) {
+ return compareDates(((DateTimeData)value1),
+ ((DateTimeData)value2), true);
+ }//compare()
+
+ /**
+ * Compare algorithm described in dateDime (3.2.7).
+ * Duration datatype overwrites this method
+ *
+ * @param date1 normalized date representation of the first value
+ * @param date2 normalized date representation of the second value
+ * @param strict
+ * @return less, greater, less_equal, greater_equal, equal
+ */
+ protected short compareDates(DateTimeData date1, DateTimeData date2, boolean strict) {
+ if (date1.utc == date2.utc) {
+ return compareOrder(date1, date2);
+ }
+ short c1, c2;
+
+ DateTimeData tempDate = new DateTimeData(null, this);
+
+ if ( date1.utc=='Z' ) {
+
+ //compare date1<=date1<=(date2 with time zone -14)
+ //
+ cloneDate(date2, tempDate); //clones date1 value to global temporary storage: fTempDate
+ tempDate.timezoneHr=14;
+ tempDate.timezoneMin = 0;
+ tempDate.utc='+';
+ normalize(tempDate);
+ c1 = compareOrder(date1, tempDate);
+ if (c1 == LESS_THAN)
+ return c1;
+
+ //compare date1>=(date2 with time zone +14)
+ //
+ cloneDate(date2, tempDate); //clones date1 value to global temporary storage: tempDate
+ tempDate.timezoneHr = -14;
+ tempDate.timezoneMin = 0;
+ tempDate.utc='-';
+ normalize(tempDate);
+ c2 = compareOrder(date1, tempDate);
+ if (c2 == GREATER_THAN)
+ return c2;
+
+ return INDETERMINATE;
+ }
+ else if ( date2.utc=='Z' ) {
+
+ //compare (date1 with time zone -14)<=date2
+ //
+ cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate
+ tempDate.timezoneHr = -14;
+ tempDate.timezoneMin = 0;
+ tempDate.utc='-';
+ if (DEBUG) {
+ System.out.println("tempDate=" + dateToString(tempDate));
+ }
+ normalize(tempDate);
+ c1 = compareOrder(tempDate, date2);
+ if (DEBUG) {
+ System.out.println("date=" + dateToString(date2));
+ System.out.println("tempDate=" + dateToString(tempDate));
+ }
+ if (c1 == LESS_THAN)
+ return c1;
+
+ //compare (date1 with time zone +14)<=date2
+ //
+ cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate
+ tempDate.timezoneHr = 14;
+ tempDate.timezoneMin = 0;
+ tempDate.utc='+';
+ normalize(tempDate);
+ c2 = compareOrder(tempDate, date2);
+ if (DEBUG) {
+ System.out.println("tempDate=" + dateToString(tempDate));
+ }
+ if (c2 == GREATER_THAN)
+ return c2;
+
+ return INDETERMINATE;
+ }
+ return INDETERMINATE;
+
+ }
+
+ /**
+ * Given normalized values, determines order-relation
+ * between give date/time objects.
+ *
+ * @param date1 date/time object
+ * @param date2 date/time object
+ * @return 0 if date1 and date2 are equal, a value less than 0 if date1 is less than date2, a value greater than 0 if date1 is greater than date2
+ */
+ protected short compareOrder(DateTimeData date1, DateTimeData date2) {
+ if(date1.position < 1) {
+ if (date1.year < date2.year)
+ return -1;
+ if (date1.year > date2.year)
+ return 1;
+ }
+ if(date1.position < 2) {
+ if (date1.month < date2.month)
+ return -1;
+ if (date1.month > date2.month)
+ return 1;
+ }
+ if (date1.day < date2.day)
+ return -1;
+ if (date1.day > date2.day)
+ return 1;
+ if (date1.hour < date2.hour)
+ return -1;
+ if (date1.hour > date2.hour)
+ return 1;
+ if (date1.minute < date2.minute)
+ return -1;
+ if (date1.minute > date2.minute)
+ return 1;
+ if (date1.second < date2.second)
+ return -1;
+ if (date1.second > date2.second)
+ return 1;
+ if (date1.utc < date2.utc)
+ return -1;
+ if (date1.utc > date2.utc)
+ return 1;
+ return 0;
+ }
+
+ /**
+ * Parses time hh:mm:ss.sss and time zone if any
+ *
+ * @param start
+ * @param end
+ * @param data
+ * @exception RuntimeException
+ */
+ protected void getTime (String buffer, int start, int end, DateTimeData data) throws RuntimeException{
+
+ int stop = start+2;
+
+ //get hours (hh)
+ data.hour=parseInt(buffer, start,stop);
+
+ //get minutes (mm)
+
+ if (buffer.charAt(stop++)!=':') {
+ throw new RuntimeException("Error in parsing time zone" );
+ }
+ start = stop;
+ stop = stop+2;
+ data.minute=parseInt(buffer, start,stop);
+
+ //get seconds (ss)
+ if (buffer.charAt(stop++)!=':') {
+ throw new RuntimeException("Error in parsing time zone" );
+ }
+
+ //find UTC sign if any
+ int sign = findUTCSign(buffer, start, end);
+
+ //get seconds (ms)
+ start = stop;
+ stop = sign < 0 ? end : sign;
+ data.second = parseSecond(buffer, start, stop);
+
+ //parse UTC time zone (hh:mm)
+ if (sign > 0) {
+ getTimeZone(buffer, data, sign, end);
+ }
+ }
+
+ /**
+ * Parses date CCYY-MM-DD
+ *
+ * @param buffer
+ * @param start start position
+ * @param end end position
+ * @param date
+ * @exception RuntimeException
+ */
+ protected int getDate (String buffer, int start, int end, DateTimeData date) throws RuntimeException{
+
+ start = getYearMonth(buffer, start, end, date);
+
+ if (buffer.charAt(start++) !='-') {
+ throw new RuntimeException("CCYY-MM must be followed by '-' sign");
+ }
+ int stop = start + 2;
+ date.day=parseInt(buffer, start, stop);
+ return stop;
+ }
+
+ /**
+ * Parses date CCYY-MM
+ *
+ * @param buffer
+ * @param start start position
+ * @param end end position
+ * @param date
+ * @exception RuntimeException
+ */
+ protected int getYearMonth (String buffer, int start, int end, DateTimeData date) throws RuntimeException{
+
+ if ( buffer.charAt(0)=='-' ) {
+ // REVISIT: date starts with preceding '-' sign
+ // do we have to do anything with it?
+ //
+ start++;
+ }
+ 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 && 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.year= parseIntYear(buffer, i);
+ if (buffer.charAt(i)!='-') {
+ throw new RuntimeException("CCYY must be followed by '-' sign");
+ }
+ start = ++i;
+ i = start +2;
+ date.month=parseInt(buffer, start, i);
+ return i; //fStart points right after the MONTH
+ }
+
+ /**
+ * Shared code from Date and YearMonth datatypes.
+ * Finds if time zone sign is present
+ *
+ * @param end
+ * @param date
+ * @exception RuntimeException
+ */
+ protected void parseTimeZone (String buffer, int start, int end, DateTimeData date) throws RuntimeException{
+
+ //fStart points right after the date
+
+ if ( start < end ) {
+ if (!isNextCharUTCSign(buffer, start, end)) {
+ throw new RuntimeException ("Error in month parsing");
+ }
+ else {
+ getTimeZone(buffer, date, start, end);
+ }
+ }
+ }
+
+ /**
+ * Parses time zone: 'Z' or {+,-} followed by hh:mm
+ *
+ * @param data
+ * @param sign
+ * @exception RuntimeException
+ */
+ protected void getTimeZone (String buffer, DateTimeData data, int sign, int end) throws RuntimeException{
+ data.utc=buffer.charAt(sign);
+
+ if ( buffer.charAt(sign) == 'Z' ) {
+ if (end>(++sign)) {
+ throw new RuntimeException("Error in parsing time zone");
+ }
+ return;
+ }
+ if ( sign<=(end-6) ) {
+
+ int negate = buffer.charAt(sign) == '-'?-1:1;
+ //parse hr
+ int stop = ++sign+2;
+ data.timezoneHr = negate*parseInt(buffer, sign, stop);
+ if (buffer.charAt(stop++)!=':') {
+ throw new RuntimeException("Error in parsing time zone" );
+ }
+
+ //parse min
+ data.timezoneMin = negate*parseInt(buffer, stop, stop+2);
+
+ if ( stop+2!=end ) {
+ throw new RuntimeException("Error in parsing time zone");
+ }
+ if(data.timezoneHr != 0 || data.timezoneMin != 0)
+ data.normalized = false;
+ }
+ else {
+ throw new RuntimeException("Error in parsing time zone");
+ }
+ if ( DEBUG ) {
+ System.out.println("time[hh]="+data.timezoneHr + " time[mm]=" +data.timezoneMin);
+ }
+ }
+
+ /**
+ * Computes index of given char within StringBuffer
+ *
+ * @param start
+ * @param end
+ * @param ch character to look for in StringBuffer
+ * @return index of ch within StringBuffer
+ */
+ protected int indexOf (String buffer, int start, int end, char ch) {
+ for ( int i=start;i<end;i++ ) {
+ if ( buffer.charAt(i) == ch ) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Validates given date/time object accoring to W3C PR Schema
+ * [D.1 ISO 8601 Conventions]
+ *
+ * @param data
+ */
+ protected void validateDateTime (DateTimeData data) {
+
+ //REVISIT: should we throw an exception for not valid dates
+ // or reporting an error message should be sufficient?
+
+ /**
+ * XML Schema 1.1 - RQ-123: Allow year 0000 in date related types.
+ */
+ if (!Constants.SCHEMA_1_1_SUPPORT && data.year==0 ) {
+ throw new RuntimeException("The year \"0000\" is an illegal year value");
+
+ }
+
+ if ( data.month<1 || data.month>12 ) {
+ throw new RuntimeException("The month must have values 1 to 12");
+
+ }
+
+ //validate days
+ if ( data.day>maxDayInMonthFor(data.year, data.month) || data.day<1 ) {
+ throw new RuntimeException("The day must have values 1 to 31");
+ }
+
+ //validate hours
+ if ( data.hour>23 || data.hour<0 ) {
+ if (data.hour == 24 && data.minute == 0 && data.second == 0) {
+ data.hour = 0;
+ if (++data.day > maxDayInMonthFor(data.year, data.month)) {
+ data.day = 1;
+ if (++data.month > 12) {
+ data.month = 1;
+ if (Constants.SCHEMA_1_1_SUPPORT) {
+ ++data.year;
+ }
+ else if (++data.year == 0) {
+ data.year = 1;
+ }
+ }
+ }
+ }
+ else {
+ throw new RuntimeException("Hour must have values 0-23, unless 24:00:00");
+ }
+ }
+
+ //validate
+ if ( data.minute>59 || data.minute<0 ) {
+ throw new RuntimeException("Minute must have values 0-59");
+ }
+
+ //validate
+ if ( data.second>=60 || data.second<0 ) {
+ throw new RuntimeException("Second must have values 0-59");
+
+ }
+
+ //validate
+ if ( data.timezoneHr>14 || data.timezoneHr<-14 ) {
+ throw new RuntimeException("Time zone should have range -14:00 to +14:00");
+ }
+ else {
+ if((data.timezoneHr == 14 || data.timezoneHr == -14) && data.timezoneMin != 0)
+ throw new RuntimeException("Time zone should have range -14:00 to +14:00");
+ else if(data.timezoneMin > 59 || data.timezoneMin < -59)
+ throw new RuntimeException("Minute must have values 0-59");
+ }
+
+ }
+
+ /**
+ * Return index of UTC char: 'Z', '+', '-'
+ *
+ * @param start
+ * @param end
+ * @return index of the UTC character that was found
+ */
+ protected int findUTCSign (String buffer, int start, int end) {
+ int c;
+ for ( int i=start;i<end;i++ ) {
+ c=buffer.charAt(i);
+ if ( c == 'Z' || c=='+' || c=='-' ) {
+ return i;
+ }
+
+ }
+ return -1;
+ }
+
+ /**
+ * Returns <code>true</code> if the character at start is 'Z', '+' or '-'.
+ */
+ protected final boolean isNextCharUTCSign(String buffer, int start, int end) {
+ if (start < end) {
+ char c = buffer.charAt(start);
+ return (c == 'Z' || c == '+' || c == '-');
+ }
+ return false;
+ }
+
+ /**
+ * Given start and end position, parses string value
+ *
+ * @param buffer string to parse
+ * @param start start position
+ * @param end end position
+ * @return return integer representation of characters
+ */
+ protected int parseInt (String buffer, int start, int end)
+ throws NumberFormatException{
+ //REVISIT: more testing on this parsing needs to be done.
+ int radix=10;
+ int result = 0;
+ int digit=0;
+ int limit = -Integer.MAX_VALUE;
+ int multmin = limit / radix;
+ int i = start;
+ do {
+ digit = getDigit(buffer.charAt(i));
+ if ( digit < 0 ) throw new NumberFormatException("'" + buffer + "' has wrong format");
+ if ( result < multmin ) throw new NumberFormatException("'" + buffer + "' has wrong format");
+ result *= radix;
+ if ( result < limit + digit ) throw new NumberFormatException("'" + buffer + "' has wrong format");
+ result -= digit;
+
+ }while ( ++i < end );
+ return -result;
+ }
+
+ // parse Year differently to support negative value.
+ protected int parseIntYear (String buffer, int end){
+ int radix=10;
+ int result = 0;
+ boolean negative = false;
+ int i=0;
+ int limit;
+ int multmin;
+ int digit=0;
+
+ if (buffer.charAt(0) == '-'){
+ negative = true;
+ limit = Integer.MIN_VALUE;
+ i++;
+
+ }
+ else{
+ limit = -Integer.MAX_VALUE;
+ }
+ multmin = limit / radix;
+ while (i < end)
+ {
+ digit = getDigit(buffer.charAt(i++));
+ if (digit < 0) throw new NumberFormatException("'" + buffer + "' has wrong format");
+ if (result < multmin) throw new NumberFormatException("'" + buffer + "' has wrong format");
+ result *= radix;
+ if (result < limit + digit) throw new NumberFormatException("'" + buffer + "' has wrong format");
+ result -= digit;
+ }
+
+ if (negative)
+ {
+ if (i > 1) return result;
+ else throw new NumberFormatException("'" + buffer + "' has wrong format");
+ }
+ return -result;
+
+ }
+
+ /**
+ * If timezone present - normalize dateTime [E Adding durations to dateTimes]
+ *
+ * @param date CCYY-MM-DDThh:mm:ss+03
+ */
+ protected void normalize(DateTimeData date) {
+
+ // REVISIT: we have common code in addDuration() for durations
+ // should consider reorganizing it.
+ //
+
+ //add minutes (from time zone)
+ int negate = -1;
+
+ if ( DEBUG ) {
+ System.out.println("==>date.minute"+date.minute);
+ System.out.println("==>date.timezoneMin" +date.timezoneMin);
+ }
+ int temp = date.minute + negate * date.timezoneMin;
+ int carry = fQuotient (temp, 60);
+ date.minute= mod(temp, 60, carry);
+
+ if ( DEBUG ) {
+ System.out.println("==>carry: " + carry);
+ }
+ //add hours
+ temp = date.hour + negate * date.timezoneHr + carry;
+ carry = fQuotient(temp, 24);
+ date.hour=mod(temp, 24, carry);
+ if ( DEBUG ) {
+ System.out.println("==>date.hour"+date.hour);
+ System.out.println("==>carry: " + carry);
+ }
+
+ date.day=date.day+carry;
+
+ while ( true ) {
+ temp=maxDayInMonthFor(date.year, date.month);
+ if (date.day<1) {
+ date.day = date.day + maxDayInMonthFor(date.year, date.month-1);
+ carry=-1;
+ }
+ else if ( date.day>temp ) {
+ date.day=date.day-temp;
+ carry=1;
+ }
+ else {
+ break;
+ }
+ temp=date.month+carry;
+ date.month=modulo(temp, 1, 13);
+ date.year=date.year+fQuotient(temp, 1, 13);
+ if(date.year == 0 && !Constants.SCHEMA_1_1_SUPPORT) {
+ date.year = (date.timezoneHr < 0 || date.timezoneMin < 0)?1:-1;
+ }
+ }
+ date.utc='Z';
+ }
+
+
+ /**
+ * @param date
+ */
+ protected void saveUnnormalized(DateTimeData date) {
+ date.unNormYear = date.year;
+ date.unNormMonth = date.month;
+ date.unNormDay = date.day;
+ date.unNormHour = date.hour;
+ date.unNormMinute = date.minute;
+ date.unNormSecond = date.second;
+ }
+
+ /**
+ * Resets object representation of date/time
+ *
+ * @param data date/time object
+ */
+ protected void resetDateObj(DateTimeData data) {
+ data.year = 0;
+ data.month = 0;
+ data.day = 0;
+ data.hour = 0;
+ data.minute = 0;
+ data.second = 0;
+ data.utc = 0;
+ data.timezoneHr = 0;
+ data.timezoneMin = 0;
+ }
+
+ /**
+ * Given {year,month} computes maximum
+ * number of days for given month
+ *
+ * @param year
+ * @param month
+ * @return integer containg the number of days in a given month
+ */
+ protected int maxDayInMonthFor(int year, int month) {
+ //validate days
+ if ( month==4 || month==6 || month==9 || month==11 ) {
+ return 30;
+ }
+ else if ( month==2 ) {
+ if ( isLeapYear(year) ) {
+ return 29;
+ }
+ else {
+ return 28;
+ }
+ }
+ else {
+ return 31;
+ }
+ }
+
+ private boolean isLeapYear(int year) {
+
+ //REVISIT: should we take care about Julian calendar?
+ return((year%4 == 0) && ((year%100 != 0) || (year%400 == 0)));
+ }
+
+ //
+ // help function described in W3C PR Schema [E Adding durations to dateTimes]
+ //
+ protected int mod (int a, int b, int quotient) {
+ //modulo(a, b) = a - fQuotient(a,b)*b
+ return (a - quotient*b) ;
+ }
+
+ //
+ // help function described in W3C PR Schema [E Adding durations to dateTimes]
+ //
+ protected int fQuotient (int a, int b) {
+
+ //fQuotient(a, b) = the greatest integer less than or equal to a/b
+ return (int)Math.floor((float)a/b);
+ }
+
+ //
+ // help function described in W3C PR Schema [E Adding durations to dateTimes]
+ //
+ protected int modulo (int temp, int low, int high) {
+ //modulo(a - low, high - low) + low
+ int a = temp - low;
+ int b = high - low;
+ return (mod (a, b, fQuotient(a, b)) + low) ;
+ }
+
+ //
+ // help function described in W3C PR Schema [E Adding durations to dateTimes]
+ //
+ protected int fQuotient (int temp, int low, int high) {
+ //fQuotient(a - low, high - low)
+
+ return fQuotient(temp - low, high - low);
+ }
+
+
+ protected String dateToString(DateTimeData date) {
+ StringBuffer message = new StringBuffer(25);
+ append(message, date.year, 4);
+ message.append('-');
+ append(message, date.month, 2);
+ message.append('-');
+ append(message, date.day, 2);
+ message.append('T');
+ append(message, date.hour, 2);
+ message.append(':');
+ append(message, date.minute, 2);
+ message.append(':');
+ append(message, date.second);
+ append(message, (char)date.utc, 0);
+ return message.toString();
+ }
+
+ protected final void append(StringBuffer message, int value, int nch) {
+ if (value == Integer.MIN_VALUE) {
+ message.append(value);
+ return;
+ }
+ if (value < 0) {
+ message.append('-');
+ value = -value;
+ }
+ if (nch == 4) {
+ if (value < 10)
+ message.append("000");
+ else if (value < 100)
+ message.append("00");
+ else if (value < 1000)
+ message.append('0');
+ message.append(value);
+ }
+ else if (nch == 2) {
+ if (value < 10)
+ message.append('0');
+ message.append(value);
+ }
+ else {
+ if (value != 0)
+ message.append((char)value);
+ }
+ }
+
+ protected final void append(StringBuffer message, double value) {
+ if (value < 0) {
+ message.append('-');
+ value = -value;
+ }
+ if (value < 10) {
+ message.append('0');
+ }
+ append2(message, value);
+ }
+
+ protected final void append2(StringBuffer message, double value) {
+ final int intValue = (int) value;
+ if (value == intValue) {
+ message.append(intValue);
+ }
+ else {
+ append3(message, value);
+ }
+ }
+
+ private void append3(StringBuffer message, double value) {
+ String d = String.valueOf(value);
+ int eIndex = d.indexOf('E');
+ if (eIndex == -1) {
+ message.append(d);
+ return;
+ }
+ int exp;
+ if (value < 1) {
+ // Need to convert from scientific notation of the form
+ // n.nnn...E-N (N >= 4) to a normal decimal value.
+ try {
+ exp = parseInt(d, eIndex+2, d.length());
+ }
+ // This should never happen.
+ // It's only possible if String.valueOf(double) is broken.
+ catch (Exception e) {
+ message.append(d);
+ return;
+ }
+ message.append("0.");
+ for (int i = 1; i < exp; ++i) {
+ message.append('0');
+ }
+ // Remove trailing zeros.
+ int end = eIndex - 1;
+ while (end > 0) {
+ char c = d.charAt(end);
+ if (c != '0') {
+ break;
+ }
+ --end;
+ }
+ // Now append the digits to the end. Skip over the decimal point.
+ for (int i = 0; i <= end; ++i) {
+ char c = d.charAt(i);
+ if (c != '.') {
+ message.append(c);
+ }
+ }
+ }
+ else {
+ // Need to convert from scientific notation of the form
+ // n.nnn...EN (N >= 7) to a normal decimal value.
+ try {
+ exp = parseInt(d, eIndex+1, d.length());
+ }
+ // This should never happen.
+ // It's only possible if String.valueOf(double) is broken.
+ catch (Exception e) {
+ message.append(d);
+ return;
+ }
+ final int integerEnd = exp + 2;
+ for (int i = 0; i < eIndex; ++i) {
+ char c = d.charAt(i);
+ if (c != '.') {
+ if (i == integerEnd) {
+ message.append('.');
+ }
+ message.append(c);
+ }
+ }
+ // Append trailing zeroes if necessary.
+ for (int i = integerEnd - eIndex; i > 0; --i) {
+ message.append('0');
+ }
+ }
+ }
+
+ protected double parseSecond(String buffer, int start, int end)
+ throws NumberFormatException {
+ int dot = -1;
+ for (int i = start; i < end; i++) {
+ char ch = buffer.charAt(i);
+ if (ch == '.')
+ dot = i;
+ else if (ch > '9' || ch < '0')
+ throw new NumberFormatException("'" + buffer + "' has wrong format");
+ }
+ if (dot == -1) {
+ if (start+2 != end)
+ throw new NumberFormatException("'" + buffer + "' has wrong format");
+ }
+ else if (start+2 != dot || dot+1 == end) {
+ throw new NumberFormatException("'" + buffer + "' has wrong format");
+ }
+ return Double.parseDouble(buffer.substring(start, end));
+ }
+
+ //
+ //Private help functions
+ //
+
+ private void cloneDate (DateTimeData finalValue, DateTimeData tempDate) {
+ tempDate.year = finalValue.year;
+ tempDate.month = finalValue.month;
+ tempDate.day = finalValue.day;
+ tempDate.hour = finalValue.hour;
+ tempDate.minute = finalValue.minute;
+ tempDate.second = finalValue.second;
+ tempDate.utc = finalValue.utc;
+ tempDate.timezoneHr = finalValue.timezoneHr;
+ tempDate.timezoneMin = finalValue.timezoneMin;
+ }
+
+ /**
+ * Represents date time data
+ */
+ static final class DateTimeData implements XSDateTime {
+ int year, month, day, hour, minute, utc;
+ double second;
+ int timezoneHr, timezoneMin;
+ private String originalValue;
+ boolean normalized = true;
+
+ int unNormYear;
+ int unNormMonth;
+ int unNormDay;
+ int unNormHour;
+ int unNormMinute;
+ double unNormSecond;
+
+ // used for comparisons - to decide the 'interesting' portions of
+ // a date/time based data type.
+ int position;
+ // 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(String originalValue, AbstractDateTimeDV type) {
+ this.originalValue = originalValue;
+ this.type = type;
+ }
+ public DateTimeData(int year, int month, int day, int hour, int minute,
+ double second, int utc, String originalValue, boolean normalized, AbstractDateTimeDV type) {
+ this.year = year;
+ this.month = month;
+ this.day = day;
+ this.hour = hour;
+ this.minute = minute;
+ this.second = second;
+ this.utc = utc;
+ this.type = type;
+ this.originalValue = originalValue;
+ }
+ public boolean equals(Object obj) {
+ if (!(obj instanceof DateTimeData))
+ return false;
+ return type.compareDates(this, (DateTimeData)obj, true)==0;
+ }
+ public synchronized String toString() {
+ if (canonical == null) {
+ canonical = type.dateToString(this);
+ }
+ return canonical;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getYear()
+ */
+ public int getYears() {
+ if(type instanceof DurationDV)
+ return 0;
+ return normalized?year:unNormYear;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getMonth()
+ */
+ public int getMonths() {
+ if(type instanceof DurationDV) {
+ return year*12 + month;
+ }
+ return normalized?month:unNormMonth;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getDay()
+ */
+ public int getDays() {
+ if(type instanceof DurationDV)
+ return 0;
+ return normalized?day:unNormDay;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getHour()
+ */
+ public int getHours() {
+ if(type instanceof DurationDV)
+ return 0;
+ return normalized?hour:unNormHour;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getMinutes()
+ */
+ public int getMinutes() {
+ if(type instanceof DurationDV)
+ return 0;
+ return normalized?minute:unNormMinute;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getSeconds()
+ */
+ public double getSeconds() {
+ if(type instanceof DurationDV) {
+ return day*24*60*60 + hour*60*60 + minute*60 + second;
+ }
+ return normalized?second:unNormSecond;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#hasTimeZone()
+ */
+ public boolean hasTimeZone() {
+ return utc != 0;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getTimeZoneHours()
+ */
+ public int getTimeZoneHours() {
+ return timezoneHr;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getTimeZoneMinutes()
+ */
+ public int getTimeZoneMinutes() {
+ return timezoneMin;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getLexicalValue()
+ */
+ public String getLexicalValue() {
+ return originalValue;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#normalize()
+ */
+ public XSDateTime normalize() {
+ if(!normalized) {
+ DateTimeData dt = (DateTimeData)this.clone();
+ dt.normalized = true;
+ return dt;
+ }
+ return this;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#isNormalized()
+ */
+ public boolean isNormalized() {
+ return normalized;
+ }
+
+ public Object clone() {
+ DateTimeData dt = new DateTimeData(this.year, this.month, this.day, this.hour,
+ this.minute, this.second, this.utc, this.originalValue, this.normalized, this.type);
+ dt.canonical = this.canonical;
+ dt.position = position;
+ dt.timezoneHr = this.timezoneHr;
+ dt.timezoneMin = this.timezoneMin;
+ dt.unNormYear = this.unNormYear;
+ dt.unNormMonth = this.unNormMonth;
+ dt.unNormDay = this.unNormDay;
+ dt.unNormHour = this.unNormHour;
+ dt.unNormMinute = this.unNormMinute;
+ dt.unNormSecond = this.unNormSecond;
+ return dt;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getXMLGregorianCalendar()
+ */
+ public XMLGregorianCalendar getXMLGregorianCalendar() {
+ return type.getXMLGregorianCalendar(this);
+ }
+ /* (non-Javadoc)
+ * @see org.apache.xerces.xs.datatypes.XSDateTime#getDuration()
+ */
+ public Duration getDuration() {
+ return type.getDuration(this);
+ }
+ }
+
+ protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData data) {
+ return null;
+ }
+
+ protected Duration getDuration(DateTimeData data) {
+ return null;
+ }
+
+ protected final BigDecimal getFractionalSecondsAsBigDecimal(DateTimeData data) {
+ final StringBuffer buf = new StringBuffer();
+ append3(buf, data.unNormSecond);
+ String value = buf.toString();
+ final int index = value.indexOf('.');
+ if (index == -1) {
+ return null;
+ }
+ value = value.substring(index);
+ final BigDecimal _val = new BigDecimal(value);
+ if (_val.compareTo(BigDecimal.valueOf(0)) == 0) {
+ return null;
+ }
+ return _val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyAtomicDV.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyAtomicDV.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyAtomicDV.java
new file mode 100644
index 0000000..84694fa
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyAtomicDV.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.jena.ext.xerces.impl.dv.ValidationContext;
+
+/**
+ * Represent the schema type "anyAtomicType"
+ *
+ * @xerces.experimental
+ *
+ * @author Ankit Pasricha, IBM
+ *
+ * @version $Id: AnyAtomicDV.java 446745 2006-09-15 21:43:58Z mrglavas $
+ */
+@SuppressWarnings("all")
+class AnyAtomicDV extends TypeValidator {
+
+ public short getAllowedFacets() {
+ return 0;
+ }
+
+ public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
+ return content;
+ }
+
+} // class AnyAtomicDV
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnySimpleDV.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnySimpleDV.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnySimpleDV.java
new file mode 100644
index 0000000..5e98ce7
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnySimpleDV.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.jena.ext.xerces.impl.dv.ValidationContext;
+
+/**
+ * Represent the schema type "anySimpleType"
+ *
+ * @xerces.internal
+ *
+ * @author Neeraj Bajaj, Sun Microsystems, inc.
+ * @author Sandy Gao, IBM
+ *
+ * @version $Id: AnySimpleDV.java 446745 2006-09-15 21:43:58Z mrglavas $
+ */
+@SuppressWarnings("all")
+public class AnySimpleDV extends TypeValidator {
+
+ public short getAllowedFacets() {
+ // anySimpleType doesn't allow any facet, not even whiteSpace
+ return 0;
+ }
+
+ public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
+ return content;
+ }
+
+} // class AnySimpleDV
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyURIDV.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyURIDV.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyURIDV.java
new file mode 100644
index 0000000..80701ba
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/AnyURIDV.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.jena.ext.xerces.impl.dv.ValidationContext;
+import org.apache.jena.ext.xerces.util.URI;
+
+/**
+ * Represent the schema type "anyURI"
+ *
+ * @xerces.internal
+ *
+ * @author Neeraj Bajaj, Sun Microsystems, inc.
+ * @author Sandy Gao, IBM
+ *
+ * @version $Id: AnyURIDV.java 699892 2008-09-28 21:08:27Z mrglavas $
+ */
+@SuppressWarnings("all")
+public class AnyURIDV extends TypeValidator {
+
+ private static final URI BASE_URI;
+ static {
+ URI uri = null;
+ try {
+ uri = new URI("abc://def.ghi.jkl");
+ } catch (URI.MalformedURIException ex) {
+ }
+ BASE_URI = uri;
+ }
+
+ public short getAllowedFacets(){
+ return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE );
+ }
+
+ // before we return string we have to make sure it is correct URI as per spec.
+ // for some types (string and derived), they just return the string itself
+ public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
+ // check 3.2.17.c0 must: URI (rfc 2396/2723)
+ try {
+ if( content.length() != 0 ) {
+ // encode special characters using XLink 5.4 algorithm
+ final String encoded = encode(content);
+ // Support for relative URLs
+ // According to Java 1.1: URLs may also be specified with a
+ // String and the URL object that it is related to.
+ new URI(BASE_URI, encoded );
+ }
+ } catch (URI.MalformedURIException ex) {
+ throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "anyURI"});
+ }
+
+ // REVISIT: do we need to return the new URI object?
+ return content;
+ }
+
+ // which ASCII characters need to be escaped
+ private static boolean gNeedEscaping[] = new boolean[128];
+ // the first hex character if a character needs to be escaped
+ private static char gAfterEscaping1[] = new char[128];
+ // the second hex character if a character needs to be escaped
+ private static char gAfterEscaping2[] = new char[128];
+ private static char[] gHexChs = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+ // initialize the above 3 arrays
+ static {
+ for (int i = 0; i <= 0x1f; i++) {
+ gNeedEscaping[i] = true;
+ gAfterEscaping1[i] = gHexChs[i >> 4];
+ gAfterEscaping2[i] = gHexChs[i & 0xf];
+ }
+ gNeedEscaping[0x7f] = true;
+ gAfterEscaping1[0x7f] = '7';
+ gAfterEscaping2[0x7f] = 'F';
+ char[] escChs = {' ', '<', '>', '"', '{', '}',
+ '|', '\\', '^', '~', '`'};
+ int len = escChs.length;
+ char ch;
+ for (int i = 0; i < len; i++) {
+ ch = escChs[i];
+ gNeedEscaping[ch] = true;
+ gAfterEscaping1[ch] = gHexChs[ch >> 4];
+ gAfterEscaping2[ch] = gHexChs[ch & 0xf];
+ }
+ }
+
+ // To encode special characters in anyURI, by using %HH to represent
+ // special ASCII characters: 0x00~0x1F, 0x7F, ' ', '<', '>', etc.
+ // and non-ASCII characters (whose value >= 128).
+ private static String encode(String anyURI){
+ int len = anyURI.length(), ch;
+ StringBuffer buffer = new StringBuffer(len*3);
+
+ // for each character in the anyURI
+ int i = 0;
+ for (; i < len; i++) {
+ ch = anyURI.charAt(i);
+ // if it's not an ASCII character, break here, and use UTF-8 encoding
+ if (ch >= 128)
+ break;
+ if (gNeedEscaping[ch]) {
+ buffer.append('%');
+ buffer.append(gAfterEscaping1[ch]);
+ buffer.append(gAfterEscaping2[ch]);
+ }
+ else {
+ buffer.append((char)ch);
+ }
+ }
+
+ // we saw some non-ascii character
+ if (i < len) {
+ // get UTF-8 bytes for the remaining sub-string
+ byte[] bytes = null;
+ byte b;
+ try {
+ bytes = anyURI.substring(i).getBytes("UTF-8");
+ } catch (java.io.UnsupportedEncodingException e) {
+ // should never happen
+ return anyURI;
+ }
+ len = bytes.length;
+
+ // for each byte
+ for (i = 0; i < len; i++) {
+ b = bytes[i];
+ // for non-ascii character: make it positive, then escape
+ if (b < 0) {
+ ch = b + 256;
+ buffer.append('%');
+ buffer.append(gHexChs[ch >> 4]);
+ buffer.append(gHexChs[ch & 0xf]);
+ }
+ else if (gNeedEscaping[b]) {
+ buffer.append('%');
+ buffer.append(gAfterEscaping1[b]);
+ buffer.append(gAfterEscaping2[b]);
+ }
+ else {
+ buffer.append((char)b);
+ }
+ }
+ }
+
+ // If encoding happened, create a new string;
+ // otherwise, return the orginal one.
+ if (buffer.length() != len) {
+ return buffer.toString();
+ }
+ else {
+ return anyURI;
+ }
+ }
+
+} // class AnyURIDV
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/Base64BinaryDV.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/Base64BinaryDV.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/Base64BinaryDV.java
new file mode 100644
index 0000000..d4417aa
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/Base64BinaryDV.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.jena.ext.xerces.impl.dv.ValidationContext;
+import org.apache.jena.ext.xerces.impl.dv.util.Base64;
+import org.apache.jena.ext.xerces.impl.dv.util.ByteListImpl;
+
+/**
+ * Represent the schema type "base64Binary"
+ *
+ * @xerces.internal
+ *
+ * @author Neeraj Bajaj, Sun Microsystems, inc.
+ * @author Sandy Gao, IBM
+ *
+ * @version $Id: Base64BinaryDV.java 446745 2006-09-15 21:43:58Z mrglavas $
+ */
+@SuppressWarnings("all")
+public class Base64BinaryDV extends TypeValidator {
+
+ public short getAllowedFacets(){
+ return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE );
+ }
+
+ public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
+ byte[] decoded = Base64.decode(content);
+ if (decoded == null)
+ throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "base64Binary"});
+
+ return new XBase64(decoded);
+ }
+
+ // length of a binary type is the number of bytes
+ public int getDataLength(Object value) {
+ return ((XBase64)value).getLength();
+ }
+
+ /**
+ * represent base64 data
+ */
+ private static final class XBase64 extends ByteListImpl {
+
+ public XBase64(byte[] data) {
+ super(data);
+ }
+ public synchronized String toString() {
+ if (canonical == null) {
+ canonical = Base64.encode(data);
+ }
+ return canonical;
+ }
+
+ 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;
+ }
+
+ public int hashCode() {
+ int hash = 0;
+ for (int i = 0; i < data.length; ++i) {
+ hash = hash * 37 + ((data[i]) & 0xff);
+ }
+ return hash;
+ }
+ }
+} // class Base64BinaryDV
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseDVFactory.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseDVFactory.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseDVFactory.java
new file mode 100644
index 0000000..896bcc0
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseDVFactory.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.SchemaDVFactory;
+import org.apache.jena.ext.xerces.impl.dv.XSFacets;
+import org.apache.jena.ext.xerces.impl.dv.XSSimpleType;
+import org.apache.jena.ext.xerces.util.SymbolHash;
+import org.apache.jena.ext.xerces.xs.XSConstants;
+import org.apache.jena.ext.xerces.xs.XSObjectList;
+
+/**
+ * the factory to create/return built-in schema DVs and create user-defined DVs
+ *
+ * @xerces.internal
+ *
+ * @author Neeraj Bajaj, Sun Microsystems, inc.
+ * @author Sandy Gao, IBM
+ *
+ * @version $Id: BaseDVFactory.java 699892 2008-09-28 21:08:27Z mrglavas $
+ */
+@SuppressWarnings("all")
+public class BaseDVFactory extends SchemaDVFactory {
+
+ static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
+
+ // there are 27 types. 53 is the closest prime number to 27*2=54.
+ static SymbolHash fBaseTypes = new SymbolHash(53);
+ static {
+ createBuiltInTypes(fBaseTypes);
+ }
+
+ /**
+ * Get a built-in simple type of the given name
+ * REVISIT: its still not decided within the Schema WG how to define the
+ * ur-types and if all simple types should be derived from a
+ * complex type, so as of now we ignore the fact that anySimpleType
+ * is derived from anyType, and pass 'null' as the base of
+ * anySimpleType. It needs to be changed as per the decision taken.
+ *
+ * @param name the name of the datatype
+ * @return the datatype validator of the given name
+ */
+ public XSSimpleType getBuiltInType(String name) {
+ return (XSSimpleType)fBaseTypes.get(name);
+ }
+
+ /**
+ * get all built-in simple types, which are stored in a hashtable keyed by
+ * the name
+ *
+ * @return a hashtable which contains all built-in simple types
+ */
+ public SymbolHash getBuiltInTypes() {
+ return fBaseTypes.makeClone();
+ }
+
+ /**
+ * Create a new simple type which is derived by restriction from another
+ * simple type.
+ *
+ * @param name name of the new type, could be null
+ * @param targetNamespace target namespace of the new type, could be null
+ * @param finalSet value of "final"
+ * @param base base type of the new type
+ * @param annotations set of annotations
+ * @return the newly created simple type
+ */
+ public XSSimpleType createTypeRestriction(String name, String targetNamespace,
+ short finalSet, XSSimpleType base, XSObjectList annotations) {
+ return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations);
+ }
+
+ /**
+ * Create a new simple type which is derived by list from another simple
+ * type.
+ *
+ * @param name name of the new type, could be null
+ * @param targetNamespace target namespace of the new type, could be null
+ * @param finalSet value of "final"
+ * @param itemType item type of the list type
+ * @param annotations set of annotations
+ * @return the newly created simple type
+ */
+ public XSSimpleType createTypeList(String name, String targetNamespace,
+ short finalSet, XSSimpleType itemType,
+ XSObjectList annotations) {
+ return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations);
+ }
+
+ /**
+ * Create a new simple type which is derived by union from a list of other
+ * simple types.
+ *
+ * @param name name of the new type, could be null
+ * @param targetNamespace target namespace of the new type, could be null
+ * @param finalSet value of "final"
+ * @param memberTypes member types of the union type
+ * @param annotations set of annotations
+ * @return the newly created simple type
+ */
+ public XSSimpleType createTypeUnion(String name, String targetNamespace,
+ short finalSet, XSSimpleType[] memberTypes,
+ XSObjectList annotations) {
+ int typeNum = memberTypes.length;
+ XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
+ System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);
+
+ return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations);
+ }
+
+ // create all built-in types
+ static void createBuiltInTypes(SymbolHash types) {
+ // base schema simple type names
+ final String ANYSIMPLETYPE = "anySimpleType";
+ final String ANYURI = "anyURI";
+ final String BASE64BINARY = "base64Binary";
+ final String BOOLEAN = "boolean";
+ final String BYTE = "byte";
+ final String DATE = "date";
+ final String DATETIME = "dateTime";
+ final String DAY = "gDay";
+ final String DECIMAL = "decimal";
+ final String INT = "int";
+ final String INTEGER = "integer";
+ final String LONG = "long";
+ final String NEGATIVEINTEGER = "negativeInteger";
+ final String MONTH = "gMonth";
+ final String MONTHDAY = "gMonthDay";
+ final String NONNEGATIVEINTEGER= "nonNegativeInteger";
+ final String NONPOSITIVEINTEGER= "nonPositiveInteger";
+ final String POSITIVEINTEGER = "positiveInteger";
+ final String SHORT = "short";
+ final String STRING = "string";
+ final String TIME = "time";
+ final String UNSIGNEDBYTE = "unsignedByte";
+ final String UNSIGNEDINT = "unsignedInt";
+ final String UNSIGNEDLONG = "unsignedLong";
+ final String UNSIGNEDSHORT = "unsignedShort";
+ final String YEAR = "gYear";
+ final String YEARMONTH = "gYearMonth";
+
+ final XSFacets facets = new XSFacets();
+
+ XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
+ types.put(ANYSIMPLETYPE, anySimpleType);
+ XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(anySimpleType, STRING, XSSimpleTypeDecl.DV_STRING, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.STRING_DT);
+ types.put(STRING, stringDV);
+ types.put(BOOLEAN, new XSSimpleTypeDecl(anySimpleType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN, XSSimpleType.ORDERED_FALSE, false, true, false, true, XSConstants.BOOLEAN_DT));
+ XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(anySimpleType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.DECIMAL_DT);
+ types.put(DECIMAL, decimalDV);
+
+ types.put(ANYURI, new XSSimpleTypeDecl(anySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ANYURI_DT));
+ types.put(BASE64BINARY, new XSSimpleTypeDecl(anySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.BASE64BINARY_DT));
+ types.put(DATETIME, new XSSimpleTypeDecl(anySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATETIME_DT));
+ types.put(TIME, new XSSimpleTypeDecl(anySimpleType, TIME, XSSimpleTypeDecl.DV_TIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.TIME_DT));
+ types.put(DATE, new XSSimpleTypeDecl(anySimpleType, DATE, XSSimpleTypeDecl.DV_DATE, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATE_DT));
+ types.put(YEARMONTH, new XSSimpleTypeDecl(anySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEARMONTH_DT));
+ types.put(YEAR, new XSSimpleTypeDecl(anySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEAR_DT));
+ types.put(MONTHDAY, new XSSimpleTypeDecl(anySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTHDAY_DT));
+ types.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY, XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GDAY_DT));
+ types.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTH_DT));
+
+ XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.INTEGER_DT);
+ types.put(INTEGER, integerDV);
+
+ facets.maxInclusive = "0";
+ XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONPOSITIVEINTEGER_DT);
+ nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
+ types.put(NONPOSITIVEINTEGER, nonPositiveDV);
+
+ facets.maxInclusive = "-1";
+ XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(nonPositiveDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NEGATIVEINTEGER_DT);
+ negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
+ types.put(NEGATIVEINTEGER, negativeDV);
+
+ facets.maxInclusive = "9223372036854775807";
+ facets.minInclusive = "-9223372036854775808";
+ XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LONG_DT);
+ longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ types.put(LONG, longDV);
+
+
+ facets.maxInclusive = "2147483647";
+ facets.minInclusive = "-2147483648";
+ XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.INT_DT);
+ intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ types.put(INT, intDV);
+
+ facets.maxInclusive = "32767";
+ facets.minInclusive = "-32768";
+ XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.SHORT_DT);
+ shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ types.put(SHORT, shortDV);
+
+ facets.maxInclusive = "127";
+ facets.minInclusive = "-128";
+ XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.BYTE_DT);
+ byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ types.put(BYTE, byteDV);
+
+ facets.minInclusive = "0" ;
+ XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONNEGATIVEINTEGER_DT);
+ nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
+ types.put(NONNEGATIVEINTEGER, nonNegativeDV);
+
+ facets.maxInclusive = "18446744073709551615" ;
+ XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDLONG_DT);
+ unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ types.put(UNSIGNEDLONG, unsignedLongDV);
+
+ facets.maxInclusive = "4294967295" ;
+ XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDINT_DT);
+ unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ types.put(UNSIGNEDINT, unsignedIntDV);
+
+ facets.maxInclusive = "65535" ;
+ XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDSHORT_DT);
+ unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ types.put(UNSIGNEDSHORT, unsignedShortDV);
+
+ facets.maxInclusive = "255" ;
+ XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDBYTE_DT);
+ unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ types.put(UNSIGNEDBYTE, unsignedByteDV);
+
+ facets.minInclusive = "1" ;
+ XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.POSITIVEINTEGER_DT);
+ positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
+ types.put(POSITIVEINTEGER, positiveIntegerDV);
+ }//createBuiltInTypes(SymbolHash)
+
+}//BaseDVFactory
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseSchemaDVFactory.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseSchemaDVFactory.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseSchemaDVFactory.java
new file mode 100644
index 0000000..9eca62f
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BaseSchemaDVFactory.java
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.SchemaDVFactory;
+import org.apache.jena.ext.xerces.impl.dv.XSFacets;
+import org.apache.jena.ext.xerces.impl.dv.XSSimpleType;
+import org.apache.jena.ext.xerces.impl.xs.XSDeclarationPool;
+import org.apache.jena.ext.xerces.util.SymbolHash;
+import org.apache.jena.ext.xerces.xs.XSConstants;
+import org.apache.jena.ext.xerces.xs.XSObjectList;
+
+/**
+ * the base factory to create/return built-in schema DVs and create user-defined DVs
+ *
+ * @xerces.internal
+ *
+ * @author Neeraj Bajaj, Sun Microsystems, inc.
+ * @author Sandy Gao, IBM
+ * @author Khaled Noaman, IBM
+ *
+ * @version $Id: BaseSchemaDVFactory.java 805582 2009-08-18 21:13:20Z sandygao $
+ */
+@SuppressWarnings("all")
+public abstract class BaseSchemaDVFactory extends SchemaDVFactory {
+
+ static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
+
+ protected XSDeclarationPool fDeclPool = null;
+
+ // create common built-in types
+ protected static void createBuiltInTypes(SymbolHash builtInTypes, XSSimpleTypeDecl baseAtomicType) {
+ // all schema simple type names
+ final String ANYSIMPLETYPE = "anySimpleType";
+ final String ANYURI = "anyURI";
+ final String BASE64BINARY = "base64Binary";
+ final String BOOLEAN = "boolean";
+ final String BYTE = "byte";
+ final String DATE = "date";
+ final String DATETIME = "dateTime";
+ final String DAY = "gDay";
+ final String DECIMAL = "decimal";
+ final String DOUBLE = "double";
+ final String DURATION = "duration";
+ final String ENTITY = "ENTITY";
+ final String ENTITIES = "ENTITIES";
+ final String FLOAT = "float";
+ final String HEXBINARY = "hexBinary";
+ final String ID = "ID";
+ final String IDREF = "IDREF";
+ final String IDREFS = "IDREFS";
+ final String INT = "int";
+ final String INTEGER = "integer";
+ final String LONG = "long";
+ final String NAME = "Name";
+ final String NEGATIVEINTEGER = "negativeInteger";
+ final String MONTH = "gMonth";
+ final String MONTHDAY = "gMonthDay";
+ final String NCNAME = "NCName";
+ final String NMTOKEN = "NMTOKEN";
+ final String NMTOKENS = "NMTOKENS";
+ final String LANGUAGE = "language";
+ final String NONNEGATIVEINTEGER= "nonNegativeInteger";
+ final String NONPOSITIVEINTEGER= "nonPositiveInteger";
+ final String NORMALIZEDSTRING = "normalizedString";
+ final String NOTATION = "NOTATION";
+ final String POSITIVEINTEGER = "positiveInteger";
+ final String QNAME = "QName";
+ final String SHORT = "short";
+ final String STRING = "string";
+ final String TIME = "time";
+ final String TOKEN = "token";
+ final String UNSIGNEDBYTE = "unsignedByte";
+ final String UNSIGNEDINT = "unsignedInt";
+ final String UNSIGNEDLONG = "unsignedLong";
+ final String UNSIGNEDSHORT = "unsignedShort";
+ final String YEAR = "gYear";
+ final String YEARMONTH = "gYearMonth";
+
+ final XSFacets facets = new XSFacets();
+
+ builtInTypes.put(ANYSIMPLETYPE, XSSimpleTypeDecl.fAnySimpleType);
+
+ XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(baseAtomicType, STRING, XSSimpleTypeDecl.DV_STRING, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.STRING_DT);
+ builtInTypes.put(STRING, stringDV);
+ builtInTypes.put(BOOLEAN, new XSSimpleTypeDecl(baseAtomicType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN, XSSimpleType.ORDERED_FALSE, false, true, false, true, XSConstants.BOOLEAN_DT));
+ XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(baseAtomicType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.DECIMAL_DT);
+ builtInTypes.put(DECIMAL, decimalDV);
+
+ builtInTypes.put(ANYURI, new XSSimpleTypeDecl(baseAtomicType, ANYURI, XSSimpleTypeDecl.DV_ANYURI, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ANYURI_DT));
+ builtInTypes.put(BASE64BINARY, new XSSimpleTypeDecl(baseAtomicType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.BASE64BINARY_DT));
+
+ XSSimpleTypeDecl durationDV = new XSSimpleTypeDecl(baseAtomicType, DURATION, XSSimpleTypeDecl.DV_DURATION, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DURATION_DT);
+ builtInTypes.put(DURATION, durationDV);
+
+ builtInTypes.put(DATETIME, new XSSimpleTypeDecl(baseAtomicType, DATETIME, XSSimpleTypeDecl.DV_DATETIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATETIME_DT));
+ builtInTypes.put(TIME, new XSSimpleTypeDecl(baseAtomicType, TIME, XSSimpleTypeDecl.DV_TIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.TIME_DT));
+ builtInTypes.put(DATE, new XSSimpleTypeDecl(baseAtomicType, DATE, XSSimpleTypeDecl.DV_DATE, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATE_DT));
+ builtInTypes.put(YEARMONTH, new XSSimpleTypeDecl(baseAtomicType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEARMONTH_DT));
+ builtInTypes.put(YEAR, new XSSimpleTypeDecl(baseAtomicType, YEAR, XSSimpleTypeDecl.DV_GYEAR, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEAR_DT));
+ builtInTypes.put(MONTHDAY, new XSSimpleTypeDecl(baseAtomicType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTHDAY_DT));
+ builtInTypes.put(DAY, new XSSimpleTypeDecl(baseAtomicType, DAY, XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GDAY_DT));
+ builtInTypes.put(MONTH, new XSSimpleTypeDecl(baseAtomicType, MONTH, XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTH_DT));
+
+ XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.INTEGER_DT);
+ builtInTypes.put(INTEGER, integerDV);
+
+ facets.maxInclusive = "0";
+ XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONPOSITIVEINTEGER_DT);
+ nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
+ builtInTypes.put(NONPOSITIVEINTEGER, nonPositiveDV);
+
+ facets.maxInclusive = "-1";
+ XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(nonPositiveDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NEGATIVEINTEGER_DT);
+ negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
+ builtInTypes.put(NEGATIVEINTEGER, negativeDV);
+
+ facets.maxInclusive = "9223372036854775807";
+ facets.minInclusive = "-9223372036854775808";
+ XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LONG_DT);
+ longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ builtInTypes.put(LONG, longDV);
+
+ facets.maxInclusive = "2147483647";
+ facets.minInclusive = "-2147483648";
+ XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.INT_DT);
+ intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ builtInTypes.put(INT, intDV);
+
+ facets.maxInclusive = "32767";
+ facets.minInclusive = "-32768";
+ XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.SHORT_DT);
+ shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ builtInTypes.put(SHORT, shortDV);
+
+ facets.maxInclusive = "127";
+ facets.minInclusive = "-128";
+ XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.BYTE_DT);
+ byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ builtInTypes.put(BYTE, byteDV);
+
+ facets.minInclusive = "0" ;
+ XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONNEGATIVEINTEGER_DT);
+ nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
+ builtInTypes.put(NONNEGATIVEINTEGER, nonNegativeDV);
+
+ facets.maxInclusive = "18446744073709551615" ;
+ XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDLONG_DT);
+ unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ builtInTypes.put(UNSIGNEDLONG, unsignedLongDV);
+
+ facets.maxInclusive = "4294967295" ;
+ XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDINT_DT);
+ unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ builtInTypes.put(UNSIGNEDINT, unsignedIntDV);
+
+ facets.maxInclusive = "65535" ;
+ XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDSHORT_DT);
+ unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ builtInTypes.put(UNSIGNEDSHORT, unsignedShortDV);
+
+ facets.maxInclusive = "255" ;
+ XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDBYTE_DT);
+ unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ builtInTypes.put(UNSIGNEDBYTE, unsignedByteDV);
+
+ facets.minInclusive = "1" ;
+ XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.POSITIVEINTEGER_DT);
+ positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
+ builtInTypes.put(POSITIVEINTEGER, positiveIntegerDV);
+
+ builtInTypes.put(FLOAT, new XSSimpleTypeDecl(baseAtomicType, FLOAT, XSSimpleTypeDecl.DV_FLOAT, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.FLOAT_DT));
+ builtInTypes.put(DOUBLE, new XSSimpleTypeDecl(baseAtomicType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.DOUBLE_DT));
+ builtInTypes.put(HEXBINARY, new XSSimpleTypeDecl(baseAtomicType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.HEXBINARY_DT));
+ builtInTypes.put(NOTATION, new XSSimpleTypeDecl(baseAtomicType, NOTATION, XSSimpleTypeDecl.DV_NOTATION, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.NOTATION_DT));
+
+ facets.whiteSpace = XSSimpleType.WS_REPLACE;
+ XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NORMALIZEDSTRING_DT);
+ normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
+ builtInTypes.put(NORMALIZEDSTRING, normalizedDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.TOKEN_DT);
+ tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
+ builtInTypes.put(TOKEN, tokenDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ facets.pattern = "([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*";
+ XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LANGUAGE_DT);
+ languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0);
+ builtInTypes.put(LANGUAGE, languageDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NAME_DT);
+ nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NAME);
+ builtInTypes.put(NAME, nameDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NCNAME_DT) ;
+ ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NCNAME);
+ builtInTypes.put(NCNAME, ncnameDV);
+
+ builtInTypes.put(QNAME, new XSSimpleTypeDecl(baseAtomicType, QNAME, XSSimpleTypeDecl.DV_QNAME, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.QNAME_DT));
+
+ builtInTypes.put(ID, new XSSimpleTypeDecl(ncnameDV, ID, XSSimpleTypeDecl.DV_ID, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.ID_DT));
+ XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.IDREF_DT);
+ builtInTypes.put(IDREF, idrefDV);
+
+ facets.minLength = 1;
+ XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV, true, null);
+ XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
+ idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
+ builtInTypes.put(IDREFS, idrefsDV);
+
+ XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ENTITY_DT);
+ builtInTypes.put(ENTITY, entityDV);
+
+ facets.minLength = 1;
+ tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, entityDV, true, null);
+ XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0, false, null);
+ entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
+ builtInTypes.put(ENTITIES, entitiesDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NMTOKEN_DT);
+ nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NMTOKEN);
+ builtInTypes.put(NMTOKEN, nmtokenDV);
+
+ facets.minLength = 1;
+ tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV, true, null);
+ XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
+ nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
+ builtInTypes.put(NMTOKENS, nmtokensDV);
+ } //createBuiltInTypes()
+
+ /**
+ * Create a new simple type which is derived by restriction from another
+ * simple type.
+ *
+ * @param name name of the new type, could be null
+ * @param targetNamespace target namespace of the new type, could be null
+ * @param finalSet value of "final"
+ * @param base base type of the new type
+ * @param annotations set of annotations
+ * @return the newly created simple type
+ */
+ public XSSimpleType createTypeRestriction(String name, String targetNamespace,
+ short finalSet, XSSimpleType base, XSObjectList annotations) {
+
+ if (fDeclPool != null) {
+ XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl();
+ return st.setRestrictionValues((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, annotations);
+ }
+ return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations);
+ }
+
+ /**
+ * Create a new simple type which is derived by list from another simple
+ * type.
+ *
+ * @param name name of the new type, could be null
+ * @param targetNamespace target namespace of the new type, could be null
+ * @param finalSet value of "final"
+ * @param itemType item type of the list type
+ * @param annotations set of annotations
+ * @return the newly created simple type
+ */
+ public XSSimpleType createTypeList(String name, String targetNamespace,
+ short finalSet, XSSimpleType itemType,
+ XSObjectList annotations) {
+ if (fDeclPool != null) {
+ XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl();
+ return st.setListValues(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, annotations);
+ }
+ return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations);
+ }
+
+ /**
+ * Create a new simple type which is derived by union from a list of other
+ * simple types.
+ *
+ * @param name name of the new type, could be null
+ * @param targetNamespace target namespace of the new type, could be null
+ * @param finalSet value of "final"
+ * @param memberTypes member types of the union type
+ * @param annotations set of annotations
+ * @return the newly created simple type
+ */
+ public XSSimpleType createTypeUnion(String name, String targetNamespace,
+ short finalSet, XSSimpleType[] memberTypes,
+ XSObjectList annotations) {
+ int typeNum = memberTypes.length;
+ XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
+ System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);
+
+ if (fDeclPool != null) {
+ XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl();
+ return st.setUnionValues(name, targetNamespace, finalSet, mtypes, annotations);
+ }
+ return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations);
+ }
+
+ public void setDeclPool (XSDeclarationPool declPool){
+ fDeclPool = declPool;
+ }
+
+ /** Implementation internal **/
+ public XSSimpleTypeDecl newXSSimpleTypeDecl() {
+ return new XSSimpleTypeDecl();
+ }
+} //BaseSchemaDVFactory
http://git-wip-us.apache.org/repos/asf/jena/blob/c9a7e646/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BooleanDV.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BooleanDV.java b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BooleanDV.java
new file mode 100644
index 0000000..2eb2915
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/ext/xerces/impl/dv/xs/BooleanDV.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.ext.xerces.impl.dv.xs;
+
+import org.apache.jena.ext.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.jena.ext.xerces.impl.dv.ValidationContext;
+
+/**
+ * Represent the schema type "boolean"
+ *
+ * @xerces.internal
+ *
+ * @author Neeraj Bajaj, Sun Microsystems, inc.
+ * @author Sandy Gao, IBM
+ *
+ * @version $Id: BooleanDV.java 469063 2006-10-30 04:44:22Z mrglavas $
+ */
+@SuppressWarnings("all")
+public class BooleanDV extends TypeValidator {
+
+ public short getAllowedFacets() {
+ return (XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_WHITESPACE);
+ }
+
+ public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
+ if ("false".equals(content) || "0".equals(content)) {
+ return Boolean.FALSE;
+ }
+ else if ("true".equals(content) || "1".equals(content)) {
+ return Boolean.TRUE;
+ }
+ throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "boolean"});
+ }
+
+} // class BooleanDV