You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by "George T. Joseph" <gt...@peakin.com> on 2000/01/07 08:22:09 UTC

Changes for XSchemaValidator.java

I spent the day (actually yesterday) trying to get Schema validation working a bit better.  A diff to
org/apache/xerces/validators/schema/XSchemaValidator.java and a description is appended below for anyone who wants to use it.

George
*******************************************

reportSchemaError() was printing a stack trace for each validation error.  It was also eating the exceptions thrown instead of
propagating them back up the call stack.  I commented out the try/catch block so the calling application gets the exception and can
decide if a stack trace is appropriate.  I left printStackTrace alone where it was being called in "can't get here" situations.

A few System.exit() calls were commented out.  They should never be called but I'm not fond of having them around in APIs.

traverseAttributeDecl() was looking for the old 'required="true"' on an attribute definition instead of 'minOccurs="1"' to decide if
an attribute was required or not.

The datatypes 'negative-integer', 'positive-integer', 'non-negative-integer', and 'non-positive-integer' weren't being correctly
added to the datatype registry and were therefore unavailable.

*** xschemavalidatororig.java	Wed Jan 05 15:12:30 2000
--- xschemavalidator.java	Fri Jan 07 01:20:12 2000
***************
*** 1683,1694 ****
          catch (SAXException se) {
              se.getException().printStackTrace();
              System.err.println("error parsing schema file");
!             System.exit(1);
          }
          catch (Exception e) {
              e.printStackTrace();
              System.err.println("error parsing schema file");
!             System.exit(1);
          }
          fSchemaDocument = fSchemaParser.getDocument();
          if (fSchemaDocument == null) {
--- 1683,1694 ----
          catch (SAXException se) {
              se.getException().printStackTrace();
              System.err.println("error parsing schema file");
! //            System.exit(1);
          }
          catch (Exception e) {
              e.printStackTrace();
              System.err.println("error parsing schema file");
! //            System.exit(1);
          }
          fSchemaDocument = fSchemaParser.getDocument();
          if (fSchemaDocument == null) {
***************
*** 1703,1709 ****
          }
          catch (Exception e) {
              e.printStackTrace(System.err);
!             System.exit(1);
          }
      }

--- 1703,1709 ----
          }
          catch (Exception e) {
              e.printStackTrace(System.err);
! //            System.exit(1);
          }
      }

***************
*** 2206,2212 ****
          return index;
  	}

! 	public int traverseDatatypeDecl(Element datatypeDecl) {
  		int newTypeName = fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_NAME));
  		int export = fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_EXPORT));

--- 2206,2212 ----
          return index;
  	}

! 	public int traverseDatatypeDecl(Element datatypeDecl) throws Exception {
  		int newTypeName = fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_NAME));
  		int export = fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_EXPORT));

***************
*** 2449,2455 ****
  		// attribute default type
  		int attDefaultType = -1;
  		int attDefaultValue = -1;
