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/08/11 04:12:04 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype StateMessageDatatype.java IDDatatypeValidator.java IDREFDatatypeValidator.java InvalidDatatypeFacetException.java InvalidDatatypeValueException.java Makefile
jeffreyr 00/08/10 19:12:03
Modified: java/src/org/apache/xerces/validators/datatype
IDDatatypeValidator.java
IDREFDatatypeValidator.java
InvalidDatatypeFacetException.java
InvalidDatatypeValueException.java Makefile
Added: java/src/org/apache/xerces/validators/datatype
StateMessageDatatype.java
Log:
Added more ID, IDREF functionality to merge DTD validators and XML Schema validators.
Also added Message communication mechanism.
Revision Changes Path
1.7 +18 -11 xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java
Index: IDDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- IDDatatypeValidator.java 2000/08/10 03:46:05 1.6
+++ IDDatatypeValidator.java 2000/08/11 02:12:01 1.7
@@ -67,7 +67,7 @@
* These validators can be supplied by the application writer and may be useful as
* standalone code as well as plugins to the validator architecture.
* @author Jeffrey Rodriguez
- * @version $Id: IDDatatypeValidator.java,v 1.6 2000/08/10 03:46:05 jeffreyr Exp $
+ * @version $Id: IDDatatypeValidator.java,v 1.7 2000/08/11 02:12:01 jeffreyr Exp $
*/
public class IDDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
@@ -91,29 +91,36 @@
/**
- * Checks that "content" string is valid
+ * 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 derivedBylist
- * Flag which is true when type
- * is derived by list otherwise it
- * it is derived by extension.
- *
+ * @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
+ * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
//Pass content as a String
- if (!XMLCharacterProperties.validName(content)) {//Check if is valid key
- throw new InvalidDatatypeValueException( "ID is not valid" );//Need Message
+ if (!XMLCharacterProperties.validName(content)) {//Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
+ InvalidDatatypeValueException error = new
+ InvalidDatatypeValueException( "ID is not valid: " );
+ error.setMajorCode(XMLMessages.MSG_ID_INVALID);
+ error.setMinorCode(XMLMessages.VC_ID);
+ throw error;
}
if(!addId( content, state) ){
- throw new InvalidDatatypeValueException( "ID has to be unique" );
+ InvalidDatatypeValueException error =
+ new InvalidDatatypeValueException( "ID" + content +"has to be unique" );
+ error.setMajorCode(XMLMessages.MSG_ID_NOT_UNIQUE);
+ error.setMinorCode(XMLMessages.VC_ID);
+ throw error;
+
}
return null;
}
1.6 +83 -29 xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java
Index: IDREFDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IDREFDatatypeValidator.java 2000/08/10 03:46:05 1.5
+++ IDREFDatatypeValidator.java 2000/08/11 02:12:01 1.6
@@ -59,18 +59,21 @@
import java.util.Hashtable;
import java.util.Locale;
+import java.util.Enumeration;
import org.apache.xerces.utils.XMLCharacterProperties;
import org.apache.xerces.utils.XMLMessages;
+
+
/**
* IDREFValidator defines the interface that data type validators must obey.
* These validators can be supplied by the application writer and may be useful as
* standalone code as well as plugins to the validator architecture.
*
* @author Jeffrey Rodriguez-
- * @version $Id: IDREFDatatypeValidator.java,v 1.5 2000/08/10 03:46:05 jeffreyr Exp $
+ * @version $Id: IDREFDatatypeValidator.java,v 1.6 2000/08/11 02:12:01 jeffreyr Exp $
*/
public class IDREFDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
@@ -80,9 +83,10 @@
private Object fNullValue = null;
private Locale fLocale = null;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
-
-
+ public static final int IDREF_STORE = 0;
+ public static final int IDREF_CLEAR = 1;
+ public static final int IDREF_VALIDATE = 2;
@@ -91,9 +95,13 @@
}
public IDREFDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
- fDerivedByList = derivedByList;
- setBasetype( base ); // Set base type
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
+
+ fDerivedByList = derivedByList;
+ setBasetype( base ); // Set base type
+
+
+
}
@@ -114,14 +122,34 @@
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
- //Pass content as a String
+ //Pass content as a String
+
+ StateMessageDatatype message;
+ if ( this.fDerivedByList == false ){
+ if (state!= null){
+ message = (StateMessageDatatype) state;
+ if (message.getDatatypeState() == IDREFDatatypeValidator.IDREF_CLEAR ){
+ if ( this.fTableOfId != null ){
+ fTableOfId.clear(); //This is pass to us through the state object
+ }
+ if ( this.fTableIDRefs != null ){
+ fTableIDRefs.clear();
+ }
+ return null;
+ } else if ( message.getDatatypeState() == IDREFDatatypeValidator.IDREF_VALIDATE ){
+ this.checkIdRefs();//Validate that all keyRef is a keyIds
+ } else if ( message.getDatatypeState() == IDREFDatatypeValidator.IDREF_STORE ) {
+ this.fTableOfId = (Hashtable) message.getDatatypeObject();
+ if (!XMLCharacterProperties.validName(content)) {//Check if is valid key
+ throw new InvalidDatatypeValueException( "IDREF is not valid" );//Need Message
+ }
+ addIdRef( content, state);// We are storing IDs
+ }
+ }
+ } else {
- this.fTableOfId = (Hashtable) state;
- if (!XMLCharacterProperties.validName(content)) {//Check if is valid key
- throw new InvalidDatatypeValueException( "ID is not valid" );//Need Message
}
- addIdRef( content, state);
return null;
}
@@ -140,22 +168,22 @@
public Hashtable getFacets(){
- return null;
- }
- /**
- * Returns a copy of this object.
- */
+ return null;
+ }
+ /**
+ * Returns a copy of this object.
+ */
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
}
- /**
- * 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
- */
+ /**
+ * 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;
}
@@ -164,12 +192,12 @@
private void addIdRef(String content, Object state) {
if ( state == null ) {
- if(content != null && this.fTableOfId.containsKey( content ) ){
+ if (content != null && this.fTableOfId.containsKey( content ) ){
return;
}
- if( this.fTableIDRefs == null ){
+ if ( this.fTableIDRefs == null ){
this.fTableIDRefs = new Hashtable();
- } else if( fTableIDRefs.containsKey( content ) ){
+ } else if ( fTableIDRefs.containsKey( content ) ){
return;
}
@@ -183,10 +211,35 @@
} // addId(int):boolean
+ private void checkIdRefs() throws InvalidDatatypeValueException {
+ if ( this.fTableIDRefs == null)
+ return;
+ Enumeration en = this.fTableIDRefs.keys();
+ while (en.hasMoreElements()) {
+ Integer key = (Integer)en.nextElement();
+ if ( this.fTableOfId == null || ! this.fTableOfId.containsKey(key)) {
+ InvalidDatatypeValueException error = new
+ InvalidDatatypeValueException( "ID is not valid: " );
+ error.setMajorCode(XMLMessages.MSG_ELEMENT_WITH_ID_REQUIRED);
+ error.setMinorCode(XMLMessages.VC_IDREF);
+ throw error;
+ }
+ // Object[] args = { key.intValue() };
- /**
- * set the locate to be used for error messages
- */
+ // fErrorReporter.reportError(fErrorReporter.getLocator(),
+ // XMLMessages.XML_DOMAIN,
+ // XMLMessages.MSG_ELEMENT_WITH_ID_REQUIRED,
+ // XMLMessages.VC_IDREF,
+ // args,
+ // XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
+ }
+
+ } // checkIdRefs()
+
+
+ /**
+ * set the locate to be used for error messages
+ */
public void setLocale(Locale locale) {
fLocale = locale;
}
@@ -202,3 +255,4 @@
}
+
1.3 +17 -1 xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeFacetException.java
Index: InvalidDatatypeFacetException.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeFacetException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InvalidDatatypeFacetException.java 2000/06/02 23:04:24 1.2
+++ InvalidDatatypeFacetException.java 2000/08/11 02:12:02 1.3
@@ -63,9 +63,25 @@
/**
*
* @author Jeffrey Rodriguez
- * @version $Id: InvalidDatatypeFacetException.java,v 1.2 2000/06/02 23:04:24 jeffreyr Exp $
+ * @version $Id: InvalidDatatypeFacetException.java,v 1.3 2000/08/11 02:12:02 jeffreyr Exp $
*/
public class InvalidDatatypeFacetException extends XMLException {
+ private int majorCode = -1;
+ private int minorCode = -1;
+
+ public int getMinorCode(){
+ return minorCode;
+ }
+ public int getMajorCode(){
+ return majorCode;
+ }
+
+ public void setMinorCode(int code ){
+ majorCode = code;
+ }
+ public void setMajorCode(int code ){
+ minorCode = code;
+ }
public InvalidDatatypeFacetException ( ){
super();
1.4 +20 -6 xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeValueException.java
Index: InvalidDatatypeValueException.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeValueException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InvalidDatatypeValueException.java 2000/06/02 23:04:24 1.3
+++ InvalidDatatypeValueException.java 2000/08/11 02:12:02 1.4
@@ -61,18 +61,32 @@
* InvalidDatatypeValueException is thrown when data value doesn't match it's datatype
*
* @author Jeffrey Rodriguez
- * @version $Id: InvalidDatatypeValueException.java,v 1.3 2000/06/02 23:04:24 jeffreyr Exp $
+ * @version $Id: InvalidDatatypeValueException.java,v 1.4 2000/08/11 02:12:02 jeffreyr Exp $
*/
public class InvalidDatatypeValueException extends XMLException {
+ private int majorCode = -1;
+ private int minorCode = -1;
- public InvalidDatatypeValueException() { super(); }
- public InvalidDatatypeValueException(String msg) { super(msg); }
- public InvalidDatatypeValueException ( Exception exception ) {
+ public int getMinorCode(){
+ return minorCode;
+ }
+ public int getMajorCode(){
+ return majorCode;
+ }
+
+ public void setMinorCode(int code ){
+ majorCode = code;
+ }
+ public void setMajorCode(int code ){
+ minorCode = code;
+ }
+
+ public InvalidDatatypeValueException() { super(); }
+ public InvalidDatatypeValueException(String msg) { super(msg); }
+ public InvalidDatatypeValueException ( Exception exception ) {
super( exception );
}
public InvalidDatatypeValueException ( String message, Exception exception ) {
super( message, exception );
}
-
-
}
1.7 +1 -0 xml-xerces/java/src/org/apache/xerces/validators/datatype/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/Makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile 2000/06/02 05:36:25 1.6
+++ Makefile 2000/08/11 02:12:02 1.7
@@ -22,6 +22,7 @@
RecurringDurationDatatypeValidator.class\
TimeDurationDatatypeValidator.class\
DatatypeValidatorFactoryImpl.class\
+ StateMessageDatatype.class\
XMLException.class
DIRS =
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/StateMessageDatatype.java
Index: StateMessageDatatype.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 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.validators.datatype;
public interface StateMessageDatatype{
public Object getDatatypeObject();
public int getDatatypeState();
}