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/11/03 02:34:26 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes StatefullDatatypeValidator.java DatatypeValidatorFactoryImpl.java ENTITYDatatypeValidator.java IDDatatypeValidator.java IDREFDatatypeValidator.java ListDatatypeValidator.java Makefile NOTATIONDatatypeValidator.java QNameDatatypeValidator.java
jeffreyr 00/11/02 17:34:25
Modified: java/src/org/apache/xerces/impl Tag: xerces_j_2
XMLValidator.java
java/src/org/apache/xerces/impl/validation/datatypes Tag:
xerces_j_2 DatatypeValidatorFactoryImpl.java
ENTITYDatatypeValidator.java
IDDatatypeValidator.java
IDREFDatatypeValidator.java
ListDatatypeValidator.java Makefile
NOTATIONDatatypeValidator.java
QNameDatatypeValidator.java
Added: java/src/org/apache/xerces/impl/validation/datatypes Tag:
xerces_j_2 StatefullDatatypeValidator.java
Log:
connecting statefull validator/attribute validators plus some other upgrades
Revision Changes Path
No revision
No revision
1.1.2.22 +57 -2 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLValidator.java
Index: XMLValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLValidator.java,v
retrieving revision 1.1.2.21
retrieving revision 1.1.2.22
diff -u -r1.1.2.21 -r1.1.2.22
--- XMLValidator.java 2000/11/02 21:22:54 1.1.2.21
+++ XMLValidator.java 2000/11/03 01:34:11 1.1.2.22
@@ -80,6 +80,17 @@
import org.apache.xerces.xni.XMLDTDContentModelFilter;
import org.apache.xerces.xni.XMLDTDContentModelHandler;
+import org.apache.xerces.impl.validation.DatatypeValidator;
+import org.apache.xerces.impl.validation.datatypes.DatatypeValidatorFactoryImpl;
+import org.apache.xerces.impl.validation.datatypes.ENTITYDatatypeValidator;
+import org.apache.xerces.impl.validation.datatypes.IDDatatypeValidator;
+import org.apache.xerces.impl.validation.datatypes.IDREFDatatypeValidator;
+import org.apache.xerces.impl.validation.datatypes.ListDatatypeValidator;
+import org.apache.xerces.impl.validation.InvalidDatatypeFacetException;
+import org.apache.xerces.impl.validation.InvalidDatatypeValueException;
+
+
+
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@@ -89,7 +100,7 @@
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
* @author Andy Clark, IBM
*
- * @version $Id: XMLValidator.java,v 1.1.2.21 2000/11/02 21:22:54 ericye Exp $
+ * @version $Id: XMLValidator.java,v 1.1.2.22 2000/11/03 01:34:11 jeffreyr Exp $
*/
public class XMLValidator
implements XMLComponent,
@@ -208,6 +219,23 @@
private String fFIXEDSymbol ;
private String fDATATYPESymbol ;
+
+ /** Datatype Registry and attribute validators */
+
+ private DatatypeValidatorFactoryImpl fDataTypeReg;
+ private IDDatatypeValidator fValID;
+ private IDREFDatatypeValidator fValIDRef;
+ private ListDatatypeValidator fValIDRefs;
+ private ENTITYDatatypeValidator fValENTITY;
+ private ListDatatypeValidator fValENTITIES;
+ /*
+ private DatatypeValidator fValNMTOKEN;
+ private DatatypeValidator fValNMTOKENS;
+ private DatatypeValidator fValNOTATION;
+ */
+
+
+
/** DEBUG flags */
private boolean DEBUG_ATTRIBUTES;
private boolean DEBUG_ELEMENT_CHILDREN;
@@ -231,7 +259,7 @@
*
* @param componentManager The component manager.
*
- * @throws SAXException Thrown by component on initialization error.
+ * @throws SAXException Thrown by component on finitialization error.
* For example, if a feature or property is
* required for the operation of the component, the
* component manager may throw a
@@ -1991,6 +2019,33 @@
fREQUIREDSymbol = fSymbolTable.addSymbol("#REQUIRED");
fFIXEDSymbol = fSymbolTable.addSymbol("#FIXED");
fDATATYPESymbol = fSymbolTable.addSymbol("<<datatype>>");
+
+ //Initialize Validators
+ //Datatype Registry
+
+ fDataTypeReg =
+ DatatypeValidatorFactoryImpl.getDatatypeRegistry();
+ fDataTypeReg.resetRegistry();
+
+ fValID = (IDDatatypeValidator) fDataTypeReg.getDatatypeValidator("ID" );
+ fValIDRef = (IDREFDatatypeValidator) fDataTypeReg.getDatatypeValidator("IDREF" );
+ fValIDRefs = (ListDatatypeValidator) fDataTypeReg.getDatatypeValidator("IDREFS" );
+ fValENTITY = (ENTITYDatatypeValidator) fDataTypeReg.getDatatypeValidator("ENTITY" );
+ fValENTITIES = (ListDatatypeValidator) fDataTypeReg.getDatatypeValidator("ENTITIES" );
+ /*
+ fValNMTOKEN = fDataTypeReg.getDatatypeValidator("NMTOKEN");
+ fValNMTOKENS = fDataTypeReg.getDatatypeValidator("NMTOKENS");
+ fValNOTATION = fDataTypeReg.getDatatypeValidator("NOTATION" );
+ */
+
+
+ //Initialize ENTITY & ENTITIES Validatorh
+
+ fValID.initialize(null);
+ fValIDRef.initialize( fValID.getInternalStateInformation() );
+ fValENTITY.initialize(fCurrentGrammar);
+ fValENTITIES.initialize(fCurrentGrammar);
+
}
/** ensure element stack capacity */
No revision
No revision
1.1.2.9 +4 -4 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.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- DatatypeValidatorFactoryImpl.java 2000/10/31 22:49:00 1.1.2.8
+++ DatatypeValidatorFactoryImpl.java 2000/11/03 01:34:16 1.1.2.9
@@ -84,7 +84,7 @@
* method to get a validator.
*
* @author Jeffrey Rodriguez
- * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.1.2.8 2000/10/31 22:49:00 jeffreyr Exp $
+ * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.1.2.9 2000/11/03 01:34:16 jeffreyr Exp $
*/
public class DatatypeValidatorFactoryImpl implements DatatypeValidatorFactory {
private static final boolean fDebug = false;
@@ -431,14 +431,14 @@
DatatypeValidator idData = tstRegistry.getDatatypeValidator( "ID" );
if ( idData != null ) {
- ((IDDatatypeValidator) idData).initialize();
+ ((IDDatatypeValidator) idData).initialize(null);
try {
idData.validate( "a1", null );
idData.validate( "a2", null );
} catch ( Exception ex ) {
ex.printStackTrace();
}
- Hashtable tst = (Hashtable)((IDDatatypeValidator) idData).getTableIds();
+ Hashtable tst = (Hashtable)((IDDatatypeValidator) idData).getInternalStateInformation();
if (tst != null) {
System.out.println("Table of ID = " + tst.toString());
}
@@ -455,7 +455,7 @@
DatatypeValidator idRefData = tstRegistry.getDatatypeValidator("IDREF" );
if( idRefData != null ){
IDREFDatatypeValidator refData = (IDREFDatatypeValidator) idRefData;
- refData.initialize( ((IDDatatypeValidator) idData).getTableIds());
+ refData.initialize( ((IDDatatypeValidator) idData).getInternalStateInformation());
try {
refData.validate( "a1", null );
refData.validate( "a2", null );
1.1.2.5 +104 -88 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/ENTITYDatatypeValidator.java
Index: ENTITYDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/ENTITYDatatypeValidator.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- ENTITYDatatypeValidator.java 2000/11/01 03:03:55 1.1.2.4
+++ ENTITYDatatypeValidator.java 2000/11/03 01:34:17 1.1.2.5
@@ -90,110 +90,126 @@
* able to validate entities.</P>
*
* @author Jeffrey Rodriguez-
- * @version $Id: ENTITYDatatypeValidator.java,v 1.1.2.4 2000/11/01 03:03:55 jeffreyr Exp $
+ * @version $Id: ENTITYDatatypeValidator.java,v 1.1.2.5 2000/11/03 01:34:17 jeffreyr Exp $
* @see org.apache.xerces.impl.validation.Grammar
* @see org.apache.xerces.impl.validation.grammars.DTDGrammar
* @see org.apache.xerces.impl.validation.grammars.SchemaGrammar
*/
-public class ENTITYDatatypeValidator extends AbstractDatatypeValidator {
- private DatatypeValidator fBaseValidator = null;
- private Grammar fGrammar = null;
- private XMLEntityDecl fEntityDecl = new XMLEntityDecl();
-
- public ENTITYDatatypeValidator () throws InvalidDatatypeFacetException {
- this( null, null, false ); // Native, No Facets defined, Restriction
- }
-
- public ENTITYDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
- setBasetype( base ); // Set base type
- }
+public class ENTITYDatatypeValidator extends AbstractDatatypeValidator
+implements StatefullDatatypeValidator {
+ private DatatypeValidator fBaseValidator = null;
+ private Grammar fGrammar = null;
+ private XMLEntityDecl fEntityDecl = new XMLEntityDecl();
+
+ public ENTITYDatatypeValidator () throws InvalidDatatypeFacetException {
+ this( null, null, false ); // Native, No Facets defined, Restriction
+ }
+
+ public ENTITYDatatypeValidator ( DatatypeValidator base, Hashtable facets,
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
+ setBasetype( base ); // Set base type
+ }
+
+
+ /**
+ * <P>Checks that "content" string is valid
+ * datatype.
+ * If invalid a Datatype validation exception is thrown.</P>
+ * <P>The following constrain is checked:
+ * ENTITY values must match an unparsed entity
+ * name that is declared in the schema.</P>
+ *
+ * @param content A string containing the content to be validated
+ * @param state
+ * @exception throws InvalidDatatypeException if the content is
+ * invalid according to the rules for the validators
+ * @exception InvalidDatatypeValueException
+ * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
+ */
+ public void validate(String content, Object state ) throws InvalidDatatypeValueException{
+ int entityDeclIndex = -1;
+ if (fGrammar == null) {
+ InvalidDatatypeValueException error =
+ new InvalidDatatypeValueException( "ERROR: ENTITYDatatype Validator: Failed Need to call initialize method with a valid Grammar reference" );//Need Message
+ throw error;
+ }
+ fEntityDecl.clear();//Reset Entity Decl struct
- /**
- * <P>Checks that "content" string is valid
- * datatype.
- * If invalid a Datatype validation exception is thrown.</P>
- * <P>The following constrain is checked:
- * ENTITY values must match an unparsed entity
- * name that is declared in the schema.</P>
- *
- * @param content A string containing the content to be validated
- * @param state
- * @exception throws InvalidDatatypeException if the content is
- * invalid according to the rules for the validators
- * @exception InvalidDatatypeValueException
- * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
- */
- public void validate(String content, Object state ) throws InvalidDatatypeValueException{
- int entityDeclIndex = -1;
- if ( fGrammar == null ) {
- InvalidDatatypeValueException error =
- new InvalidDatatypeValueException( "ERROR: ENTITYDatatype Validator: Failed Need to call initialize method with a valid Grammar reference" );//Need Message
- throw error;
- }
-
- fEntityDecl.clear();//Reset Entity Decl struct
-
- entityDeclIndex = fGrammar.getEntityDeclIndex( content );
-
- if ( entityDeclIndex == -1 ) {
- fGrammar.getEntityDecl( entityDeclIndex, fEntityDecl );
- if ( fEntityDecl.notation != null ) {// not unparsed entity
+ entityDeclIndex = fGrammar.getEntityDeclIndex( content );
+
+ if (entityDeclIndex == -1) {
+ fGrammar.getEntityDecl( entityDeclIndex, fEntityDecl );
+ if (fEntityDecl.notation != null) {// not unparsed entity
+ InvalidDatatypeValueException error =
+ new InvalidDatatypeValueException( "ENTITY '"+ content +"' is not unparsed" );
+ throw error;
+ }
+ } else {
InvalidDatatypeValueException error =
- new InvalidDatatypeValueException( "ENTITY '"+ content +"' is not unparsed" );
+ new InvalidDatatypeValueException( "ENTITY '"+ content +"' is not valid" );
throw error;
- }
- } else {
- InvalidDatatypeValueException error =
- new InvalidDatatypeValueException( "ENTITY '"+ content +"' is not valid" );
- throw error;
- }
- }
+ }
+ }
- /**
- * <P>Initializes internal Grammar reference
- * This method is unique to ENTITYDatatypeValidator.</P>
- * <P>This method should be called before calling the
- * validate method</P>
- *
- * @param grammar
- */
- public void initialize( Grammar grammar ){
- fGrammar = grammar;
- }
+ /**
+ * A no-op method in this Datatype
+ */
+ public void validate(){
+ }
- /**
- * REVISIT
- * Compares two Datatype for order
- *
- * @return
- */
- public int compare( String content1, String content2){
- return -1;
- }
-
- public Hashtable getFacets(){
- return null;
- }
- // Private methods start here
- /**
- * Returns a copy of this object.
- */
- public Object clone() throws CloneNotSupportedException {
- throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
- }
+ /**
+ * <P>Initializes internal Grammar reference
+ * This method is unique to ENTITYDatatypeValidator.</P>
+ * <P>This method should be called before calling the
+ * validate method</P>
+ *
+ * @param grammar
+ */
+ public void initialize( Object grammar ) {
+ fGrammar = (Grammar) grammar;
+ }
+
+ /**
+ * REVISIT
+ * Compares two Datatype for order
+ *
+ * @return
+ */
+ public int compare( String content1, String content2) {
+ return -1;
+ }
+
+ public Hashtable getFacets() {
+ return null;
+ }
+
+ // Private methods start here
+
+ /**
+ * Returns a copy of this object.
+ */
+ public Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
+ }
/**
- *
- * @param base the validator for this type's base type
+ * A no-op method in this validator
*/
- private void setBasetype(DatatypeValidator base){
- fBaseValidator = base;
- }
+ public Object getInternalStateInformation() {
+ return null;
+ }
+
+ /**
+ *
+ * @param base the validator for this type's base type
+ */
+ private void setBasetype(DatatypeValidator base) {
+ fBaseValidator = base;
+ }
1.1.2.6 +161 -151 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/IDDatatypeValidator.java
Index: IDDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/IDDatatypeValidator.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- IDDatatypeValidator.java 2000/10/31 18:49:15 1.1.2.5
+++ IDDatatypeValidator.java 2000/11/03 01:34:19 1.1.2.6
@@ -126,161 +126,171 @@
* </CODE>
*
* @author Jeffrey Rodriguez
- * @version $Id: IDDatatypeValidator.java,v 1.1.2.5 2000/10/31 18:49:15 jeffreyr Exp $
+ * @version $Id: IDDatatypeValidator.java,v 1.1.2.6 2000/11/03 01:34:19 jeffreyr Exp $
* @see org.apache.xerces.impl.validation.datatypes.AbstractDatatypeValidator
* @see org.apache.xerces.impl.validation.DatatypeValidator
* @see org.apache.xerces.impl.validation.datatypes.IDREFDatatypeValidator
*/
-public class IDDatatypeValidator extends AbstractDatatypeValidator {
- private DatatypeValidator fBaseValidator;
- private Object fNullValue;
- private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
- private Hashtable fTableOfId;
- private Locale fLocale;
-
-
-
- public IDDatatypeValidator () throws InvalidDatatypeFacetException {
- this( null, null, false ); // Native, No Facets defined, Restriction
- }
-
- public IDDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
- }
-
-
-
- /**
- * Checks that "content" string is valid
- * datatype.
- * If invalid a Datatype validation exception is thrown.
- *
- * @param content A string containing the content to be validated
- * @param state Generic Object state that can be use to pass
- * Structures
- * @return
- * @exception throws InvalidDatatypeException if the content is
- * invalid according to the rules for the validators
- * @exception InvalidDatatypeValueException
- * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
- */
- public void validate(String content, Object state ) throws InvalidDatatypeValueException{
-
- if (!XMLChar.isValidName(content) == true) {//Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
- InvalidDatatypeValueException error = new
- InvalidDatatypeValueException( "ID is not valid: " + content );
- throw error;
- }
- if (!addId( content) ) { //It is OK to pass a null here
- InvalidDatatypeValueException error =
- new InvalidDatatypeValueException( "ID '" + content +"' has to be unique" );
- throw error;
- }
- }
-
- /**
- * Initializes internal table of IDs used
- * by ID datatype validator to keep track
- * of ID's.
- * This method is unique to IDDatatypeValidator.
- */
- public void initialize(){
- if ( this.fTableOfId != null) {
- this.fTableOfId.clear();
- } else {
- this.fTableOfId = new Hashtable();
- }
- }
-
- /**
- * REVISIT
- * Compares two Datatype for order
- *
- * @param o1
- * @param o2
- * @return
- */
- public int compare( String content1, String content2){
- return -1;
- }
-
- public Hashtable getFacets(){
- return null;
- }
-
- /**
- * Return a copy of this object.
- */
- public Object clone() throws CloneNotSupportedException {
- throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
- }
-
- /**
- * This method is unique to IDDatatypeValidator.
- * It returns a reference to the internal ID table.
- * This method should be used by the IDREF datatype
- * validator which needs read access to ID table.
- *
- * @return
- */
- public Object getTableIds(){
- return fTableOfId;
- }
-
-
- /**
- * Name of base type as a string.
- * A Native datatype has the string "native" as its
- * base type.
- *
- * @param base the validator for this type's base type
- */
- private void setBasetype(DatatypeValidator base){
- fBaseValidator = base;
- }
-
- /**
- * Adds validated ID to internal table of ID's.
- * We check ID uniqueness constraint.
- *
- * @param content
- * @return If ID validated is not unique we return a false and
- * then validate method throws a validation exception.
- */
- private boolean addId(String content) {
- //System.out.println("Added ID = " + content );
- if ( fTableOfId == null ) {
- fTableOfId = new Hashtable();//Gain reference to table
- } else if ( this.fTableOfId.containsKey( content ) ) {
- //System.out.println("ID - it already has this key =" + content +"table = " + this.fTableOfId );
- return false;
- }
- if ( this.fNullValue == null ) {
- fNullValue = new Object();
- }
- //System.out.println("Before putting content" + content );
- try {
- fTableOfId.put( content, fNullValue );
- } catch ( Exception ex ) {
- ex.printStackTrace();
- }
- return true;
- } // addId(int):boolean
-
-
-
- /**
- * set the locate to be used for error messages
- */
- public void setLocale(Locale locale) {
- fLocale = locale;
- }
-
-
- private String getErrorString(int major, int minor, Object args[]) {
- //return fMessageProvider.createMessage(fLocale, major, minor, args);
- return fMessageProvider.formatMessage(fLocale, null, null );
- }
+public class IDDatatypeValidator extends AbstractDatatypeValidator
+implements StatefullDatatypeValidator {
+ private DatatypeValidator fBaseValidator;
+ private Object fNullValue;
+ private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
+ private Hashtable fTableOfId;
+ private Locale fLocale;
+
+
+
+ public IDDatatypeValidator () throws InvalidDatatypeFacetException {
+ this( null, null, false ); // Native, No Facets defined, Restriction
+ }
+
+ public IDDatatypeValidator ( DatatypeValidator base, Hashtable facets,
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
+ }
+
+
+
+ /**
+ * Checks that "content" string is valid
+ * datatype.
+ * If invalid a Datatype validation exception is thrown.
+ *
+ * @param content A string containing the content to be validated
+ * @param state Generic Object state that can be use to pass
+ * Structures
+ * @return
+ * @exception throws InvalidDatatypeException if the content is
+ * invalid according to the rules for the validators
+ * @exception InvalidDatatypeValueException
+ * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
+ */
+ public void validate(String content, Object state ) throws InvalidDatatypeValueException{
+
+ if (!XMLChar.isValidName(content) == true) {//Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
+ InvalidDatatypeValueException error = new
+ InvalidDatatypeValueException( "ID is not valid: " + content );
+ throw error;
+ }
+ if (!addId( content)) { //It is OK to pass a null here
+ InvalidDatatypeValueException error =
+ new InvalidDatatypeValueException( "ID '" + content +"' has to be unique" );
+ throw error;
+ }
+ }
+
+ /**
+ * A no-op method in this Datatype
+ */
+ public void validate() throws InvalidDatatypeValueException{
+ }
+
+
+ /**
+ * Initializes internal table of IDs used
+ * by ID datatype validator to keep track
+ * of ID's.
+ * This method is unique to IDDatatypeValidator.
+ *
+ * @param state This is a dummy parameter.
+ */
+ public void initialize( Object state) {
+ if (this.fTableOfId != null) {
+ this.fTableOfId.clear();
+ } else {
+ this.fTableOfId = new Hashtable();
+ }
+ }
+
+ /**
+ * REVISIT
+ * Compares two Datatype for order
+ *
+ * @param o1
+ * @param o2
+ * @return
+ */
+ public int compare( String content1, String content2) {
+ return -1;
+ }
+
+ public Hashtable getFacets() {
+ return null;
+ }
+
+ /**
+ * Return a copy of this object.
+ */
+ public Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
+ }
+
+ /**
+ * This method is unique to IDDatatypeValidator.
+ * It returns a reference to the internal ID table.
+ * This method should be used by the IDREF datatype
+ * validator which needs read access to ID table.
+ *
+ * @return
+ */
+ public Object getInternalStateInformation() {
+ return fTableOfId;
+ }
+
+
+ /**
+ * Name of base type as a string.
+ * A Native datatype has the string "native" as its
+ * base type.
+ *
+ * @param base the validator for this type's base type
+ */
+ private void setBasetype(DatatypeValidator base) {
+ fBaseValidator = base;
+ }
+
+ /**
+ * Adds validated ID to internal table of ID's.
+ * We check ID uniqueness constraint.
+ *
+ * @param content
+ * @return If ID validated is not unique we return a false and
+ * then validate method throws a validation exception.
+ */
+ private boolean addId(String content) {
+ //System.out.println("Added ID = " + content );
+ if (fTableOfId == null) {
+ fTableOfId = new Hashtable();//Gain reference to table
+ } else if (this.fTableOfId.containsKey( content )) {
+ //System.out.println("ID - it already has this key =" + content +"table = " + this.fTableOfId );
+ return false;
+ }
+ if (this.fNullValue == null) {
+ fNullValue = new Object();
+ }
+ //System.out.println("Before putting content" + content );
+ try {
+ fTableOfId.put( content, fNullValue );
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return true;
+ } // addId(int):boolean
+
+
+
+ /**
+ * set the locate to be used for error messages
+ */
+ public void setLocale(Locale locale) {
+ fLocale = locale;
+ }
+
+
+ private String getErrorString(int major, int minor, Object args[]) {
+ //return fMessageProvider.createMessage(fLocale, major, minor, args);
+ return fMessageProvider.formatMessage(fLocale, null, null );
+ }
}
1.1.2.5 +10 -2 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/IDREFDatatypeValidator.java
Index: IDREFDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/IDREFDatatypeValidator.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- IDREFDatatypeValidator.java 2000/10/31 20:08:36 1.1.2.4
+++ IDREFDatatypeValidator.java 2000/11/03 01:34:19 1.1.2.5
@@ -104,12 +104,13 @@
* </CODE>
*
* @author Jeffrey Rodriguez-
- * @version $Id: IDREFDatatypeValidator.java,v 1.1.2.4 2000/10/31 20:08:36 jeffreyr Exp $
+ * @version $Id: IDREFDatatypeValidator.java,v 1.1.2.5 2000/11/03 01:34:19 jeffreyr Exp $
* @see org.apache.xerces.impl.validation.datatypes.IDDatatypeValidator
* @see org.apache.xerces.impl.validation.datatypes.AbstractDatatypeValidator
* @see org.apache.xerces.impl.validation.DatatypeValidator
*/
-public class IDREFDatatypeValidator extends AbstractDatatypeValidator {
+public class IDREFDatatypeValidator extends AbstractDatatypeValidator
+implements StatefullDatatypeValidator{
private DatatypeValidator fBaseValidator = null;
private Hashtable fTableOfId = null; //This is pass to us through the state object
private Hashtable fTableIDRefs = null;
@@ -290,6 +291,13 @@
*/
public void setLocale(Locale locale) {
fLocale = locale;
+ }
+
+ /**
+ * A no-op method in this validator
+ */
+ public Object getInternalStateInformation(){
+ return null;
}
private String getErrorString(int major, int minor, Object args[]) {
1.1.2.2 +76 -35 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/ListDatatypeValidator.java
Index: ListDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/ListDatatypeValidator.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- ListDatatypeValidator.java 2000/10/17 02:01:04 1.1.2.1
+++ ListDatatypeValidator.java 2000/11/03 01:34:20 1.1.2.2
@@ -76,7 +76,8 @@
/**
* StringValidator validates that XML content is a W3C string type.
*/
-public class ListDatatypeValidator extends AbstractDatatypeValidator{
+public class ListDatatypeValidator extends AbstractDatatypeValidator
+implements StatefullDatatypeValidator {
private Locale fLocale = null;
DatatypeValidator fBaseValidator = null; // Native datatypes have null
@@ -99,16 +100,16 @@
}
public ListDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
fDerivedByList = derivedByList;
- if ( facets != null ){
+ if (facets != null) {
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
- if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
+ if (key.equals(SchemaSymbols.ELT_LENGTH)) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
@@ -116,10 +117,10 @@
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
- if ( fLength < 0 )
+ if (fLength < 0)
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
- } else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
+ } else if (key.equals(SchemaSymbols.ELT_MINLENGTH)) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
@@ -127,7 +128,7 @@
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
- } else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
+ } else if (key.equals(SchemaSymbols.ELT_MAXLENGTH)) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
@@ -142,21 +143,21 @@
throw new InvalidDatatypeFacetException("invalid facet tag : " + key);
}
}
- if (((fFacetsDefined & DatatypeValidator.FACET_LENGTH ) != 0 ) ) {
- if (((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH ) != 0 ) ) {
+ 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 ) ) {
+ "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." );
+ "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 ) {
+ 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 );
+ "must be greater that the value of maxLength" + fMaxLength );
}
}
}// End of Facets Setting
@@ -193,11 +194,11 @@
* @return A Hashtable containing the facets
* for this datatype.
*/
- public Hashtable getFacets(){
+ public Hashtable getFacets() {
return null;
}
- public int compare( String content, String facetValue ){
+ public int compare( String content, String facetValue ) {
// if derive by list then this should iterate through
// the tokens in each string and compare using the base type
// compare function.
@@ -223,7 +224,7 @@
newObj.fEnumeration = this.fEnumeration;
newObj.fFacetsDefined = this.fFacetsDefined;
newObj.fDerivedByList = this.fDerivedByList;
- } catch ( InvalidDatatypeFacetException ex) {
+ } catch (InvalidDatatypeFacetException ex) {
ex.printStackTrace();
}
return newObj;
@@ -235,51 +236,50 @@
StringTokenizer parsedList = new StringTokenizer( content );
try {
int numberOfTokens = parsedList.countTokens();
- if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
- if ( numberOfTokens > fMaxLength ) {
+ if ((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0) {
+ if (numberOfTokens > fMaxLength) {
throw new InvalidDatatypeValueException("Value '"+content+
"' with length ='"+ numberOfTokens + "' tokens"+
"' exceeds maximum length facet of '"+fMaxLength+"' tokens.");
}
}
- if ( (fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
- if ( numberOfTokens < fMinLength ) {
+ if ((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0) {
+ if (numberOfTokens < fMinLength) {
throw new InvalidDatatypeValueException("Value '"+content+
"' with length ='"+ numberOfTokens+ "' tokens" +
"' is less than minimum length facet of '"+fMinLength+"' tokens." );
}
}
- if ( (fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0 ) {
- if ( numberOfTokens != fLength ) {
+ if ((fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0) {
+ if (numberOfTokens != fLength) {
throw new InvalidDatatypeValueException("Value '"+content+
"' with length ='"+ numberOfTokens+ "' tokens" +
"' is not equal to length facet of '"+fLength+"' tokens.");
}
}
- if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
+ if ((fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0) {
// Enumerations are defined in the value space so the contains method
// of vector doesn't really do the right thing, we really should check using compare
- if ( fEnumeration.contains( content ) == false )
+ if (fEnumeration.contains( content ) == false)
throw new InvalidDatatypeValueException("Value '"+
content+"' must be one of "+fEnumeration);
}
-
+
if (this.fDerivedByList) {
- while ( parsedList.hasMoreTokens() ) { //Check each token in list against base type
- if ( this.fBaseValidator != null ) {//validate against parent type if any
+ while (parsedList.hasMoreTokens()) { //Check each token in list against base type
+ if (this.fBaseValidator != null) {//validate against parent type if any
this.fBaseValidator.validate( parsedList.nextToken(), state );
}
}
- }
- else {
- if ( this.fBaseValidator != null ) {//validate against parent type if any
+ } else {
+ if (this.fBaseValidator != null) {//validate against parent type if any
this.fBaseValidator.validate( content, state );
}
}
-
- } catch ( NoSuchElementException e ) {
+
+ } catch (NoSuchElementException e) {
e.printStackTrace();
}
}
@@ -287,6 +287,47 @@
private void setBasetype( DatatypeValidator base) {
fBaseValidator = base;
}
+
+ /**
+ * <P>Initializes the internal datattype state with documentInstance state information</P>
+ * <P>This method should be called before calling the
+ * validate method</P>
+ *
+ * @param documentInstanceState
+ */
+ public void initialize( Object documentInstanceState ) {
+ if (fBaseValidator instanceof StatefullDatatypeValidator ){
+ ((StatefullDatatypeValidator)fBaseValidator).initialize( documentInstanceState );
+ }
+ }
+
+ /**
+ * <P>Initializes the internal datatype state
+ */
+
+ public void validate()throws InvalidDatatypeValueException {
+ if ((fBaseValidator instanceof
+ org.apache.xerces.impl.validation.datatypes.IDREFDatatypeValidator )) {
+ ((StatefullDatatypeValidator)fBaseValidator).validate();
+ }
+
+ }
+ /**
+ * <P>This method returns some internal state of a statefull validator</P>
+ * It returns a reference to the internal state
+ *
+ * @return Object
+ */
+ public Object getInternalStateInformation() {
+ Object value = null;
+ if (fBaseValidator instanceof
+ org.apache.xerces.impl.validation.datatypes.IDDatatypeValidator ) {
+ value = ((StatefullDatatypeValidator)fBaseValidator).getInternalStateInformation();
+ }
+ return value;
+ }
+
+
}
1.1.2.5 +1 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/Makefile,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- Makefile 2000/10/28 00:13:37 1.1.2.4
+++ Makefile 2000/11/03 01:34:20 1.1.2.5
@@ -21,6 +21,7 @@
UnionDatatypeValidator.class \
URIReferenceDatatypeValidator.class \
RecurringDurationDatatypeValidator.class\
+ StatefullDatatypeValidator.class\
TimeDurationDatatypeValidator.class\
DatatypeValidatorFactoryImpl.class
1.1.2.3 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/NOTATIONDatatypeValidator.java
Index: NOTATIONDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/NOTATIONDatatypeValidator.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- NOTATIONDatatypeValidator.java 2000/10/17 02:01:04 1.1.2.2
+++ NOTATIONDatatypeValidator.java 2000/11/03 01:34:20 1.1.2.3
@@ -77,9 +77,9 @@
* standalone code as well as plugins to the validator architecture.
*
* @author Jeffrey Rodriguez-
- * @version $Id: NOTATIONDatatypeValidator.java,v 1.1.2.2 2000/10/17 02:01:04 jeffreyr Exp $
+ * @version $Id: NOTATIONDatatypeValidator.java,v 1.1.2.3 2000/11/03 01:34:20 jeffreyr Exp $
*/
-public class NOTATIONDatatypeValidator extends AbstractDatatypeValidator {
+ public class NOTATIONDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
public NOTATIONDatatypeValidator () throws InvalidDatatypeFacetException {
1.1.2.3 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/QNameDatatypeValidator.java
Index: QNameDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/QNameDatatypeValidator.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- QNameDatatypeValidator.java 2000/10/17 02:01:05 1.1.2.2
+++ QNameDatatypeValidator.java 2000/11/03 01:34:21 1.1.2.3
@@ -83,7 +83,7 @@
* XML].
*
* @author Jeffrey Rodriguez
- * @version $Id: QNameDatatypeValidator.java,v 1.1.2.2 2000/10/17 02:01:05 jeffreyr Exp $
+ * @version $Id: QNameDatatypeValidator.java,v 1.1.2.3 2000/11/03 01:34:21 jeffreyr Exp $
*/
public class QNameDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
@@ -297,7 +297,7 @@
if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
if ( fRegex == null || fRegex.matches( content) == false )
- throw new InvalidDatatypeValueException("Value '"+content+
+ throw new InvalidDatatypeValueException("Value '"+content+
"' does not match regular expression facet '" + fPattern + "'." );
}
}
No revision
No revision
1.1.2.1 +91 -0 xml-xerces/java/src/org/apache/xerces/impl/validation/datatypes/Attic/StatefullDatatypeValidator.java