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/10 04:58:19 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype IDDatatypeValidator.java
jeffreyr 00/08/09 19:58:19
Modified: java/src/org/apache/xerces/validators/datatype
IDDatatypeValidator.java
Log:
WIP- Migrating ATTValidators from XMLValidator to Schema to unify all validator.
Revision Changes Path
1.5 +61 -7 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- IDDatatypeValidator.java 2000/06/23 01:26:29 1.4
+++ IDDatatypeValidator.java 2000/08/10 02:58:19 1.5
@@ -59,25 +59,33 @@
import java.util.Hashtable;
import java.util.Locale;
+import java.util.Hashtable;
+import org.apache.xerces.utils.XMLCharacterProperties;
+import org.apache.xerces.utils.XMLMessages;
/**
* DataTypeValidator 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: IDDatatypeValidator.java,v 1.4 2000/06/23 01:26:29 jeffreyr Exp $
+ * @version $Id: IDDatatypeValidator.java,v 1.5 2000/08/10 02:58:19 jeffreyr Exp $
*/
public class IDDatatypeValidator extends AbstractDatatypeValidator {
- private DatatypeValidator fBaseValidator = null;
- private boolean fDerivedByList = false;
+ private DatatypeValidator fBaseValidator = null;
+ private boolean fDerivedByList = false;
+ private Object fNullValue = null;
+ private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
+ private Hashtable fTableOfId;
+ private Locale fLocale = null;
+
public IDDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public IDDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
fDerivedByList = derivedByList;
}
@@ -100,6 +108,14 @@
* @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(!addId( content, state) ){
+ throw new InvalidDatatypeValueException( "ID has to be unique" );
+ }
return null;
}
@@ -118,9 +134,10 @@
public Hashtable getFacets(){
return null;
}
- /**
- * Returns a copy of this object.
- */
+
+ /**
+ * Returns a copy of this object.
+ */
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
}
@@ -136,5 +153,42 @@
private void setBasetype(DatatypeValidator base){
fBaseValidator = base;
}
+
+ /** addId. */
+ private boolean addId(String content, Object state) {
+
+ if ( state == null ) {
+ if ( this.fTableOfId == null ){
+ this.fTableOfId = new Hashtable();
+ } else if ( this.fTableOfId.containsKey( content ) ){
+ return false;
+ }
+ if ( this.fNullValue == null ){
+ fNullValue = new Object();
+ }
+ this.fTableOfId.put( content, fNullValue );
+ } else {
+ ;
+ }
+ 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[]) {
+ try {
+ return fMessageProvider.createMessage(fLocale, major, minor, args);
+ } catch (Exception e) {
+ return "Illegal Errorcode "+minor;
+ }
+ }
+
}