You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by je...@locus.apache.org on 2000/10/12 23:46:12 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes BinaryDatatypeValidator.java BooleanDatatypeValidator.java DecimalDatatypeValidator.java DoubleDatatypeValidator.java ENTITYDatatypeValidator.java FloatDatatypeValidator.java HexBin.java IDDatatypeValidator.java IDREFDatatypeValidator.java NOTATIONDatatypeValidator.java QNameDatatypeValidator.java RecurringDurationDatatypeValidator.java TimeDurationDatatypeValidator.java URIReferenceDatatypeValidator.java AbstractDatatypeValidator.java DatatypeValidatorFactoryImpl.java StringDatatypeValidator.java
jeffreyr 00/10/12 14:46:09
Modified: java/src/org/apache/xerces/impl/validation Tag: xerces_j_2
DatatypeValidator.java Grammar.java
InvalidDatatypeValueException.java
java/src/org/apache/xerces/impl/validation/datatypes Tag:
xerces_j_2 AbstractDatatypeValidator.java
DatatypeValidatorFactoryImpl.java
StringDatatypeValidator.java
Added: java/src/org/apache/xerces/impl/validation/datatypes Tag:
xerces_j_2 BinaryDatatypeValidator.java
BooleanDatatypeValidator.java
DecimalDatatypeValidator.java
DoubleDatatypeValidator.java
ENTITYDatatypeValidator.java
FloatDatatypeValidator.java HexBin.java
IDDatatypeValidator.java
IDREFDatatypeValidator.java
NOTATIONDatatypeValidator.java
QNameDatatypeValidator.java
RecurringDurationDatatypeValidator.java
TimeDurationDatatypeValidator.java
URIReferenceDatatypeValidator.java
Log:
Add the whole datatype validation
Revision Changes Path
No revision
No revision
1.1.2.3 +19 -1 xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/DatatypeValidator.java
Index: DatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/DatatypeValidator.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- DatatypeValidator.java 2000/10/02 00:40:07 1.1.2.2
+++ DatatypeValidator.java 2000/10/12 21:43:58 1.1.2.3
@@ -61,9 +61,27 @@
/**
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: DatatypeValidator.java,v 1.1.2.2 2000/10/02 00:40:07 lehors Exp $
+ * @version $Id: DatatypeValidator.java,v 1.1.2.3 2000/10/12 21:43:58 jeffreyr Exp $
*/
public interface DatatypeValidator {
+ //
+ // Data
+ //
+ public static final int FACET_LENGTH = 1;
+ public static final int FACET_MINLENGTH = 1<<1;
+ public static final int FACET_MAXLENGTH = 1<<2;
+ public static final int FACET_PATTERN = 1<<3;
+ public static final int FACET_ENUMERATION = 1<<4;
+ public static final int FACET_MAXINCLUSIVE = 1<<5;
+ public static final int FACET_MAXEXCLUSIVE = 1<<6;
+ public static final int FACET_MININCLUSIVE = 1<<7;
+ public static final int FACET_MINEXCLUSIVE = 1<<8;
+ public static final int FACET_PRECISSION = 1<<9;
+ public static final int FACET_SCALE = 1<<10;
+ public static final int FACET_ENCODING = 1<<11;
+ public static final int FACET_DURATION = 1<<12;
+ public static final int FACET_PERIOD = 1<<13;
+
//
// Methods
1.1.2.8 +16 -16 xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/Grammar.java
Index: Grammar.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/Grammar.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- Grammar.java 2000/10/12 16:56:18 1.1.2.7
+++ Grammar.java 2000/10/12 21:43:59 1.1.2.8
@@ -68,7 +68,7 @@
* @author Stubs generated by DesignDoc on Wed Jun 07 11:58:44 PDT 2000
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
*
- * @version $Id: Grammar.java,v 1.1.2.7 2000/10/12 16:56:18 jeffreyr Exp $
+ * @version $Id: Grammar.java,v 1.1.2.8 2000/10/12 21:43:59 jeffreyr Exp $
*/
public class Grammar {
@@ -286,19 +286,19 @@
short attributeType;
boolean isList;
- if (fAttributeDeclType[chunk][index] == -1) {
+ //if (fAttributeDeclType[chunk][index] == -1) {
- attributeType = -1;
- isList = false;
- }
- else {
- attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK);
- isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0;
- }
- attributeDecl.simpleType.setValues(attributeType,"",fAttributeDeclEnumeration[chunk][index],
- isList, fAttributeDeclDefaultType[chunk][index],
- fAttributeDeclDefaultValue[chunk][index],
- fAttributeDeclDatatypeValidator[chunk][index]);
+ // attributeType = -1;
+ //isList = false;
+ // }
+ // else {
+ // attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK);
+ // isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0;
+ //}
+ //attributeDecl.simpleType.setValues(attributeType,"",fAttributeDeclEnumeration[chunk][index],
+ // isList, fAttributeDeclDefaultType[chunk][index],
+ // fAttributeDeclDefaultValue[chunk][index],
+ // fAttributeDeclDatatypeValidator[chunk][index]);
return true;
} // getAttributeDecl
@@ -432,9 +432,9 @@
- if (elementDecl.simpleType.list == true ) {
- fElementDeclType[chunk][index] |= LIST_FLAG;
- }
+ //if (elementDecl.simpleType.list == true ) {
+ // fElementDeclType[chunk][index] |= LIST_FLAG;
+ //}
}
1.1.2.3 +25 -2 xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/InvalidDatatypeValueException.java
Index: InvalidDatatypeValueException.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/InvalidDatatypeValueException.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- InvalidDatatypeValueException.java 2000/10/02 00:40:07 1.1.2.2
+++ InvalidDatatypeValueException.java 2000/10/12 21:44:01 1.1.2.3
@@ -61,15 +61,22 @@
/**
* @author Stubs generated by DesignDoc on Wed Jun 07 11:58:44 PDT 2000
- * @version $Id: InvalidDatatypeValueException.java,v 1.1.2.2 2000/10/02 00:40:07 lehors Exp $
+ * @version $Id: InvalidDatatypeValueException.java,v 1.1.2.3 2000/10/12 21:44:01 jeffreyr Exp $
*/
public class InvalidDatatypeValueException
extends SAXException {
-
//
+ //data
+ //
+ private int majorCode = -1;
+ private int minorCode = -1;
+
+ //
// Constructors
//
+
+
/**
*
*/
@@ -104,5 +111,21 @@
public InvalidDatatypeValueException(String message, Exception exception) {
super(message, exception);
}
+
+ //methods
+public int getMinorCode(){
+ return minorCode;
+}
+public int getMajorCode(){
+ return majorCode;
+}
+
+public void setMinorCode(int code ){
+ majorCode = code;
+}
+public void setMajorCode(int code ){
+ minorCode = code;
+}
+
} // class InvalidDatatypeValueException
No revision
No revision
1.1.2.3 +10 -1 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/AbstractDatatypeValidator.java
Index: AbstractDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/AbstractDatatypeValidator.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- AbstractDatatypeValidator.java 2000/10/02 00:40:09 1.1.2.2
+++ AbstractDatatypeValidator.java 2000/10/12 21:44:05 1.1.2.3
@@ -64,7 +64,7 @@
/**
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: AbstractDatatypeValidator.java,v 1.1.2.2 2000/10/02 00:40:09 lehors Exp $
+ * @version $Id: AbstractDatatypeValidator.java,v 1.1.2.3 2000/10/12 21:44:05 jeffreyr Exp $
*/
public class AbstractDatatypeValidator
implements DatatypeValidator {
@@ -79,6 +79,15 @@
//
// Constructors
//
+
+ /**
+ *
+ * Constructor for Native datatype, No Facets defined, derived by Restriction
+ */
+
+ protected AbstractDatatypeValidator()
+ throws InvalidDatatypeFacetException {
+ }
/**
*
1.1.2.3 +328 -28 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/DatatypeValidatorFactoryImpl.java
Index: DatatypeValidatorFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/DatatypeValidatorFactoryImpl.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- DatatypeValidatorFactoryImpl.java 2000/10/02 00:40:09 1.1.2.2
+++ DatatypeValidatorFactoryImpl.java 2000/10/12 21:44:11 1.1.2.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,42 +58,342 @@
package org.apache.xerces.impl.validation.datatypes;
import java.util.Hashtable;
+import java.lang.reflect.*;
import org.apache.xerces.impl.validation.DatatypeValidator;
import org.apache.xerces.impl.validation.DatatypeValidatorFactory;
import org.apache.xerces.impl.validation.InvalidDatatypeFacetException;
import org.apache.xerces.impl.validation.InvalidDatatypeValueException;
+import org.apache.xerces.impl.validation.grammars.SchemaSymbols;
+
+
/**
- * @author Stubs generated by DesignDoc on Wed Jun 07 11:58:44 PDT 2000
- * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.1.2.2 2000/10/02 00:40:09 lehors Exp $
+ * This is the datatype validator factory registry.
+ *
+ * This class is based on a Singleton pattern so there
+ * only one registry table, fBaseTypes.
+ *
+ * This class implements a factory method and it is
+ * use by validators to register and obtain datatypes.
+ *
+ * Validator should first obtain the datatype Registry
+ * through the getDatatypeRegistry class method, and
+ * then they should call the createDatatypeValidator
+ * method to get a validator.
+ *
+ * @author Jeffrey Rodriguez
+ * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.1.2.3 2000/10/12 21:44:11 jeffreyr Exp $
*/
-public class DatatypeValidatorFactoryImpl
- implements DatatypeValidatorFactory {
+public class DatatypeValidatorFactoryImpl implements DatatypeValidatorFactory {
+ private static final boolean fDebug = false;
+ private Hashtable fBaseTypes = new Hashtable();
+
- //
- // Data
- //
-
- /** fBaseTypes */
- protected Hashtable fBaseTypes;
-
- //
- // DatatypeValidatorFactory methods
- //
+ private static DatatypeValidatorFactoryImpl fRegistryOfDatatypes =
+ new DatatypeValidatorFactoryImpl();
+ private DatatypeValidatorFactoryImpl() {
+ initializeRegistry();
+ }
+
/**
- * createDatatypeValidator
- *
- * @param name
- * @param base
- * @param facets
- * @param list
- *
- * @return
+ * Initializes registry with primitive and derived
+ * Simple types.
*/
- public DatatypeValidator createDatatypeValidator(String name, DatatypeValidator base, Hashtable facets, boolean list)
- throws InvalidDatatypeFacetException, InvalidDatatypeValueException {
- return null;
- } // createDatatypeValidator
+ void initializeRegistry() {
+ DatatypeValidator v = null;
+
+ //Register Primitive Datatypes
+
+ try {
+ fBaseTypes.put("string", new StringDatatypeValidator() );
+ fBaseTypes.put("boolean", new BooleanDatatypeValidator() );
+ fBaseTypes.put("float", new FloatDatatypeValidator());
+ fBaseTypes.put("double", new DoubleDatatypeValidator());
+ fBaseTypes.put("decimal", new DecimalDatatypeValidator());
+ fBaseTypes.put("timeDuration", new TimeDurationDatatypeValidator());
+ fBaseTypes.put("recurringDuration", new RecurringDurationDatatypeValidator());
+ fBaseTypes.put("binary", new BinaryDatatypeValidator());
+ fBaseTypes.put("uriReference", new URIReferenceDatatypeValidator());
+ fBaseTypes.put("ID", new IDDatatypeValidator());
+ fBaseTypes.put("IDREF", new IDREFDatatypeValidator());
+ fBaseTypes.put("ENTITY", new ENTITYDatatypeValidator());
+ fBaseTypes.put("NOTATION", new NOTATIONDatatypeValidator());
+ fBaseTypes.put("QName", new QNameDatatypeValidator());
+
+
+ Hashtable facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_PATTERN , "([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*" );
+
+ createDatatypeValidator("language", new StringDatatypeValidator() , facets,
+ false );
+
+ createDatatypeValidator( "IDREFS", new IDREFDatatypeValidator(), null , true );
+
+ createDatatypeValidator( "ENTITIES", new ENTITYDatatypeValidator(), null, true );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_PATTERN , "\\c+" );
+ createDatatypeValidator("NMTOKEN", new StringDatatypeValidator(), facets, false );
+
+ createDatatypeValidator("NMTOKENS",
+ getDatatypeValidator( "NMTOKEN" ), null, true );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_PATTERN , "\\i\\c*" );
+ createDatatypeValidator("Name", new StringDatatypeValidator(), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
+ createDatatypeValidator("NCName", new StringDatatypeValidator(), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_SCALE, "0");
+ createDatatypeValidator("integer", new DecimalDatatypeValidator(), facets, false);
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "0" );
+ createDatatypeValidator("nonPositiveInteger",
+ getDatatypeValidator("integer"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "-1" );
+ createDatatypeValidator("negativeInteger",
+ getDatatypeValidator( "nonPositiveInteger"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "9223372036854775807");
+ facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-9223372036854775808");
+ createDatatypeValidator("long", getDatatypeValidator( "integer"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "2147483647");
+ facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-2147483648");
+ createDatatypeValidator("int", getDatatypeValidator( "long"), facets,false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "32767");
+ facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-32768");
+ createDatatypeValidator("short", getDatatypeValidator( "int"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "127");
+ facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-128");
+ createDatatypeValidator("byte",
+ getDatatypeValidator( "short"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MININCLUSIVE, "0" );
+ createDatatypeValidator("nonNegativeInteger",
+ getDatatypeValidator( "integer"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "18446744073709551615" );
+ createDatatypeValidator("unsignedLong",
+ getDatatypeValidator( "nonNegativeInteger"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "4294967295" );
+ createDatatypeValidator("unsignedInt",
+ getDatatypeValidator( "unsignedLong"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "65535" );
+ createDatatypeValidator("unsignedShort",
+ getDatatypeValidator( "unsignedInt"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "255" );
+ createDatatypeValidator("unsignedByte",
+ getDatatypeValidator( "unsignedShort"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_MININCLUSIVE, "1" );
+ createDatatypeValidator("positiveInteger",
+ getDatatypeValidator( "nonNegativeInteger"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
+ facets.put(SchemaSymbols.ELT_PERIOD, "P0Y" );
+ createDatatypeValidator("timeInstant",
+ getDatatypeValidator( "recurringDuration"),facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
+// facets.put(SchemaSymbols.ELT_PERIOD, "PY24H" ); Bug -- WORK TODO
+ createDatatypeValidator("time",
+ getDatatypeValidator( "recurringDuration"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_PERIOD, "P0Y" );
+ createDatatypeValidator("timePeriod",
+ getDatatypeValidator( "recurringDuration"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_DURATION, "PT24H" );
+ createDatatypeValidator("date",
+ getDatatypeValidator( "timePeriod"), facets, false );
+
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_DURATION, "P1M" );
+ createDatatypeValidator("month",
+ getDatatypeValidator( "timePeriod"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_DURATION, "P1Y" );
+ createDatatypeValidator("year",
+ getDatatypeValidator( "timePeriod"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_DURATION, "P100Y" );
+ createDatatypeValidator("century",
+ getDatatypeValidator( "timePeriod"), facets, false );
+
+ facets = new Hashtable();
+ facets.put(SchemaSymbols.ELT_PERIOD, "P1Y" );
+ facets.put(SchemaSymbols.ELT_DURATION, "PT24H" );
+ createDatatypeValidator("recurringDate",
+ getDatatypeValidator( "recurringDuration"),facets, false );
+ } catch ( InvalidDatatypeFacetException ex ){
+ ex.printStackTrace();
+ } catch ( InvalidDatatypeValueException ex ){
+ ex.printStackTrace();
+ }
+ }
+
+ public void resetRegistry(){
+ fBaseTypes.clear();
+ initializeRegistry();
+ }
+
+ public DatatypeValidator createDatatypeValidator(String name, DatatypeValidator base, Hashtable facets, boolean list)
+ throws InvalidDatatypeFacetException, InvalidDatatypeValueException {
+
+ DatatypeValidator simpleType = null;
+
+ if (this.fDebug == true) {
+ System.out.println("type name = " + name );
+ }
+
+ if ( base != null ) {
+ try {
+ Class validatorDef = base.getClass();
+
+ Class [] validatorArgsClass = new Class[] {
+ org.apache.xerces.impl.validation.DatatypeValidator.class,
+ java.util.Hashtable.class,
+ boolean.class};
+
+
+
+ Object [] validatorArgs = new Object[] {
+ base, facets, new Boolean( list )};
+
+
+
+
+ Constructor validatorConstructor =
+ validatorDef.getConstructor( validatorArgsClass );
+
+
+ simpleType =
+ ( DatatypeValidator ) createDatatypeValidator (
+ validatorConstructor, validatorArgs );
+
+ if (simpleType != null) {
+ addValidator( name, simpleType );//register validator
+ }
+
+
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+
+ }
+ return simpleType;// return it
+ }
+
+
+
+ private static Object createDatatypeValidator(Constructor validatorConstructor,
+ Object[] arguments) throws InvalidDatatypeFacetException {
+ Object validator = null;
+ try {
+ validator = validatorConstructor.newInstance(arguments);
+ return validator;
+ } catch (InstantiationException e) {
+ if( fDebug ){
+ e.printStackTrace();
+ }else {
+ return null;
+ }
+ } catch (IllegalAccessException e) {
+ if( fDebug ){
+ e.printStackTrace();
+ }else {
+ return null;
+ }
+ } catch (IllegalArgumentException e) {
+ if( fDebug ){
+ e.printStackTrace();
+ }else {
+ return null;
+ }
+ } catch (InvocationTargetException e) {
+ if ( fDebug ){
+ System.out.println("!! The original error message is: " + e.getTargetException().getMessage() );
+ e.getTargetException().printStackTrace();
+ } else {
+ throw new InvalidDatatypeFacetException( e.getTargetException().getMessage() );
+ //System.out.println("Exception: " + e.getTargetException
+ //validator = null;
+ }
+ }
+ return validator;
+ }
+
+
+ public DatatypeValidator getDatatypeValidator(String type) {
+ AbstractDatatypeValidator simpleType = null;
+ if( fDebug ) {
+ System.out.println( "type = >" + type +"<");
+ System.out.println( "fBaseTypes = >" + fBaseTypes +"<" );
+ simpleType = (AbstractDatatypeValidator) fBaseTypes.get(type);
+ }
+ if ( type != null && fBaseTypes != null
+ && fBaseTypes.containsKey( type ) == true ) {
+ simpleType = (AbstractDatatypeValidator) fBaseTypes.get(type);
+ }
+ return (DatatypeValidator) simpleType;
+ }
+
+ private void addValidator(String name, DatatypeValidator v) {
+ fBaseTypes.put(name,v);
+ }
+
+ static public DatatypeValidatorFactoryImpl getDatatypeRegistry() {
+ return fRegistryOfDatatypes;
+ }
+
+ static public void main( String argv[] ){
+ DatatypeValidatorFactoryImpl tstRegistry = DatatypeValidatorFactoryImpl.getDatatypeRegistry();
+
+
+ DatatypeValidator tstData1 = tstRegistry.getDatatypeValidator( "NTOKEN" );
+ DatatypeValidator tstData2 = tstRegistry.getDatatypeValidator( "NTOKENS" );
+
+ System.out.println( "NMTOKEN = " + tstData1 );
+ System.out.println( "NMTOKENS = " + tstData2 );
+
+ }
+}
-} // class DatatypeValidatorFactoryImpl
1.1.2.3 +406 -16 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/StringDatatypeValidator.java
Index: StringDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/StringDatatypeValidator.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- StringDatatypeValidator.java 2000/10/02 00:40:09 1.1.2.2
+++ StringDatatypeValidator.java 2000/10/12 21:45:02 1.1.2.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
+ * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,34 +54,424 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
-
package org.apache.xerces.impl.validation.datatypes;
import java.util.Hashtable;
+import java.util.Vector;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.text.Collator;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.NoSuchElementException;
import org.apache.xerces.impl.validation.DatatypeValidator;
+import org.apache.xerces.impl.validation.grammars.SchemaSymbols;
+import org.apache.xerces.impl.validation.datatypes.regex.RegularExpression;
import org.apache.xerces.impl.validation.InvalidDatatypeFacetException;
+import org.apache.xerces.impl.validation.InvalidDatatypeValueException;
+
+
/**
- * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: StringDatatypeValidator.java,v 1.1.2.2 2000/10/02 00:40:09 lehors Exp $
+ * StringValidator validates that XML content is a W3C string type.
+ * @version $Id: StringDatatypeValidator.java,v 1.1.2.3 2000/10/12 21:45:02 jeffreyr Exp $
*/
-public class StringDatatypeValidator
- extends AbstractDatatypeValidator {
+public class StringDatatypeValidator extends AbstractDatatypeValidator{
+ private Locale fLocale = null;
+ DatatypeValidator fBaseValidator = null; // Native datatypes have null
+
+ private int fLength = 0;
+ private int fMaxLength = Integer.MAX_VALUE;
+ private int fMinLength = 0;
+ private String fPattern = null;
+ private Vector fEnumeration = null;
+ private String fMaxInclusive = null;
+ private String fMaxExclusive = null;
+ private String fMinInclusive = null;
+ private String fMinExclusive = null;
+ private int fFacetsDefined = 0;
+ private boolean fDerivedByList = false;//default
+
+ private boolean isMaxExclusiveDefined = false;
+ private boolean isMaxInclusiveDefined = false;
+ private boolean isMinExclusiveDefined = false;
+ private boolean isMinInclusiveDefined = false;
+ private RegularExpression fRegex = null;
+
+
+
+
+ public StringDatatypeValidator () throws InvalidDatatypeFacetException{
+ this( null, null, false ); // Native, No Facets defined, Restriction
+
+ }
+
+ public StringDatatypeValidator ( DatatypeValidator base, Hashtable facets,
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
+
+ setBasetype( base ); // Set base type
+
+ fDerivedByList = derivedByList;
+
+ // Set Facets if any defined
+ //fFacetsDefined = 0;
+ if ( facets != null ){
+ if ( fDerivedByList == false) {
+
+ for (Enumeration e = facets.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+
+ if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
+ fFacetsDefined += DatatypeValidator.FACET_LENGTH;
+ String lengthValue = (String)facets.get(key);
+ try {
+ fLength = Integer.parseInt( lengthValue );
+ } catch (NumberFormatException nfe) {
+ throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
+ }
+ if ( fLength < 0 )
+ throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
- //
- // Constructors
- //
+ } else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
+ fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
+ String minLengthValue = (String)facets.get(key);
+ try {
+ fMinLength = Integer.parseInt( minLengthValue );
+ } catch (NumberFormatException nfe) {
+ throw new InvalidDatatypeFacetException("minLength value '"+minLengthValue+"' is invalid.");
+ }
+ } else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
+ fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
+ String maxLengthValue = (String)facets.get(key);
+ try {
+ fMaxLength = Integer.parseInt( maxLengthValue );
+ } catch (NumberFormatException nfe) {
+ throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
+ }
+ } else if (key.equals(SchemaSymbols.ELT_PATTERN)) {
+ fFacetsDefined += DatatypeValidator.FACET_PATTERN;
+ fPattern = (String)facets.get(key);
+ fRegex = new RegularExpression(fPattern, "X");
+ } else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
+ fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
+ fEnumeration = (Vector)facets.get(key);
+ } else if (key.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
+ fMaxInclusive = (String)facets.get(key);
+ } else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
+ fMaxExclusive = (String)facets.get(key);
+ } else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
+ fMinInclusive = (String)facets.get(key);
+ } else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MINEXCLUSIVE;
+ fMinExclusive = (String)facets.get(key);
+ } else {
+ throw new InvalidDatatypeFacetException("invalid facet tag : " + key);
+ }
+ }
+ if (((fFacetsDefined & DatatypeValidator.FACET_LENGTH ) != 0 ) ) {
+ if (((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH ) != 0 ) ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both length and maxLength to be members of facets." );
+ } else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both length and minLength to be members of facets." );
+ }
+ }
+
+ if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
+ DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
+ if ( fMinLength > fMaxLength ) {
+ throw new InvalidDatatypeFacetException( "Value of minLength = '" + fMinLength +
+ "'must be less than the value of maxLength = '" + fMaxLength + "'.");
+ }
+ }
+
+ isMaxExclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MAXEXCLUSIVE ) != 0 )?true:false;
+ isMaxInclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MAXINCLUSIVE ) != 0 )?true:false;
+ isMinExclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MINEXCLUSIVE ) != 0 )?true:false;
+ isMinInclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MININCLUSIVE ) != 0 )?true:false;
+
+ if ( isMaxExclusiveDefined && isMaxInclusiveDefined ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." );
+ }
+ if ( isMinExclusiveDefined && isMinInclusiveDefined ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both minInclusive and minExclusive to be specified for the same datatype." );
+ }
+ } else { //derived by list
+ for (Enumeration e = facets.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
+ fFacetsDefined += DatatypeValidator.FACET_LENGTH;
+ String lengthValue = (String)facets.get(key);
+ try {
+ fLength = Integer.parseInt( lengthValue );
+ } catch (NumberFormatException nfe) {
+ throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
+ }
+ if ( fLength < 0 )
+ throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
+
+ } else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
+ fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
+ String minLengthValue = (String)facets.get(key);
+ try {
+ fMinLength = Integer.parseInt( minLengthValue );
+ } catch (NumberFormatException nfe) {
+ throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
+ }
+ } else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
+ fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
+ String maxLengthValue = (String)facets.get(key);
+ try {
+ fMaxLength = Integer.parseInt( maxLengthValue );
+ } catch (NumberFormatException nfe) {
+ throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
+ }
+ } else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
+ fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
+ fEnumeration = (Vector)facets.get(key);
+ } else {
+ throw new InvalidDatatypeFacetException("invalid facet tag : " + key);
+ }
+ }
+ if (((fFacetsDefined & DatatypeValidator.FACET_LENGTH ) != 0 ) ) {
+ if (((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH ) != 0 ) ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both length and maxLength to be members of facets." );
+ } else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both length and minLength to be members of facets." );
+ }
+ }
+
+ if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
+ DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
+ if ( fMinLength > fMaxLength ) {
+ throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
+ "must be greater that the value of maxLength" + fMaxLength );
+ }
+ }
+ }
+ }// End of Facets Setting
+ }
+
+
+
+
/**
+ * validate that a string is a W3C string type
*
+ * @param content A string containing the content to be validated
+ * @param list
+ * @exception throws InvalidDatatypeException if the content is
+ * not a W3C string type
+ * @exception InvalidDatatypeValueException
+ */
+ public void validate(String content, Object state) throws InvalidDatatypeValueException
+ {
+ if ( fDerivedByList == false ) {
+ if (fFacetsDefined != 0 )//Any facets to validate
+ checkContent( content, state );
+ } else { //derived by list
+ checkContentList( content, state );
+ }
+ }
+
+
+ /**
+ * set the locate to be used for error messages
+ */
+ public void setLocale(Locale locale) {
+ fLocale = locale;
+ }
+
+
+ /**
*
- * @param base
- * @param facets
- * @param list
+ * @return A Hashtable containing the facets
+ * for this datatype.
*/
- public StringDatatypeValidator(DatatypeValidator base, Hashtable facets, boolean list)
- throws InvalidDatatypeFacetException {
- super(base, facets, list);
+ public Hashtable getFacets(){
+ return null;
}
+
+ private void checkContent( String content, Object state )throws InvalidDatatypeValueException
+ {
+
+ if ( this.fBaseValidator != null ) {//validate against parent type if any
+ this.fBaseValidator.validate( content, state );
+ }
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
+ if ( content.length() > fMaxLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length '"+content.length()+
+ "' exceeds maximum length facet of '"+fMaxLength+"'.");
+ }
+ }
+ if ( (fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
+ if ( content.length() < fMinLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length '"+content.length()+
+ "' is less than minimum length facet of '"+fMinLength+"'." );
+ }
+ }
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0 ) {
+ if ( content.length() != fLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length '"+content.length()+
+ "' is not equal to length facet '"+fLength+"'.");
+ }
+ }
+
+
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
+ if ( fEnumeration.contains( content ) == false )
+ throw new InvalidDatatypeValueException("Value '"+content+"' must be one of "+fEnumeration);
+ }
+
+ if ( isMaxExclusiveDefined == true ) {
+ int comparisonResult;
+ comparisonResult = compare( content, fMaxExclusive );
+ if ( comparisonResult >= 0 ) {
+ throw new InvalidDatatypeValueException( "MaxExclusive:Value '"+content+ "' must be " +
+ "lexicographically less than" + fMaxExclusive );
+
+ }
+
+ }
+ if ( isMaxInclusiveDefined == true ) {
+ int comparisonResult;
+ comparisonResult = compare( content, fMaxInclusive );
+ if ( comparisonResult > 0 )
+ throw new InvalidDatatypeValueException( "MaxInclusive:Value '"+content+ "' must be " +
+ "lexicographically less or equal than" + fMaxInclusive );
+ }
+
+ if ( isMinExclusiveDefined == true ) {
+ int comparisonResult;
+ comparisonResult = compare( content, fMinExclusive );
+
+ //System.out.println( "exclusive = " + comparisonResult );
+
+ if ( comparisonResult <= 0 )
+ throw new InvalidDatatypeValueException( "MinExclusive:Value '"+content+ "' must be " +
+ "lexicographically greater than" + fMinExclusive );
+ }
+ if ( isMinInclusiveDefined == true ) {
+ int comparisonResult;
+ comparisonResult = compare( content, fMinInclusive );
+ //System.out.println( "inclusive = " + comparisonResult );
+ if ( comparisonResult < 0 )
+ throw new InvalidDatatypeValueException( "MinInclusive:Value '"+content+ "' must be " +
+ "lexicographically greater or equal than '" + fMinInclusive + "'." );
+ }
+
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
+ //RegularExpression regex = new RegularExpression(fPattern );
+ if ( fRegex == null || fRegex.matches( content) == false )
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' does not match regular expression facet '" + fPattern + "'." );
+ }
+
+ }
+ public int compare( String content, String facetValue ){
+ Locale loc = Locale.getDefault();
+ Collator collator = Collator.getInstance( loc );
+ return collator.compare( content, facetValue );
+ }
+
+ /**
+ * Returns a copy of this object.
+ */
+ public Object clone() throws CloneNotSupportedException {
+ StringDatatypeValidator newObj = null;
+ try {
+ newObj = new StringDatatypeValidator();
+
+ newObj.fLocale = this.fLocale;
+ newObj.fBaseValidator = this.fBaseValidator;
+ newObj.fLength = this.fLength;
+ newObj.fMaxLength = this.fMaxLength;
+ newObj.fMinLength = this.fMinLength;
+ newObj.fPattern = this.fPattern;
+ newObj.fEnumeration = this.fEnumeration;
+ newObj.fMaxInclusive = this.fMaxInclusive;
+ newObj.fMaxExclusive = this.fMaxExclusive;
+ newObj.fMinInclusive = this.fMinInclusive;
+ newObj.fMinExclusive = this.fMinExclusive;
+ newObj.fFacetsDefined = this.fFacetsDefined;
+ newObj.fDerivedByList = this.fDerivedByList;
+ newObj.isMaxExclusiveDefined = this.isMaxExclusiveDefined;
+ newObj.isMaxInclusiveDefined = this.isMaxInclusiveDefined;
+ newObj.isMinExclusiveDefined = this.isMinExclusiveDefined;
+ newObj.isMinInclusiveDefined = this.isMinInclusiveDefined;
+ } catch ( InvalidDatatypeFacetException ex) {
+ ex.printStackTrace();
+ }
+ return newObj;
+ }
+
+ // Private methods
+ private void checkContentList( String content, Object state )throws InvalidDatatypeValueException
+ {
+ StringTokenizer parsedList = new StringTokenizer( content );
+ try {
+ int numberOfTokens = parsedList.countTokens();
+ if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
+ if ( numberOfTokens > fMaxLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length ='"+ numberOfTokens + "'tokens"+
+ "' exceeds maximum length facet with '"+fMaxLength+"' tokens.");
+ }
+ }
+ if ( (fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
+ if ( numberOfTokens < fMinLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length ='"+ numberOfTokens+ "'tokens" +
+ "' is less than minimum length facet with '"+fMinLength+"' tokens." );
+ }
+ }
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0 ) {
+ if ( numberOfTokens != fLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length ='"+ numberOfTokens+ "'tokens" +
+ "' is not equal to length facet with '"+fLength+"'. tokens");
+ }
+ }
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
+ if ( fEnumeration.contains( content ) == false )
+ throw new InvalidDatatypeValueException("Value '"+
+ content+"' must be one of "+fEnumeration);
+ }
+ while ( parsedList.hasMoreTokens() ) { //Check actual list content
+ if ( this.fBaseValidator != null ) {//validate against parent type if any
+ this.fBaseValidator.validate( parsedList.nextToken(), state );
+ }
+ }
+ } catch ( NoSuchElementException e ) {
+ e.printStackTrace();
+ }
+ }
+
+ private void setBasetype( DatatypeValidator base) {
+ fBaseValidator = base;
+ }
+
+}
-} // class StringDatatypeValidator
No revision
No revision
1.1.2.1 +236 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/BinaryDatatypeValidator.java
1.1.2.1 +216 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/BooleanDatatypeValidator.java
1.1.2.1 +617 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/DecimalDatatypeValidator.java
1.1.2.1 +379 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/DoubleDatatypeValidator.java
1.1.2.1 +262 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/ENTITYDatatypeValidator.java
1.1.2.1 +409 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/FloatDatatypeValidator.java
1.1.2.1 +163 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/HexBin.java
1.1.2.1 +230 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/IDDatatypeValidator.java
1.1.2.1 +311 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/IDREFDatatypeValidator.java
1.1.2.1 +159 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/NOTATIONDatatypeValidator.java
1.1.2.1 +410 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/QNameDatatypeValidator.java
1.1.2.1 +214 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/RecurringDurationDatatypeValidator.java
1.1.2.1 +238 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/TimeDurationDatatypeValidator.java
1.1.2.1 +323 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/URIReferenceDatatypeValidator.java