! 		boolean required = attrDecl.getAttribute("required").equals("true");
  		if (required) {
  			attDefaultType = fStringPool.addSymbol("#REQUIRED");
  		} else {
--- 2449,2455 ----
  		// attribute default type
  		int attDefaultType = -1;
  		int attDefaultValue = -1;
! 		boolean required = attrDecl.getAttribute("minOccurs").equals("1");
  		if (required) {
  			attDefaultType = fStringPool.addSymbol("#REQUIRED");
  		} else {
***************
*** 3011,3027 ****
          return -1;
      }

! 	private void reportSchemaError(int major, Object args[]) {
! 	    try {
      		fErrorReporter.reportError(fErrorReporter.getLocator(),
  	    							   SchemaMessageProvider.SCHEMA_DOMAIN,
  		    						   major,
  			    					   SchemaMessageProvider.MSG_NONE,
  				    				   args,
  					    			   XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
! 		} catch (Exception e) {
! 		    e.printStackTrace();
! 		}
  	}

      //
--- 3011,3027 ----
          return -1;
      }

! 	private void reportSchemaError(int major, Object args[]) throws Exception {
! //	    try {
      		fErrorReporter.reportError(fErrorReporter.getLocator(),
  	    							   SchemaMessageProvider.SCHEMA_DOMAIN,
  		    						   major,
  			    					   SchemaMessageProvider.MSG_NONE,
  				    				   args,
  					    			   XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
! //		} catch (Exception e) {
! //		    e.printStackTrace();
! //		}
  	}

      //
***************
*** 3113,3119 ****

          String integerSubtypeTable[][] = {
              { "non-negative-integer", DatatypeValidator.MININCLUSIVE , "0"},
!             { "postive-integer", DatatypeValidator.MININCLUSIVE, "1"},
              { "non-positive-integer", DatatypeValidator.MAXINCLUSIVE, "0"},
              { "negative-integer", DatatypeValidator.MAXINCLUSIVE, "-1"}
          };
--- 3113,3119 ----

          String integerSubtypeTable[][] = {
              { "non-negative-integer", DatatypeValidator.MININCLUSIVE , "0"},
!             { "positive-integer", DatatypeValidator.MININCLUSIVE, "1"},
              { "non-positive-integer", DatatypeValidator.MAXINCLUSIVE, "0"},
              { "negative-integer", DatatypeValidator.MAXINCLUSIVE, "-1"}
          };
***************
*** 3149,3155 ****
                  } catch (UnknownFacetException ufe) {
                      System.out.println("Internal error initializing registry - Unknown facet: "+integerSubtypeTable[i][0]);
                  }
!                 fRegistry.put(integerSubtypeTable[0], v);
              }
          }

--- 3149,3155 ----
                  } catch (UnknownFacetException ufe) {
                      System.out.println("Internal error initializing registry - Unknown facet: "+integerSubtypeTable[i][0]);
                  }
!                 fRegistry.put(integerSubtypeTable[i][0], v);
              }
          }



Re: Changes for XSchemaValidator.java

Posted by Ted Leung <tw...@sauria.com>.
George,

Thanks for all these good patches.  I didn't get a chance to
look at them today, and I'm away on vacation until Tuesday.
I'll take a look at them when I get back.  I don't want you
to think you're being ignored.

Ted

----- Original Message -----
From: "George T. Joseph" <gt...@peakin.com>
To: "xerces-dev" <xe...@xml.apache.org>
Sent: Thursday, January 06, 2000 11:22 PM
Subject: Changes for XSchemaValidator.java


