You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/11/09 18:49:50 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes Base64.java HexBin.java Base64BinaryDV.java BooleanDV.java DateDV.java HexBinaryDV.java ListDV.java NewDVInterfaces.java SchemaDVFactoryImpl.java StringDV.java UnionDV.java XSSimpleTypeDecl.java
sandygao 01/11/09 09:49:49
Modified: java/src/org/apache/xerces/impl/v2/new_datatypes
Base64BinaryDV.java BooleanDV.java DateDV.java
HexBinaryDV.java ListDV.java NewDVInterfaces.java
SchemaDVFactoryImpl.java StringDV.java UnionDV.java
XSSimpleTypeDecl.java
Added: java/src/org/apache/xerces/impl/v2/new_datatypes Base64.java
HexBin.java
Log:
New changes to the implementation: some modifications to the interfaces;
fixed some bugs; added normalization support; created all built-in types, etc.
Revision Changes Path
1.4 +1 -3 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/Base64BinaryDV.java
Index: Base64BinaryDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/Base64BinaryDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Base64BinaryDV.java 2001/11/09 00:30:37 1.3
+++ Base64BinaryDV.java 2001/11/09 17:49:49 1.4
@@ -57,15 +57,13 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import org.apache.xerces.impl.xs.util.Base64;
-
/**
* Represent the schema type "base64Binary"
*
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: Base64BinaryDV.java,v 1.3 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: Base64BinaryDV.java,v 1.4 2001/11/09 17:49:49 sandygao Exp $
*/
public class Base64BinaryDV extends TypeValidator {
1.2 +1 -3 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/BooleanDV.java
Index: BooleanDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/BooleanDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BooleanDV.java 2001/11/09 00:30:37 1.1
+++ BooleanDV.java 2001/11/09 17:49:49 1.2
@@ -1,14 +1,12 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import java.util.Locale;
-
/**
* Represent the schema type "boolean"
*
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: BooleanDV.java,v 1.1 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: BooleanDV.java,v 1.2 2001/11/09 17:49:49 sandygao Exp $
*/
public class BooleanDV extends TypeValidator{
1.2 +1 -4 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/DateDV.java
Index: DateDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/DateDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DateDV.java 2001/11/09 00:30:37 1.1
+++ DateDV.java 2001/11/09 17:49:49 1.2
@@ -58,16 +58,13 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import java.util.Hashtable;
-import org.apache.xerces.impl.XMLErrorReporter;
-
/**
* Validator for <date> datatype (W3C Schema datatypes)
*
* @author Elena Litani
* @Gopal Sharma, SUN Microsystems Inc.
*
- * @version $Id: DateDV.java,v 1.1 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: DateDV.java,v 1.2 2001/11/09 17:49:49 sandygao Exp $
*/
public class DateDV extends DateTimeDV {
1.4 +1 -4 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/HexBinaryDV.java
Index: HexBinaryDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/HexBinaryDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HexBinaryDV.java 2001/11/09 00:30:37 1.3
+++ HexBinaryDV.java 2001/11/09 17:49:49 1.4
@@ -57,16 +57,13 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import org.apache.xerces.impl.xs.util.HexBin;
-import java.io.UnsupportedEncodingException;
-
/**
* Represent the schema type "hexBinary"
*
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: HexBinaryDV.java,v 1.3 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: HexBinaryDV.java,v 1.4 2001/11/09 17:49:49 sandygao Exp $
*/
public class HexBinaryDV extends TypeValidator {
1.2 +5 -1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/ListDV.java
Index: ListDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/ListDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ListDV.java 2001/11/09 00:30:37 1.1
+++ ListDV.java 2001/11/09 17:49:49 1.2
@@ -63,7 +63,7 @@
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: ListDV.java,v 1.1 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: ListDV.java,v 1.2 2001/11/09 17:49:49 sandygao Exp $
*/
public class ListDV extends TypeValidator{
@@ -77,4 +77,8 @@
return content;
}
+ // length of a list type is the number of items in the list
+ public int getDataLength(Object value) {
+ return ((Object[])value).length;
+ }
} // class ListDV
1.2 +11 -1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/NewDVInterfaces.java
Index: NewDVInterfaces.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/NewDVInterfaces.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NewDVInterfaces.java 2001/11/09 00:30:37 1.1
+++ NewDVInterfaces.java 2001/11/09 17:49:49 1.2
@@ -57,6 +57,8 @@
package org.apache.xerces.impl.v2.new_datatypes;
+import java.util.Hashtable;
+
/**
* All the interfaces that need to be implemented by DV implementations,
* and those interfaces/classes that DV implementations depend on.
@@ -67,7 +69,7 @@
*
* @author Sandy Gao, IBM
*
- * @version $Id: NewDVInterfaces.java,v 1.1 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: NewDVInterfaces.java,v 1.2 2001/11/09 17:49:49 sandygao Exp $
*/
/**
@@ -149,6 +151,9 @@
// we need to pass in anyType as the base of anySimpleType
public XSSimpleType getBuiltInType(String name);
+ // get all built-in DVs, which are stored in a hashtable keyed by the name
+ public Hashtable getBuiltInTypes();
+
// create a user-defined DV according to how it's defined:
// <restriction> / <list> / <union>
public XSSimpleType createTypeRestriction(String name, String targetNamespace,
@@ -164,6 +169,8 @@
*/
interface XSFacet {
public String getName();
+ // maybe it's a better idea to always expose strings
+ // so String getValue(); and String[] getValues() for enumeration
public Object getValue();
public boolean isFixed();
}
@@ -240,6 +247,7 @@
public short getFinalSet();
public short getVariety();
+ public short getDefinedFacets();
// the following methods are for PSVI. they are not implemented yet.
//public XSFacet[] getFacets();
@@ -255,6 +263,8 @@
*/
interface XSAtomicSimpleType extends XSSimpleType {
// return the built-in primitive type
+ // is this what we really want? or
+ // public int getPrimitiveKind()?
public XSSimpleType getPrimitiveType();
}
1.2 +162 -106 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/SchemaDVFactoryImpl.java
Index: SchemaDVFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/SchemaDVFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SchemaDVFactoryImpl.java 2001/11/09 00:30:37 1.1
+++ SchemaDVFactoryImpl.java 2001/11/09 17:49:49 1.2
@@ -65,7 +65,7 @@
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: SchemaDVFactoryImpl.java,v 1.1 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: SchemaDVFactoryImpl.java,v 1.2 2001/11/09 17:49:49 sandygao Exp $
*/
public class SchemaDVFactoryImpl implements SchemaDVFactory {
@@ -81,6 +81,12 @@
return (XSSimpleType)fBuiltInTypes.get(name);
}
+ // get all built-in DVs, which are stored in a hashtable keyed by the name
+ public Hashtable getBuiltInTypes() {
+ prepareBuiltInTypes();
+ return (Hashtable)fBuiltInTypes.clone();
+ }
+
// create a user-defined DV according to how it's defined: <restriction>
public XSSimpleType createTypeRestriction(String name, String targetNamespace,
short finalSet, XSSimpleType base) {
@@ -104,9 +110,14 @@
return new XSSimpleTypeDecl(fAnySimpleType, name, targetNamespace, finalSet, mtypes);
}
+ // make sure the built-in types are created
+ // the types are supposed to be reused for all factory objects,
+ // so we synchorinize on the class object.
void prepareBuiltInTypes() {
if (fBuiltInTypes == null) {
synchronized (this.getClass()) {
+ // check again, in case I'm waiting for another thread to create
+ // the types.
if (fBuiltInTypes == null) {
createBuiltInTypes();
}
@@ -147,6 +158,7 @@
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";
@@ -167,7 +179,7 @@
final XSFacets facets = new XSFacets();
fBuiltInTypes = new Hashtable();
-
+ //REVISIT: passing "anyType" here.
fAnySimpleType = new XSSimpleTypeDecl(null, ANYSIMPLETYPE, XSSimpleTypeDecl.DV_ANYSIMPLETYPE);
fBuiltInTypes.put(ANYSIMPLETYPE, fAnySimpleType);
XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(fAnySimpleType, STRING, XSSimpleTypeDecl.DV_STRING);
@@ -175,119 +187,163 @@
fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, STRING, XSSimpleTypeDecl.DV_BOOLEAN));
XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(fAnySimpleType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL);
fBuiltInTypes.put(DECIMAL, decimalDV);
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, TIME, XSSimpleTypeDecl.DV_TIME));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, DATE, XSSimpleTypeDecl.DV_DATE));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY));
- fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(fAnySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH));
+ fBuiltInTypes.put(ANYURI, new XSSimpleTypeDecl(fAnySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI));
+ fBuiltInTypes.put(BASE64BINARY, new XSSimpleTypeDecl(fAnySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY));
+ fBuiltInTypes.put(DURATION, new XSSimpleTypeDecl(fAnySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION));
+ fBuiltInTypes.put(DATETIME, new XSSimpleTypeDecl(fAnySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME));
+ fBuiltInTypes.put(TIME, new XSSimpleTypeDecl(fAnySimpleType, TIME, XSSimpleTypeDecl.DV_TIME));
+ fBuiltInTypes.put(DATE, new XSSimpleTypeDecl(fAnySimpleType, DATE, XSSimpleTypeDecl.DV_DATE));
+ fBuiltInTypes.put(YEARMONTH, new XSSimpleTypeDecl(fAnySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH));
+ fBuiltInTypes.put(YEAR, new XSSimpleTypeDecl(fAnySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR));
+ fBuiltInTypes.put(MONTHDAY, new XSSimpleTypeDecl(fAnySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY));
+ fBuiltInTypes.put(DAY, new XSSimpleTypeDecl(fAnySimpleType, DAY, XSSimpleTypeDecl.DV_GDAY));
+ fBuiltInTypes.put(MONTH, new XSSimpleTypeDecl(fAnySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH));
+
facets.fractionDigits = 0;
XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, URI_SCHEMAFORSCHEMA, (short)0);
- integerDV.applyFacets(facets, XSSimpleType.FACET_FRACTIONDIGITS, (short)0);
+ integerDV.applyFacets1(facets , XSSimpleType.FACET_FRACTIONDIGITS, (short)0);
fBuiltInTypes.put(INTEGER, integerDV);
+
facets.maxInclusive = "0";
XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0);
- nonPositiveDV.applyFacets(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
+ nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
fBuiltInTypes.put(NONPOSITIVEINTEGER, nonPositiveDV);
+
facets.maxInclusive = "-1";
XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(integerDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0);
- negativeDV.applyFacets(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
+ negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
fBuiltInTypes.put(NEGATIVEINTEGER, negativeDV);
- /*facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "9223372036854775807");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-9223372036854775808");
- XSSimpleTypeDecl longDV = new DecimalXSSimpleTypeDecl(integerDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.LONG, longDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "2147483647");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-2147483648");
- XSSimpleTypeDecl intDV = new DecimalXSSimpleTypeDecl(longDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.INT, intDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "32767");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-32768");
- XSSimpleTypeDecl shortDV = new DecimalXSSimpleTypeDecl(intDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.SHORT, shortDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "127");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-128");
- addGlobalTypeDecl(SchemaSymbols.BYTE, new DecimalXSSimpleTypeDecl(shortDV, facets, false, null));
- facets.clear();
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "0" );
- XSSimpleTypeDecl nonNegativeDV = new DecimalXSSimpleTypeDecl(integerDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.NONNEGATIVEINTEGER, nonNegativeDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "18446744073709551615" );
- XSSimpleTypeDecl unsignedLongDV = new DecimalXSSimpleTypeDecl(nonNegativeDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.UNSIGNEDLONG, unsignedLongDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "4294967295" );
- XSSimpleTypeDecl unsignedIntDV = new DecimalXSSimpleTypeDecl(unsignedLongDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.UNSIGNEDINT, unsignedIntDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "65535" );
- XSSimpleTypeDecl unsignedShortDV = new DecimalXSSimpleTypeDecl(unsignedIntDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.UNSIGNEDSHORT, unsignedShortDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "255" );
- addGlobalTypeDecl(SchemaSymbols.UNSIGNEDBYTE, new DecimalXSSimpleTypeDecl(unsignedShortDV, facets, false, null));
- facets.clear();
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "1" );
- addGlobalTypeDecl(SchemaSymbols.POSITIVEINTEGER, new DecimalXSSimpleTypeDecl(nonNegativeDV, facets, false, null));
-
- if (!fullSet)
- return;
-
- addGlobalTypeDecl(SchemaSymbols.FLOAT, new FloatXSSimpleTypeDecl(fAnySimpleType, null, false, null));
- addGlobalTypeDecl(SchemaSymbols.DOUBLE, new DoubleXSSimpleTypeDecl(fAnySimpleType, null, false, null));
- addGlobalTypeDecl(SchemaSymbols.HEXBINARY, new HexBinaryXSSimpleTypeDecl(fAnySimpleType, null, false, null));
- addGlobalTypeDecl(SchemaSymbols.NOTATION, new NOTATIONXSSimpleTypeDecl(fAnySimpleType, null, false, null));
-
- facets.clear();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.REPLACE);
- XSSimpleTypeDecl normalizedDV = new StringXSSimpleTypeDecl(stringDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.NORMALIZEDSTRING, normalizedDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.COLLAPSE);
- XSSimpleTypeDecl tokenDV = new StringXSSimpleTypeDecl(normalizedDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.TOKEN, tokenDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.COLLAPSE);
- facets.put(SchemaSymbols.ELT_PATTERN , "([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*");
- addGlobalTypeDecl(SchemaSymbols.LANGUAGE, new StringXSSimpleTypeDecl(tokenDV, facets, false, null));
- facets.clear();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.COLLAPSE);
- facets.put(AbstractStringValidator.FACET_SPECIAL_TOKEN, AbstractStringValidator.SPECIAL_TOKEN_NAME);
- XSSimpleTypeDecl nameDV = new StringXSSimpleTypeDecl(tokenDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.NAME, nameDV);
- facets.clear();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.COLLAPSE);
- facets.put(AbstractStringValidator.FACET_SPECIAL_TOKEN, AbstractStringValidator.SPECIAL_TOKEN_NCNAME);
- XSSimpleTypeDecl ncnameDV = new StringXSSimpleTypeDecl(nameDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.NCNAME, ncnameDV);
- XSSimpleTypeDecl qnameDV = new QNameXSSimpleTypeDecl(fAnySimpleType, null, false, null);
- ((QNameXSSimpleTypeDecl)qnameDV).setNCNameValidator(ncnameDV);
- addGlobalTypeDecl(SchemaSymbols.QNAME, qnameDV);
- addGlobalTypeDecl(SchemaSymbols.ID, new IDXSSimpleTypeDecl(ncnameDV, null, false, null));
- XSSimpleTypeDecl idrefDV = new IDREFXSSimpleTypeDecl(ncnameDV, null, false, null);
- addGlobalTypeDecl(SchemaSymbols.IDREF, idrefDV);
- addGlobalTypeDecl(SchemaSymbols.IDREFS, new ListXSSimpleTypeDecl(idrefDV, null, true, null));
- XSSimpleTypeDecl entityDV = new EntityXSSimpleTypeDecl(ncnameDV, null, false, null);
- addGlobalTypeDecl(SchemaSymbols.ENTITY, entityDV);
- addGlobalTypeDecl(SchemaSymbols.ENTITIES, new ListXSSimpleTypeDecl(entityDV, null, true, null));
-
- facets.clear();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.COLLAPSE);
- facets.put(AbstractStringValidator.FACET_SPECIAL_TOKEN, AbstractStringValidator.SPECIAL_TOKEN_NMTOKEN);
- XSSimpleTypeDecl nmtokenDV = new StringXSSimpleTypeDecl(tokenDV, facets, false, null);
- addGlobalTypeDecl(SchemaSymbols.NMTOKEN, nmtokenDV);
- addGlobalTypeDecl(SchemaSymbols.NMTOKENS, new ListXSSimpleTypeDecl(nmtokenDV, null, true, null));
-*/
- }//getBuiltInSimpleType()
+ facets.maxInclusive = "9223372036854775807";
+ facets.minInclusive = "-9223372036854775808";
+ XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0);
+ longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ fBuiltInTypes.put(LONG, longDV);
+
+
+ facets.maxInclusive = "2147483647";
+ facets.minInclusive = "-2147483648";
+ XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0);
+ intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ fBuiltInTypes.put(INT, intDV);
+
+ facets.maxInclusive = "32767";
+ facets.minInclusive = "-32768";
+ XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0);
+ shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ fBuiltInTypes.put(SHORT, shortDV);
+
+ facets.maxInclusive = "127";
+ facets.minInclusive = "-128";
+ XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0);
+ byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
+ fBuiltInTypes.put(BYTE, byteDV);
+
+ facets.minInclusive = "0" ;
+ XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0);
+ nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
+ fBuiltInTypes.put(NONNEGATIVEINTEGER, nonNegativeDV);
+
+ facets.maxInclusive = "18446744073709551615" ;
+ XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0);
+ unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ fBuiltInTypes.put(UNSIGNEDLONG, unsignedLongDV);
+
+ facets.maxInclusive = "4294967295" ;
+ XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0);
+ unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ fBuiltInTypes.put(UNSIGNEDINT, unsignedIntDV);
+
+ facets.maxInclusive = "65535" ;
+ XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0);
+ unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ fBuiltInTypes.put(UNSIGNEDSHORT, unsignedShortDV);
+
+ facets.maxInclusive = "255" ;
+ XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0);
+ unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
+ fBuiltInTypes.put(UNSIGNEDBYTE, unsignedByteDV);
+
+ facets.minInclusive = "1" ;
+ XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0);
+ positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
+ fBuiltInTypes.put(POSITIVEINTEGER, positiveIntegerDV);
+
+
+ fBuiltInTypes.put(FLOAT, new XSSimpleTypeDecl(fAnySimpleType, FLOAT, XSSimpleTypeDecl.DV_FLOAT));
+ fBuiltInTypes.put(DOUBLE, new XSSimpleTypeDecl(fAnySimpleType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE));
+ fBuiltInTypes.put(HEXBINARY, new XSSimpleTypeDecl(fAnySimpleType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY));
+ fBuiltInTypes.put(NOTATION, new XSSimpleTypeDecl(fAnySimpleType, NOTATION, XSSimpleTypeDecl.DV_NOTATION));
+
+
+ facets.whiteSpace = XSSimpleType.WS_REPLACE;
+ XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0);
+ normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
+ fBuiltInTypes.put(NORMALIZEDSTRING, normalizedDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0);
+ tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
+ fBuiltInTypes.put(TOKEN, tokenDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ facets.patterh = "([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*";
+ XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0);
+ languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0);
+ fBuiltInTypes.put(LANGUAGE, languageDV);
+
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0);
+ nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_TOKEN_NAME);
+ fBuiltInTypes.put(NAME, nameDV);
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0) ;
+ ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_TOKEN_NCNAME);
+ fBuiltInTypes.put(NCNAME, ncnameDV);
+
+ fBuiltInTypes.put(QNAME, new XSSimpleTypeDecl(fAnySimpleType, QNAME, XSSimpleTypeDecl.DV_QNAME));
+
+ fBuiltInTypes.put(ID, new XSSimpleTypeDecl(ncnameDV, ID , XSSimpleTypeDecl.DV_ID ));
+ XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF);
+ fBuiltInTypes.put(IDREF, idrefDV);
+
+ facets.minLength = 1;
+ XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(fAnySimpleType, null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV);
+ XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0);
+ idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
+ fBuiltInTypes.put(IDREFS, idrefsDV);
+
+ XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY);
+ fBuiltInTypes.put(ENTITY, entityDV);
+
+ facets.minLength = 1;
+ tempDV = new XSSimpleTypeDecl(fAnySimpleType, null, URI_SCHEMAFORSCHEMA, (short)0, entityDV);
+ XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0);
+ entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
+ fBuiltInTypes.put(ENTITIES, entitiesDV);
+
+
+ facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
+ XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0);
+ nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_TOKEN_NMTOKEN);
+ fBuiltInTypes.put(NMTOKEN, nmtokenDV);
+
+ facets.minLength = 1;
+ tempDV = new XSSimpleTypeDecl(fAnySimpleType, null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV);
+ XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0);
+ nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
+ fBuiltInTypes.put(NMTOKENS, nmtokensDV);
+
+ }//createBuiltInTypes()
+
+ //REVISIT: only for testing purpose.
+ public static void main(String [] args){
+ SchemaDVFactoryImpl factory = new SchemaDVFactoryImpl();
+ XSSimpleType longDecl = factory.getBuiltInType("long");
+ String typeName = longDecl.getXSTypeName() ;
+ System.out.println("name of type = " + typeName );
+ }
}//SchemaDVFactory
1.4 +1 -3 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/StringDV.java
Index: StringDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/StringDV.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StringDV.java 2001/11/09 00:30:37 1.3
+++ StringDV.java 2001/11/09 17:49:49 1.4
@@ -57,15 +57,13 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import java.util.Locale;
-
/**
* Represent the schema type "string"
*
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: StringDV.java,v 1.3 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: StringDV.java,v 1.4 2001/11/09 17:49:49 sandygao Exp $
*/
public class StringDV extends TypeValidator {
1.2 +1 -3 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/UnionDV.java
Index: UnionDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/UnionDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnionDV.java 2001/11/09 00:30:37 1.1
+++ UnionDV.java 2001/11/09 17:49:49 1.2
@@ -57,15 +57,13 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import java.util.StringTokenizer;
-
/**
* Represent the schema union types
*
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: UnionDV.java,v 1.1 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: UnionDV.java,v 1.2 2001/11/09 17:49:49 sandygao Exp $
*/
public class UnionDV extends TypeValidator{
1.6 +178 -81 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/XSSimpleTypeDecl.java
Index: XSSimpleTypeDecl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/XSSimpleTypeDecl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSSimpleTypeDecl.java 2001/11/09 00:30:37 1.5
+++ XSSimpleTypeDecl.java 2001/11/09 17:49:49 1.6
@@ -57,9 +57,7 @@
package org.apache.xerces.impl.v2.new_datatypes;
-import org.apache.xerces.impl.xs.XSTypeDecl;
import org.apache.xerces.util.XMLChar;
-import org.apache.xerces.impl.xs.util.XInt;
import org.apache.xerces.impl.xpath.regex.RegularExpression;
import java.util.Vector;
@@ -69,7 +67,7 @@
* @author Sandy Gao, IBM
* @author Neeraj Bajaj, Sun Microsystems, inc.
*
- * @version $Id: XSSimpleTypeDecl.java,v 1.5 2001/11/09 00:30:37 sandygao Exp $
+ * @version $Id: XSSimpleTypeDecl.java,v 1.6 2001/11/09 17:49:49 sandygao Exp $
*/
class XSSimpleTypeDecl implements XSAtomicSimpleType, XSListSimpleType, XSUnionSimpleType {
@@ -131,18 +129,16 @@
static final short SPECIAL_TOKEN_NONE = 0;
static final short SPECIAL_TOKEN_NMTOKEN = 1;
static final short SPECIAL_TOKEN_NAME = 2;
- static final short SPECIAL_TOKEN_IDNAME = 3;
- static final short SPECIAL_TOKEN_IDREFNAME = 4;
- static final short SPECIAL_TOKEN_NCNAME = 5;
- static final short SPECIAL_TOKEN_IDNCNAME = 6;
- static final short SPECIAL_TOKEN_IDREFNCNAME = 7;
- static final short SPECIAL_TOKEN_ENTITY = 8;
+ static final short SPECIAL_TOKEN_NCNAME = 3;
static final String[] SPECIAL_TOKEN_STRING = {
- "NONE", "NMTOKEN", "Name", "ID(Name)", "IDREF(Name)",
- "NCName", "ID(NCName)", "IDREF(NCName)", "ENTITY(NCName)",
+ "NONE", "NMTOKEN", "Name", "NCName",
};
+ static final String[] WS_FACET_STRING = {
+ "preserve", "collapse", "replace",
+ };
+
//private short fPrimitiveDV = -1;
private XSSimpleTypeDecl fItemType;
private XSSimpleTypeDecl[] fMemberTypes;
@@ -152,7 +148,7 @@
private short fFinalSet = 0;
private XSSimpleTypeDecl fBase;
private short fVariety = -1;
- private short fValidateDV = -1;
+ private short fValidationDV = -1;
private short fFacetsDefined = 0;
private short fFixedFacet = 0;
@@ -180,12 +176,14 @@
//fPrimitiveDV = validateDV;
//if (validateDV == DV_ID || validateDV == DV_IDREF || validateDV == DV_ENTITY)
// fPrimitiveDV = DV_STRING;
- fValidateDV = validateDV;
+ fValidationDV = validateDV;
fFacetsDefined = FACET_WHITESPACE;
- if (validateDV == DV_STRING)
+ if (validateDV == DV_STRING) {
fWhiteSpace = WS_PRESERVE;
- else
+ } else {
fWhiteSpace = WS_COLLAPSE;
+ fFixedFacet = FACET_WHITESPACE;
+ }
}
//Create a new simple type for restriction.
@@ -196,7 +194,7 @@
fFinalSet = finalSet;
fVariety = fBase.fVariety;
- fValidateDV = fBase.fValidateDV;
+ fValidationDV = fBase.fValidationDV;
switch (fVariety) {
case VARIETY_ATOMIC:
//fPrimitiveDV = fBase.fPrimitiveDV;
@@ -208,6 +206,24 @@
fMemberTypes = fBase.fMemberTypes;
break;
}
+
+ // always inherit facets from the base.
+ // in case a type is created, but applyFacets is not called
+ fLength = fBase.fLength;
+ fMinLength = fBase.fMinLength;
+ fMaxLength = fBase.fMaxLength;
+ fPattern = fBase.fPattern;
+ fEnumeration = fBase.fEnumeration;
+ fWhiteSpace = fBase.fWhiteSpace;
+ fMaxExclusive = fBase.fMaxExclusive;
+ fMaxInclusive = fBase.fMaxInclusive;
+ fMinExclusive = fBase.fMinExclusive;
+ fMinInclusive = fBase.fMinInclusive;
+ fTotalDigits = fBase.fTotalDigits;
+ fFractionDigits = fBase.fFractionDigits;
+ fTokenType = fBase.fTokenType;
+ fFixedFacet = fBase.fFixedFacet;
+ fFacetsDefined = fBase.fFacetsDefined;
}
//Create a new simple type for list.
@@ -219,8 +235,9 @@
fVariety = VARIETY_LIST;
fItemType = (XSSimpleTypeDecl)itemType;
- fValidateDV = DV_LIST;
+ fValidationDV = DV_LIST;
fFacetsDefined = FACET_WHITESPACE;
+ fFixedFacet = FACET_WHITESPACE;
fWhiteSpace = WS_COLLAPSE;
}
@@ -233,7 +250,11 @@
fVariety = VARIETY_UNION;
fMemberTypes = memberTypes;
- fValidateDV = DV_UNION;
+ fValidationDV = DV_UNION;
+ // even for union, we set whitespace to something
+ // this will never be used, but we can use fFacetsDefined to check
+ // whether applyFacets() is allwwed: it's not allowed
+ // if fFacetsDefined != 0
fFacetsDefined = FACET_WHITESPACE;
fWhiteSpace = WS_COLLAPSE;
}
@@ -262,6 +283,10 @@
return fVariety;
}
+ public short getDefinedFacets() {
+ return fFacetsDefined;
+ }
+
// REVISIT
public XSSimpleType getPrimitiveType() {
if (fVariety == VARIETY_ATOMIC)
@@ -270,7 +295,6 @@
return null;
}
- // REVISIT
public XSSimpleType getItemType() {
if (fVariety == VARIETY_LIST)
return fItemType;
@@ -278,7 +302,6 @@
return null;
}
- // REVISIT
public XSSimpleType[] getMemberTypes() {
if (fVariety == VARIETY_UNION)
return fMemberTypes;
@@ -287,23 +310,59 @@
}
/**
- * If <restriction> is chosen, or built-in derived types by restriction
+ * If <restriction> is chosen
*/
- public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet) {
+ public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet)
+ throws InvalidDatatypeFacetException {
applyFacets(facets, presentFacet, fixedFacet, (short)0);
}
/**
+ * built-in derived types by restriction
+ */
+ void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet) {
+
+ try {
+ applyFacets(facets, presentFacet, fixedFacet, (short)0);
+ } catch (InvalidDatatypeFacetException e) {
+ // should never gets here, internel error
+ throw new RuntimeException("internal error");
+ }
+ }
+
+ /**
+ * built-in derived types by restriction
+ */
+ void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet, short tokenType) {
+
+ try {
+ applyFacets(facets, presentFacet, fixedFacet, tokenType);
+ } catch (InvalidDatatypeFacetException e) {
+ // should never gets here, internel error
+ throw new RuntimeException("internal error");
+ }
+ }
+
+ /**
* If <restriction> is chosen, or built-in derived types by restriction
*/
- void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, short tokenType) {
- if (fFacetsDefined != 0)
- return;
+ void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, short tokenType)
+ throws InvalidDatatypeFacetException {
+ // clear facets. because we always inherit facets in the constructor
+ // REVISIT: in fact, we don't need to clear them.
+ // we can convert 5 string values (4 bounds + 1 enum) to actual values,
+ // store them somewhere, then do facet checking at once, instead of
+ // going through the following steps. (lots of checking are redundant:
+ // for example, ((presentFacet & FACET_XXX) != 0))
+
+ fFacetsDefined = 0;
+ fFixedFacet = 0;
+
int result = 0 ;
// step 1: parse present facets
- short allowedFacet = fDVs[fValidateDV].getAllowedFacets();
+ short allowedFacet = fDVs[fValidationDV].getAllowedFacets();
// length
if ((presentFacet & FACET_LENGTH) != 0) {
@@ -381,7 +440,7 @@
}
// whiteSpace
if ((presentFacet & FACET_WHITESPACE) != 0) {
- if ((allowedFacet & FACET_WHITESPACE) != 0) {
+ if ((allowedFacet & FACET_WHITESPACE) == 0) {
reportError("non-supported facet");
} else {
fWhiteSpace = facets.whiteSpace;
@@ -519,28 +578,28 @@
// check 4.3.7.c1 must: minInclusive <= maxInclusive
if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) &&
((fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
- if (fDVs[fValidateDV].compare(fMinInclusive, fMaxInclusive) == 1)
+ if (fDVs[fValidationDV].compare(fMinInclusive, fMaxInclusive) == 1)
reportError("minInclusive value ='" + getStringValue(fMinInclusive) + "'must be <= maxInclusive value ='" +
getStringValue(fMaxInclusive) + "'. " );
}
// check 4.3.8.c2 must: minExclusive <= maxExclusive ??? minExclusive < maxExclusive
if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) {
- if (fDVs[fValidateDV].compare(fMinExclusive, fMaxExclusive) == 1)
+ if (fDVs[fValidationDV].compare(fMinExclusive, fMaxExclusive) == 1)
reportError( "minExclusive value ='" + getStringValue(fMinExclusive) + "'must be <= maxExclusive value ='" +
getStringValue(fMaxExclusive) + "'. " );
}
// check 4.3.9.c2 must: minExclusive < maxInclusive
if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0) && ((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) {
- if (fDVs[fValidateDV].compare(fMinExclusive, fMaxInclusive) != -1)
+ if (fDVs[fValidationDV].compare(fMinExclusive, fMaxInclusive) != -1)
reportError( "minExclusive value ='" + getStringValue(fMinExclusive) + "'must be > maxInclusive value ='" +
getStringValue(fMaxInclusive) + "'. " );
}
// check 4.3.10.c1 must: minInclusive < maxExclusive
if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) && ((fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
- if (fDVs[fValidateDV].compare(fMinInclusive, fMaxExclusive) != -1)
+ if (fDVs[fValidationDV].compare(fMinInclusive, fMaxExclusive) != -1)
reportError( "minInclusive value ='" + getStringValue(fMinInclusive) + "'must be < maxExclusive value ='" +
getStringValue(fMaxExclusive) + "'. " );
}
@@ -640,7 +699,7 @@
if (((fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
if (((fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
- result = fDVs[fValidateDV].compare(fMaxInclusive, fBase.fMaxInclusive);
+ result = fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMaxInclusive);
if ((fBase.fFixedFacet & FACET_MAXINCLUSIVE) != 0 &&
result != 0) {
@@ -654,14 +713,14 @@
}
}
if (((fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMaxInclusive, fBase.fMaxExclusive) != -1){
+ fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMaxExclusive) != -1){
reportError(
"maxInclusive value ='" + getStringValue(fMaxInclusive) + "' must be < fBase.maxExclusive value ='" +
getStringValue(fBase.fMaxExclusive) + "'." );
}
if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
- result = fDVs[fValidateDV].compare(fMaxInclusive, fBase.fMinInclusive);
+ result = fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMinInclusive);
if (result == -1) {
reportError( "maxInclusive value ='" + getStringValue(fMaxInclusive) + "' must be >= fBase.minInclusive value ='" +
getStringValue(fBase.fMinInclusive) + "'." );
@@ -669,7 +728,7 @@
}
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMaxInclusive, fBase.fMinExclusive ) != 1)
+ fDVs[fValidationDV].compare(fMaxInclusive, fBase.fMinExclusive ) != 1)
reportError(
"maxInclusive value ='" + getStringValue(fMaxInclusive) + "' must be > fBase.minExclusive value ='" +
getStringValue(fBase.fMinExclusive) + "'." );
@@ -682,7 +741,7 @@
// maxExclusive <= fBase.minExclusive
if (((fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) {
if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0)) {
- result= fDVs[fValidateDV].compare(fMaxExclusive, fBase.fMaxExclusive);
+ result= fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMaxExclusive);
if ((fBase.fFixedFacet & FACET_MAXEXCLUSIVE) != 0 && result != 0) {
reportError( "maxExclusive value = '" + getStringValue(fMaxExclusive) +
@@ -696,7 +755,7 @@
}
if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
- result= fDVs[fValidateDV].compare(fMaxExclusive, fBase.fMaxInclusive);
+ result= fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMaxInclusive);
if (result == 1) {
reportError( "maxExclusive value ='" + getStringValue(fMaxExclusive) + "' must be <= fBase.maxInclusive value ='" +
getStringValue(fBase.fMaxInclusive) + "'." );
@@ -704,12 +763,12 @@
}
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMaxExclusive, fBase.fMinExclusive ) != 1)
+ fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMinExclusive ) != 1)
reportError( "maxExclusive value ='" + getStringValue(fMaxExclusive) + "' must be > fBase.minExclusive value ='" +
getStringValue(fBase.fMinExclusive) + "'." );
if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMaxExclusive, fBase.fMinInclusive) != 1)
+ fDVs[fValidationDV].compare(fMaxExclusive, fBase.fMinInclusive) != 1)
reportError( "maxExclusive value ='" + getStringValue(fMaxExclusive) + "' must be > fBase.minInclusive value ='" +
getStringValue(fBase.fMinInclusive) + "'." );
}
@@ -722,7 +781,7 @@
if (((fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) {
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0)) {
- result= fDVs[fValidateDV].compare(fMinExclusive, fBase.fMinExclusive);
+ result= fDVs[fValidationDV].compare(fMinExclusive, fBase.fMinExclusive);
if ((fBase.fFixedFacet & FACET_MINEXCLUSIVE) != 0 &&
result != 0) {
reportError( "minExclusive value = '" + getStringValue(fMinExclusive) +
@@ -736,7 +795,7 @@
}
if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
- result=fDVs[fValidateDV].compare(fMinExclusive, fBase.fMaxInclusive);
+ result=fDVs[fValidationDV].compare(fMinExclusive, fBase.fMaxInclusive);
if (result == 1) {
reportError(
@@ -746,7 +805,7 @@
}
if ((( fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
- result = fDVs[fValidateDV].compare(fMinExclusive, fBase.fMinInclusive);
+ result = fDVs[fValidationDV].compare(fMinExclusive, fBase.fMinInclusive);
if (result == -1) {
reportError(
@@ -756,7 +815,7 @@
}
if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMinExclusive, fBase.fMaxExclusive) != -1)
+ fDVs[fValidationDV].compare(fMinExclusive, fBase.fMaxExclusive) != -1)
reportError( "minExclusive value ='" + getStringValue(fMinExclusive) + "' must be < fBase.maxExclusive value ='" +
getStringValue(fBase.fMaxExclusive) + "'." );
}
@@ -768,7 +827,7 @@
// minInclusive >= fBase.maxExclusive
if (((fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
if (((fBase.fFacetsDefined & FACET_MININCLUSIVE) != 0)) {
- result = fDVs[fValidateDV].compare(fMinInclusive, fBase.fMinInclusive);
+ result = fDVs[fValidationDV].compare(fMinInclusive, fBase.fMinInclusive);
if ((fBase.fFixedFacet & FACET_MININCLUSIVE) != 0 &&
result != 0) {
@@ -782,18 +841,18 @@
}
}
if ((( fBase.fFacetsDefined & FACET_MAXINCLUSIVE) != 0)) {
- result=fDVs[fValidateDV].compare(fMinInclusive, fBase.fMaxInclusive);
+ result=fDVs[fValidationDV].compare(fMinInclusive, fBase.fMaxInclusive);
if (result == 1) {
reportError( "minInclusive value ='" + getStringValue(fMinInclusive) + "' must be <= fBase.maxInclusive value ='" +
getStringValue(fBase.fMaxInclusive) + "'." );
}
}
if ((( fBase.fFacetsDefined & FACET_MINEXCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMinInclusive, fBase.fMinExclusive ) != 1)
+ fDVs[fValidationDV].compare(fMinInclusive, fBase.fMinExclusive ) != 1)
reportError( "minInclusive value ='" + getStringValue(fMinInclusive) + "' must be > fBase.minExclusive value ='" +
getStringValue(fBase.fMinExclusive) + "'." );
if ((( fBase.fFacetsDefined & FACET_MAXEXCLUSIVE) != 0) &&
- fDVs[fValidateDV].compare(fMinInclusive, fBase.fMaxExclusive) != -1)
+ fDVs[fValidationDV].compare(fMinInclusive, fBase.fMaxExclusive) != -1)
reportError( "minInclusive value ='" + getStringValue(fMinInclusive) + "' must be < fBase.maxExclusive value ='" +
getStringValue(fBase.fMaxExclusive) + "'." );
}
@@ -867,7 +926,7 @@
if ( (fBase.fFacetsDefined & FACET_PATTERN) != 0 ) {
if ((fFacetsDefined & FACET_PATTERN) == 0)
fPattern = new Vector();
- fFacetsDefined |= FACET_ENUMERATION;
+ fFacetsDefined |= FACET_PATTERN;
for (int i = fBase.fPattern.size()-1; i >= 0; i--)
fPattern.addElement(fBase.fPattern.elementAt(i));
fEnumeration = fBase.fEnumeration;
@@ -956,7 +1015,7 @@
}
}
- int length = fDVs[fValidateDV].getDataLength(ob);
+ int length = fDVs[fValidationDV].getDataLength(ob);
// maxLength
if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) {
@@ -1002,7 +1061,7 @@
//fractionDigits
if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) {
- int scale = fDVs[fValidateDV].getFractionDigits(ob);
+ int scale = fDVs[fValidationDV].getFractionDigits(ob);
if (scale > fFractionDigits) {
throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.FRACTION_EXCEEDED],
new Object[] {
@@ -1014,7 +1073,7 @@
//totalDigits
if ((fFacetsDefined & FACET_TOTALDIGITS)!=0) {
- int totalDigits = fDVs[fValidateDV].getTotalDigits(ob);
+ int totalDigits = fDVs[fValidationDV].getTotalDigits(ob);
if (totalDigits > fTotalDigits) {
throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.TOTALDIGITS_EXCEEDED],
new Object[] {
@@ -1038,7 +1097,7 @@
//maxinclusive
if ( (fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) {
- compare = fDVs[fValidateDV].compare(ob, fMaxInclusive);
+ compare = fDVs[fValidationDV].compare(ob, fMaxInclusive);
maxOk = (compare == 1) ? false:true;
upperBound = fMaxInclusive.toString();
if ( upperBound != null ) {
@@ -1051,7 +1110,7 @@
//maxExclusive
if ( (fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 ) {
- compare = fDVs[fValidateDV].compare(ob, fMaxExclusive );
+ compare = fDVs[fValidationDV].compare(ob, fMaxExclusive );
maxOk = (compare==-1)?true:false;
upperBound = fMaxExclusive.toString();
if ( upperBound != null ) {
@@ -1064,7 +1123,7 @@
//minInclusive
if ( (fFacetsDefined & FACET_MININCLUSIVE) != 0 ) {
- compare = fDVs[fValidateDV].compare(ob, fMinInclusive);
+ compare = fDVs[fValidationDV].compare(ob, fMinInclusive);
minOk = (compare==-1)?false:true;
lowerBound = fMinInclusive.toString();
if ( lowerBound != null ) {
@@ -1077,7 +1136,7 @@
//minExclusive
if ( (fFacetsDefined & FACET_MINEXCLUSIVE) != 0 ) {
- compare = fDVs[fValidateDV].compare(ob, fMinExclusive);
+ compare = fDVs[fValidationDV].compare(ob, fMinExclusive);
minOk = (compare==1)?true:false;
lowerBound = fMinExclusive.toString();
if ( lowerBound != null ) {
@@ -1104,16 +1163,11 @@
// PATTERN "\\c+"
seenErr = !XMLChar.isValidNmtoken(content);
}
- else if (fTokenType == SPECIAL_TOKEN_NAME ||
- fTokenType == SPECIAL_TOKEN_IDNAME ||
- fTokenType == SPECIAL_TOKEN_IDREFNAME) {
+ else if (fTokenType == SPECIAL_TOKEN_NAME) {
// PATTERN "\\i\\c*"
seenErr = !XMLChar.isValidName(content);
}
- else if (fTokenType == SPECIAL_TOKEN_NCNAME ||
- fTokenType == SPECIAL_TOKEN_IDNCNAME ||
- fTokenType == SPECIAL_TOKEN_IDREFNCNAME ||
- fTokenType == SPECIAL_TOKEN_ENTITY) {
+ else if (fTokenType == SPECIAL_TOKEN_NCNAME) {
// PATTERN "[\\i-[:]][\\c-[:]]*"
// REVISIT: !!!NOT IMPLEMENTED in XMLChar
seenErr = !XMLChar.isValidNCName(content);
@@ -1124,26 +1178,31 @@
}
}
+ // check extra rules: for ID/IDREF/ENTITY
+ fDVs[fValidationDV].checkExtraRules(ob, context);
+
return ob;
}// validate()
private Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
+
+ if (fVariety == VARIETY_ATOMIC) {
- if(fVariety == VARIETY_ATOMIC)
- return fDVs[fValidateDV].getActualValue(content, context);
+ String nvalue = normalize(content, fWhiteSpace);
+ return fDVs[fValidationDV].getActualValue(nvalue, context);
- else if(fVariety == VARIETY_LIST){
- StringTokenizer parsedList = new StringTokenizer(content);
+ } else if (fVariety == VARIETY_LIST) {
+
+ String nvalue = normalize(content, fWhiteSpace);
+ StringTokenizer parsedList = new StringTokenizer(nvalue);
int countOfTokens = parsedList.countTokens() ;
Object[] ret = new Object[countOfTokens];
for(int i = 0 ; i < countOfTokens ; i ++){
ret[i] = fItemType.validate(parsedList.nextToken(), context);
}
return ret;
- }
- else if(fVariety == VARIETY_UNION){
- Object ret = null;
+ } else { // (fVariety == VARIETY_UNION)
for(int i = 0 ; i < fMemberTypes.length; i++) {
try {
@@ -1157,14 +1216,12 @@
throw new InvalidDatatypeValueException(msg);
}
- // should never get here
- return null;
}//getActualValue()
public boolean isEqual(Object value1, Object value2) {
if (fVariety == VARIETY_ATOMIC)
- return fDVs[fValidateDV].isEqual(value1,value2);
+ return fDVs[fValidationDV].isEqual(value1,value2);
else if (fVariety == VARIETY_LIST) {
Object[] v1 = (Object[])value1;
@@ -1194,19 +1251,59 @@
return false;
}//isEqual()
- void reportError(String msg) {
- // REVISIT: how do we report datatype facet errors?
- // passing ErrorReporter in? return an array of errors back?
- System.out.println("reportError: " + msg);
+ // normalize the string according to the whiteSpace facet
+ public static String normalize(String content, short ws) {
+ int len = content == null ? 0 : content.length();
+ if (len == 0 || ws == WS_PRESERVE)
+ return content;
+
+ StringBuffer sb = new StringBuffer();
+ if (ws == WS_REPLACE) {
+ char ch;
+ // when it's replace, just replace #x9, #xa, #xd by #x20
+ for (int i = 0; i < len; i++) {
+ ch = content.charAt(i);
+ if (ch != 0x9 && ch != 0xa && ch != 0xd)
+ sb.append(ch);
+ else
+ sb.append((char)0x20);
+ }
+ } else {
+ char ch;
+ int i;
+ boolean isLeading = true;
+ // when it's collapse
+ for (i = 0; i < len; i++) {
+ ch = content.charAt(i);
+ // append real characters, so we passed leading ws
+ if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) {
+ sb.append(ch);
+ isLeading = false;
+ }
+ else {
+ // for whitespaces, we skip all following ws
+ for (; i < len-1; i++) {
+ ch = content.charAt(i+1);
+ if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20)
+ break;
+ }
+ // if it's not a leading or tailing ws, then append a space
+ if (i < len - 1 && !isLeading)
+ sb.append((char)0x20);
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+ void reportError(String msg) throws InvalidDatatypeFacetException {
+ throw new InvalidDatatypeFacetException(msg);
}
- //REVISIT: error handling
private String whiteSpaceValue(short ws){
- if (ws != WS_REPLACE)
- return (ws == WS_PRESERVE)?"preserve":"collapse" ;
- return "replace";
-
+ return WS_FACET_STRING[ws];
}
public String getStringValue(Object value){
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/Base64.java
Index: Base64.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
/**
* This class provides encode/decode for RFC 2045 Base64 as
* defined by RFC 2045, N. Freed and N. Borenstein.
* RFC 2045: Multipurpose Internet Mail Extensions (MIME)
* Part One: Format of Internet Message Bodies. Reference
* 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
* This class is used by XML Schema binary format validation
*
* This implementation does not encode/decode streaming
* data. You need the data that you will encode/decode
* already on a byte arrray.
*
* @author Jeffrey Rodriguez
* @author Sandy Gao
* @version $Id: Base64.java,v 1.1 2001/11/09 17:49:49 sandygao Exp $
*/
public final class Base64 {
static private final int BASELENGTH = 255;
static private final int LOOKUPLENGTH = 64;
static private final int TWENTYFOURBITGROUP = 24;
static private final int EIGHTBIT = 8;
static private final int SIXTEENBIT = 16;
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 boolean fDebug = false;
static private byte [] base64Alphabet = new byte[BASELENGTH];
static private byte [] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];
static {
for (int i = 0; i<BASELENGTH; i++) {
base64Alphabet[i] = -1;
}
for (int i = 'Z'; i >= 'A'; i--) {
base64Alphabet[i] = (byte) (i-'A');
}
for (int i = 'z'; i>= 'a'; i--) {
base64Alphabet[i] = (byte) ( i-'a' + 26);
}
for (int i = '9'; i >= '0'; i--) {
base64Alphabet[i] = (byte) (i-'0' + 52);
}
base64Alphabet['+'] = 62;
base64Alphabet['/'] = 63;
for (int i = 0; i<=25; i++)
lookUpBase64Alphabet[i] = (byte) ('A'+i );
for (int i = 26, j = 0; i<=51; i++, j++)
lookUpBase64Alphabet[i] = (byte) ('a'+ j );
for (int i = 52, j = 0; i<=61; i++, j++)
lookUpBase64Alphabet[i] = (byte) ('0' + j );
lookUpBase64Alphabet[62] = (byte) '+';
lookUpBase64Alphabet[63] = (byte) '/';
}
protected static boolean isWhiteSpace(byte octect) {
return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
}
protected static boolean isPad(byte octect) {
return (octect == PAD);
}
protected static boolean isData(byte octect) {
return (base64Alphabet[octect] != -1);
}
protected static boolean isBase64(byte octect) {
return (isWhiteSpace(octect) || isPad(octect) || isData(octect));
}
/**
* Encodes hex octects into Base64
*
* @param binaryData Array containing binaryData
* @return Encoded Base64 array
*/
public static byte[] encode(byte[] binaryData) {
if (binaryData == null)
return null;
int lengthDataBits = binaryData.length*EIGHTBIT;
int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP;
int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP;
byte 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 ];
byte k=0, l=0, b1=0,b2=0,b3=0;
int encodedIndex = 0;
int dataIndex = 0;
int i = 0;
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];
if (fDebug) {
System.out.println( "b1= " + b1 +", b2= " + b2 + ", b3= " + b3 );
}
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 ];
}
// form integral number of 6-bit groups
dataIndex = i*3;
encodedIndex = i*4;
if (fewerThan24bits == EIGHTBIT) {
b1 = binaryData[dataIndex];
k = (byte) ( b1 &0x03 );
if (fDebug) {
System.out.println("b1=" + b1);
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;
} else if (fewerThan24bits == SIXTEENBIT) {
b1 = binaryData[dataIndex];
b2 = binaryData[dataIndex +1 ];
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);
encodedData[encodedIndex] = lookUpBase64Alphabet[ val1 ];
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ val2 | ( k<<4 )];
encodedData[encodedIndex + 2] = lookUpBase64Alphabet[ l<<2 ];
encodedData[encodedIndex + 3] = PAD;
}
return encodedData;
}
/**
* Decodes Base64 data into octects
*
* @param binaryData Byte array containing Base64 data
* @return Array containind decoded data.
*/
public static byte[] decode(byte[] base64Data) {
if (base64Data == null)
return null;
if (base64Data.length%FOURBYTE != 0) {
return null;//should be divisible by four
}
int numberQuadruple = (base64Data.length/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;
// Throw away anything not in normalizedBase64Data
// Adjust size
int i = 0;
int encodedIndex = 0;
int dataIndex = 0;
decodedData = new byte[ (numberQuadruple)*3];
for (; i<numberQuadruple-1; i++) {
if (!isData( (d1 = base64Data[dataIndex++]) )||
!isData( (d2 = base64Data[dataIndex++]) )||
!isData( (d3 = base64Data[dataIndex++]) )||
!isData( (d4 = base64Data[dataIndex++]) ))
return null;//if found "no data" just return null
b1 = base64Alphabet[d1];
b2 = base64Alphabet[d2];
b3 = base64Alphabet[d3];
b4 = base64Alphabet[d4];
decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ;
decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) );
decodedData[encodedIndex++] = (byte)( b3<<6 | b4 );
}
if (!isData( (d1 = base64Data[dataIndex++]) ) ||
!isData( (d2 = base64Data[dataIndex++]) )) {
return null;//if found "no data" just return null
}
b1 = base64Alphabet[d1];
b2 = base64Alphabet[d2];
d3 = base64Data[dataIndex++];
d4 = base64Data[dataIndex++];
if (!isData( (d3 ) ) ||
!isData( (d4 ) )) {//Check if they are PAD characters
if (isPad( d3 ) && isPad( d4)) { //Two PAD e.g. 3c[Pad][Pad]
if ((b2 & 0xf) != 0)//last 4 bits should be zero
return null;
byte[] tmp = new byte[ i*3 + 1 ];
System.arraycopy( decodedData, 0, tmp, 0, i*3 );
tmp[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ;
return tmp;
} else if (!isPad( d3) && isPad(d4)) { //One PAD e.g. 3cQ[Pad]
b3 = base64Alphabet[ d3 ];
if ((b3 & 0x3 ) != 0)//last 2 bits should be zero
return null;
byte[] tmp = new byte[ i*3 + 2 ];
System.arraycopy( decodedData, 0, tmp, 0, i*3 );
tmp[encodedIndex++] = (byte)( b1 <<2 | b2>>4 );
tmp[encodedIndex] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) );
return tmp;
} else {
return null;//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data
}
} else { //No PAD e.g 3cQl
b3 = base64Alphabet[ d3 ];
b4 = base64Alphabet[ d4 ];
decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ;
decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) );
decodedData[encodedIndex++] = (byte)( b3<<6 | b4 );
}
return decodedData;
}
/**
* 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 = decode(base64Data.getBytes());
return decoded == null ? null : new String(decoded);
}
}
1.1 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/HexBin.java
Index: HexBin.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl.v2.new_datatypes;
/**
* format validation
*
* This class encodes/decodes hexadecimal data
* @author Jeffrey Rodriguez
* @version $Id: HexBin.java,v 1.1 2001/11/09 17:49:49 sandygao Exp $
*/
public final class HexBin {
static private final int BASELENGTH = 255;
static private final int LOOKUPLENGTH = 16;
static private byte [] hexNumberTable = new byte[BASELENGTH];
static private byte [] lookUpHexAlphabet = new byte[LOOKUPLENGTH];
static {
for (int i = 0; i<BASELENGTH; i++ ) {
hexNumberTable[i] = -1;
}
for ( int i = '9'; i >= '0'; i--) {
hexNumberTable[i] = (byte) (i-'0');
}
for ( int i = 'F'; i>= 'A'; i--) {
hexNumberTable[i] = (byte) ( i-'A' + 10 );
}
for ( int i = 'f'; i>= 'a'; i--) {
hexNumberTable[i] = (byte) ( i-'a' + 10 );
}
for(int i = 0; i<10; i++ )
lookUpHexAlphabet[i] = (byte) ('0'+i );
for(int i = 10; i<=15; i++ )
lookUpHexAlphabet[i] = (byte) ('A'+i -10);
}
/**
* byte to be tested if it is Base64 alphabet
*
* @param octect
* @return
*/
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) {
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];
}
return encodedData;
}
static public byte[] decode(byte[] binaryData) {
if (binaryData == null)
return null;
int lengthData = binaryData.length;
if (lengthData % 2 != 0)
return null;
int lengthDecode = lengthData / 2;
byte[] decodedData = new byte[lengthDecode];
for( int i = 0; i<lengthDecode; i++ ){
decodedData[i] = (byte)((hexNumberTable[binaryData[i*2]] << 4) | hexNumberTable[binaryData[i*2+1]]);
}
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 = decode(binaryData.getBytes());
return decoded == null ? null : new String(decoded);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org