> I spent the day (actually yesterday) trying to get Schema validation
working a bit better.  A diff to
> org/apache/xerces/validators/schema/XSchemaValidator.java and a
description is appended below for anyone who wants to use it.
>
> George
> *******************************************
>
> reportSchemaError() was printing a stack trace for each validation error.
It was also eating the exceptions thrown instead of
> propagating them back up the call stack.  I commented out the try/catch
block so the calling application gets the exception and can
> decide if a stack trace is appropriate.  I left printStackTrace alone
where it was being called in "can't get here" situations.
>
> A few System.exit() calls were commented out.  They should never be called
but I'm not fond of having them around in APIs.
>
> traverseAttributeDecl() was looking for the old 'required="true"' on an
attribute definition instead of 'minOccurs="1"' to decide if
> an attribute was required or not.
>
> The datatypes 'negative-integer', 'positive-integer',
'non-negative-integer', and 'non-positive-integer' weren't being correctly
> added to the datatype registry and were therefore unavailable.
>
> *** xschemavalidatororig.java Wed Jan 05 15:12:30 2000
> --- xschemavalidator.java Fri Jan 07 01:20:12 2000
> ***************
> *** 1683,1694 ****
>           catch (SAXException se) {
>               se.getException().printStackTrace();
>               System.err.println("error parsing schema file");
> !             System.exit(1);
>           }
>           catch (Exception e) {
>               e.printStackTrace();
>               System.err.println("error parsing schema file");
> !             System.exit(1);
>           }
>           fSchemaDocument = fSchemaParser.getDocument();
>           if (fSchemaDocument == null) {
> --- 1683,1694 ----
>           catch (SAXException se) {
>               se.getException().printStackTrace();
>               System.err.println("error parsing schema file");
> ! //            System.exit(1);
>           }
>           catch (Exception e) {
>               e.printStackTrace();
>               System.err.println("error parsing schema file");
> ! //            System.exit(1);
>           }
>           fSchemaDocument = fSchemaParser.getDocument();
>           if (fSchemaDocument == null) {
> ***************
> *** 1703,1709 ****
>           }
>           catch (Exception e) {
>               e.printStackTrace(System.err);
> !             System.exit(1);
>           }
>       }
>
> --- 1703,1709 ----
>           }
>           catch (Exception e) {
>               e.printStackTrace(System.err);
> ! //            System.exit(1);
>           }
>       }
>
> ***************
> *** 2206,2212 ****
>           return index;
>   }
>
> ! public int traverseDatatypeDecl(Element datatypeDecl) {
>   int newTypeName =
fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_NAME));
>   int export =
fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_EXPORT));
>
> --- 2206,2212 ----
>           return index;
>   }
>
> ! public int traverseDatatypeDecl(Element datatypeDecl) throws Exception {
>   int newTypeName =
fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_NAME));
>   int export =
fStringPool.addSymbol(datatypeDecl.getAttribute(ATT_EXPORT));
>
> ***************
> *** 2449,2455 ****
>   // attribute default type
>   int attDefaultType = -1;
>   int attDefaultValue = -1;
> ! boolean required = attrDecl.getAttribute("required").equals("true");
>   if (required) {
>   attDefaultType = fStringPool.addSymbol("#REQUIRED");
>   } else {
> --- 2449,2455 ----
>   // attribute default type
>   int attDefaultType = -1;
>   int attDefaultValue = -1;
> ! boolean required = attrDecl.getAttribute("minOccurs").equals("1");
>   if (required) {
>   attDefaultType = fStringPool.addSymbol("#REQUIRED");
>   } else {
> ***************
> *** 3011,3027 ****
>           return -1;
>       }
>
> ! private void reportSchemaError(int major, Object args[]) {
> !     try {
>       fErrorReporter.reportError(fErrorReporter.getLocator(),
>          SchemaMessageProvider.SCHEMA_DOMAIN,
>          major,
>          SchemaMessageProvider.MSG_NONE,
>          args,
>          XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
> ! } catch (Exception e) {
> !     e.printStackTrace();
> ! }
>   }
>
>       //
> --- 3011,3027 ----
>           return -1;
>       }
>
> ! private void reportSchemaError(int major, Object args[]) throws
Exception {
> ! //     try {
>       fErrorReporter.reportError(fErrorReporter.getLocator(),
>          SchemaMessageProvider.SCHEMA_DOMAIN,
>          major,
>          SchemaMessageProvider.MSG_NONE,
>          args,
>          XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
> ! // } catch (Exception e) {
> ! //     e.printStackTrace();
> ! // }
>   }
>
>       //
> ***************
> *** 3113,3119 ****
>
>           String integerSubtypeTable[][] = {
>               { "non-negative-integer", DatatypeValidator.MININCLUSIVE ,
"0"},
> !             { "postive-integer", DatatypeValidator.MININCLUSIVE, "1"},
>               { "non-positive-integer", DatatypeValidator.MAXINCLUSIVE,
"0"},
>               { "negative-integer", DatatypeValidator.MAXINCLUSIVE, "-1"}
>           };
> --- 3113,3119 ----
>
>           String integerSubtypeTable[][] = {
>               { "non-negative-integer", DatatypeValidator.MININCLUSIVE ,
"0"},
> !             { "positive-integer", DatatypeValidator.MININCLUSIVE, "1"},
>               { "non-positive-integer", DatatypeValidator.MAXINCLUSIVE,
"0"},
>               { "negative-integer", DatatypeValidator.MAXINCLUSIVE, "-1"}
>           };
> ***************
> *** 3149,3155 ****
>                   } catch (UnknownFacetException ufe) {
>                       System.out.println("Internal error initializing
registry - Unknown facet: "+integerSubtypeTable[i][0]);
>                   }
> !                 fRegistry.put(integerSubtypeTable[0], v);
>               }
>           }
>
> --- 3149,3155 ----
>                   } catch (UnknownFacetException ufe) {
>                       System.out.println("Internal error initializing
registry - Unknown facet: "+integerSubtypeTable[i][0]);
>                   }
> !                 fRegistry.put(integerSubtypeTable[i][0], v);
>               }
>           }
>
>
>