You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/11/28 18:54:52 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new AbstractDateTimeDV.java DoubleDV.java FloatDV.java MonthDV.java SchemaDVFactoryImpl.java XSSimpleTypeDecl.java YearMonthDV.java
sandygao 01/11/28 09:54:52
Modified: java/src/org/apache/xerces/impl/dv DatatypeValidator.java
SchemaDVFactory.java ValidatedInfo.java
XSSimpleType.java
java/src/org/apache/xerces/impl/dv/xs_new
AbstractDateTimeDV.java DoubleDV.java FloatDV.java
MonthDV.java SchemaDVFactoryImpl.java
XSSimpleTypeDecl.java YearMonthDV.java
Log:
Various updates on the new simpleType design:
1. If the type is a union type, we need to return which member type is used
to actually validate a value.
2. Add a method on SchemaDVFactory to get an instance of specified factory
implementation.
3. Provide a way to tell whether a type is a NOTATION type.
4. Bug fixed in the default implementation (xs_new package).
Revision Changes Path
1.2 +5 -4 xml-xerces/java/src/org/apache/xerces/impl/dv/DatatypeValidator.java
Index: DatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/DatatypeValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DatatypeValidator.java 2001/11/19 20:13:00 1.1
+++ DatatypeValidator.java 2001/11/28 17:54:52 1.2
@@ -65,7 +65,7 @@
*
* @author Sandy Gao, IBM
*
- * @version $Id: DatatypeValidator.java,v 1.1 2001/11/19 20:13:00 sandygao Exp $
+ * @version $Id: DatatypeValidator.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public interface DatatypeValidator {
@@ -74,11 +74,12 @@
*
* @param content the string value that needs to be validated
* @param context the validation context
- * @param validatedInfo used to store validatoin result
*
- * @return the actual value (QName, Boolean) of the string value
+ * @return the actual value of the string value
+ * (most likely a normalized string, since all types
+ * in DTD are string types.)
*/
- public Object validate(String content, ValidationContext context, ValidatedInfo validatedInfo)
+ public Object validate(String content, ValidationContext context)
throws InvalidDatatypeValueException;
}
1.2 +69 -7 xml-xerces/java/src/org/apache/xerces/impl/dv/SchemaDVFactory.java
Index: SchemaDVFactory.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/SchemaDVFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SchemaDVFactory.java 2001/11/19 20:13:00 1.1
+++ SchemaDVFactory.java 2001/11/28 17:54:52 1.2
@@ -57,6 +57,7 @@
package org.apache.xerces.impl.dv;
+import org.apache.xerces.impl.dv.xs_new.SchemaDVFactoryImpl;
import java.util.Hashtable;
/**
@@ -67,11 +68,72 @@
*
* @author Sandy Gao, IBM
*
- * @version $Id: SchemaDVFactory.java,v 1.1 2001/11/19 20:13:00 sandygao Exp $
+ * @version $Id: SchemaDVFactory.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
-public interface SchemaDVFactory {
+public abstract class SchemaDVFactory {
/**
+ * property name of the schema dv factory implementation class
+ */
+ public static final String SCHEMA_DV_FACTORY_CLASS = "xerces.dv.schemadv";
+
+ private static SchemaDVFactory fSchemaDVFactory = null;
+
+ /**
+ * Get an instance of SchemaDVFactory implementation.
+ *
+ * The system property "xerces.dv.schemadv" needs to be specified to the
+ * class name of the implementation. If there is any error creating an
+ * instance of the specified class, the default implementation is used.
+ *
+ * After the first time this method successfully returns, any subsequent
+ * invocation to this method returns the same instance, even if the system
+ * property is changed later on.
+ *
+ * @return an instance of SchemaDVFactory implementation
+ */
+ public static final SchemaDVFactory getInstance() {
+ // if the factory instance has been created, just return it.
+ if (fSchemaDVFactory != null)
+ return fSchemaDVFactory;
+
+ // synchronize on the string value, to make sure that we don't create
+ // two instance of the dv factory class
+ synchronized (SCHEMA_DV_FACTORY_CLASS) {
+ // in case this thread was waiting for another thread to create
+ // the factory instance, just return the instance created by the
+ // other thread.
+ if (fSchemaDVFactory != null)
+ return fSchemaDVFactory;
+
+ // get the class name from the system property
+ String factoryClass = System.getProperty(SCHEMA_DV_FACTORY_CLASS);
+
+ try {
+ // if the class name is specified, try to create a new instance
+ // of that
+ if (factoryClass != null)
+ fSchemaDVFactory = (SchemaDVFactory)(Class.forName(factoryClass).newInstance());
+ } catch (Exception e) {
+ // REVISIT: the system property specified by the application is
+ // not valid do we want to report some kind of error/warning?
+ }
+
+ // if the class name is not specified, or we failed creating a new
+ // instance, create an instance of the default implementation of
+ // the dv factory interface
+ if (fSchemaDVFactory == null)
+ fSchemaDVFactory = new SchemaDVFactoryImpl();
+ }
+
+ // return the newly created dv factory instance
+ return fSchemaDVFactory;
+ }
+
+ // can't create a new object of this class
+ protected SchemaDVFactory(){}
+
+ /**
* Get a built-in simple type of the given name
* REVISIT: its still not decided within the Schema WG how to define the
* ur-types and if all simple types should be derived from a
@@ -82,7 +144,7 @@
* @param name the name of the datatype
* @return the datatype validator of the given name
*/
- public XSSimpleType getBuiltInType(String name);
+ public abstract XSSimpleType getBuiltInType(String name);
/**
* get all built-in simple types, which are stored in a hashtable keyed by
@@ -90,7 +152,7 @@
*
* @return a hashtable which contains all built-in simple types
*/
- public Hashtable getBuiltInTypes();
+ public abstract Hashtable getBuiltInTypes();
/**
* Create a new simple type which is derived by restriction from another
@@ -102,7 +164,7 @@
* @param base base type of the new type
* @return the newly created simple type
*/
- public XSSimpleType createTypeRestriction(String name, String targetNamespace,
+ public abstract XSSimpleType createTypeRestriction(String name, String targetNamespace,
short finalSet, XSSimpleType base);
/**
@@ -115,7 +177,7 @@
* @param itemType item type of the list type
* @return the newly created simple type
*/
- public XSListSimpleType createTypeList(String name, String targetNamespace,
+ public abstract XSListSimpleType createTypeList(String name, String targetNamespace,
short finalSet, XSSimpleType itemType);
/**
@@ -128,7 +190,7 @@
* @param base member types of the union type
* @return the newly created simple type
*/
- public XSUnionSimpleType createTypeUnion(String name, String targetNamespace,
+ public abstract XSUnionSimpleType createTypeUnion(String name, String targetNamespace,
short finalSet, XSSimpleType[] memberTypes);
}
1.2 +11 -1 xml-xerces/java/src/org/apache/xerces/impl/dv/ValidatedInfo.java
Index: ValidatedInfo.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/ValidatedInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ValidatedInfo.java 2001/11/19 20:13:00 1.1
+++ ValidatedInfo.java 2001/11/28 17:54:52 1.2
@@ -63,7 +63,7 @@
*
* @author Neeraj Bajaj, Sun Microsystems, inc.
*
- * @version $Id: ValidatedInfo.java,v 1.1 2001/11/19 20:13:00 sandygao Exp $
+ * @version $Id: ValidatedInfo.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public class ValidatedInfo {
@@ -74,6 +74,7 @@
/**
* The actual value from a string value (QName, Boolean, etc.)
+ * An array of Objects if the type is a list.
*/
public Object actualValue;
@@ -82,5 +83,14 @@
* actually validated the string value.
*/
public XSSimpleType memberType;
+
+ /**
+ * If
+ * 1. the type is a union type where one of the member types is a list, or
+ * if the type is a list; and
+ * 2. the item type of the list is a union type
+ * then an array of member types used to validate the values.
+ */
+ public XSSimpleType[] memberTypes;
}
1.2 +32 -3 xml-xerces/java/src/org/apache/xerces/impl/dv/XSSimpleType.java
Index: XSSimpleType.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/XSSimpleType.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XSSimpleType.java 2001/11/19 20:13:00 1.1
+++ XSSimpleType.java 2001/11/28 17:54:52 1.2
@@ -57,6 +57,7 @@
package org.apache.xerces.impl.dv;
+import org.apache.xerces.impl.validation.ValidationContext;
import org.apache.xerces.impl.xs.XSTypeDecl;
/**
@@ -65,9 +66,9 @@
*
* @author Sandy Gao, IBM
*
- * @version $Id: XSSimpleType.java,v 1.1 2001/11/19 20:13:00 sandygao Exp $
+ * @version $Id: XSSimpleType.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
-public interface XSSimpleType extends XSTypeDecl, DatatypeValidator {
+public interface XSSimpleType extends XSTypeDecl {
/**
* The bit combination of the following constants are used to tell
@@ -114,6 +115,28 @@
public static final short CARDINALITY_COUNTABLY_INFINITE = 2;
/**
+ * validate a given string against this DV
+ *
+ * @param content the string value that needs to be validated
+ * @param context the validation context
+ * @param validatedInfo used to store validatoin result
+ *
+ * @return the actual value (QName, Boolean) of the string value
+ */
+ public Object validate(String content, ValidationContext context, ValidatedInfo validatedInfo)
+ throws InvalidDatatypeValueException;
+
+ /**
+ * validate an actual value against this DV
+ *
+ * @param value the actual value that needs to be validated
+ * @param context the validation context
+ * @param validatedInfo used to provide the actual value and member types
+ */
+ public void validate(ValidationContext context, ValidatedInfo validatedInfo)
+ throws InvalidDatatypeValueException;
+
+ /**
* If this type is created from restriction, then some facets can be applied
* to the simple type.
*
@@ -121,7 +144,7 @@
* @param presentFacets which facets are present
* @param fixedFacets which facets are fixed
*/
- public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet)
+ public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, ValidationContext context)
throws InvalidDatatypeFacetException;
/**
@@ -172,6 +195,12 @@
* clean way of doing it except to define special method like this.
*/
public boolean isIDType();
+
+ /**
+ * Check whether this type is or is derived from NOTATION.
+ * REVISIT: this method makes NOTATION special, which is not a good design.
+ */
+ public boolean isNOTATIONType();
// REVISIT: the following methods are for PSVI. they are not implemented yet.
//public XSFacet[] getFacets();
1.2 +4 -0 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/AbstractDateTimeDV.java
Index: AbstractDateTimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/AbstractDateTimeDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractDateTimeDV.java 2001/11/19 20:13:01 1.1
+++ AbstractDateTimeDV.java 2001/11/28 17:54:52 1.2
@@ -74,7 +74,7 @@
* @author Len Berman
* @author Gopal Sharma, SUN Microsystems Inc.
*
- * @version $Id: AbstractDateTimeDV.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: AbstractDateTimeDV.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public abstract class AbstractDateTimeDV extends TypeValidator {
@@ -126,6 +126,10 @@
//error message buffer
protected StringBuffer message;
+
+ public AbstractDateTimeDV(){
+ initializeValues();
+ }
protected void initializeValues(){
fDateValue = new int[TOTAL_SIZE];
1.2 +20 -2 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/DoubleDV.java
Index: DoubleDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/DoubleDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DoubleDV.java 2001/11/19 20:13:01 1.1
+++ DoubleDV.java 2001/11/28 17:54:52 1.2
@@ -66,7 +66,7 @@
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: DoubleDV.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: DoubleDV.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public class DoubleDV extends TypeValidator {
@@ -85,8 +85,9 @@
}
}//getActualValue()
+ // Can't call Double#compareTo method, because it's introduced in jdk 1.2
public int compare(Object value1, Object value2) {
- return ((Double)value1).compareTo((Double)value2);
+ return compareDoubles((Double)value1, (Double)value2);
}//compare()
//
@@ -113,5 +114,22 @@
}
return d;
}//dValueOf()
+
+ private int compareDoubles(Double value, Double anotherValue) {
+ double thisVal = value.doubleValue();
+ double anotherVal = anotherValue.doubleValue();
+
+ if (thisVal < anotherVal)
+ return -1; // Neither val is NaN, thisVal is smaller
+ if (thisVal > anotherVal)
+ return 1; // Neither val is NaN, thisVal is larger
+
+ long thisBits = Double.doubleToLongBits(thisVal);
+ long anotherBits = Double.doubleToLongBits(anotherVal);
+
+ return (thisBits == anotherBits ? 0 : // Values are equal
+ (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
+ 1)); // (0.0, -0.0) or (NaN, !NaN)
+ }
} // class DoubleDV
1.2 +19 -2 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/FloatDV.java
Index: FloatDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/FloatDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FloatDV.java 2001/11/19 20:13:01 1.1
+++ FloatDV.java 2001/11/28 17:54:52 1.2
@@ -66,7 +66,7 @@
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: FloatDV.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: FloatDV.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public class FloatDV extends TypeValidator {
@@ -85,9 +85,9 @@
}
}//getActualValue()
- // Float compareTo method takes care of cases specified for Float in schema spec.
+ // Can't call Float#compareTo method, because it's introduced in jdk 1.2
public int compare(Object value1, Object value2){
- return ((Float)value1).compareTo((Float)value2);
+ return compareFloats((Float)value1, (Float)value2);
}//compare()
//takes care of special values positive, negative infinity and Not a Number as per the spec.
@@ -111,6 +111,23 @@
}
}
return f;
+ }
+
+ private int compareFloats(Float value, Float anotherValue){
+ float thisVal = value.floatValue();
+ float anotherVal = anotherValue.floatValue();
+
+ if (thisVal < anotherVal)
+ return -1; // Neither val is NaN, thisVal is smaller
+ if (thisVal > anotherVal)
+ return 1; // Neither val is NaN, thisVal is larger
+
+ int thisBits = Float.floatToIntBits(thisVal);
+ int anotherBits = Float.floatToIntBits(anotherVal);
+
+ return (thisBits == anotherBits ? 0 : // Values are equal
+ (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
+ 1)); // (0.0, -0.0) or (NaN, !NaN)
}
} // class FloatDV
1.2 +1 -1 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/MonthDV.java
Index: MonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/MonthDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MonthDV.java 2001/11/19 20:13:01 1.1
+++ MonthDV.java 2001/11/28 17:54:52 1.2
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: MonthDV.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: MonthDV.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public class MonthDV extends AbstractDateTimeDV {
@@ -144,7 +144,7 @@
protected int compareDates(int[] date1, int[] date2) {
if ( date1[utc]==date2[utc] ) {
- return (date1[M]>=date2[M])?(date1[M]>date2[M])?-1:0:1;
+ return (date1[M]>=date2[M])?(date1[M]>date2[M])?1:0:-1;
}
if ( date1[utc]=='Z' || date2[utc]=='Z' ) {
1.2 +1 -1 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/SchemaDVFactoryImpl.java
Index: SchemaDVFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/SchemaDVFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SchemaDVFactoryImpl.java 2001/11/19 20:13:01 1.1
+++ SchemaDVFactoryImpl.java 2001/11/28 17:54:52 1.2
@@ -71,9 +71,9 @@
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @author Sandy Gao, IBM
*
- * @version $Id: SchemaDVFactoryImpl.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: SchemaDVFactoryImpl.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
-public class SchemaDVFactoryImpl implements SchemaDVFactory {
+public class SchemaDVFactoryImpl extends SchemaDVFactory {
static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
1.2 +103 -31 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/XSSimpleTypeDecl.java
Index: XSSimpleTypeDecl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/XSSimpleTypeDecl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XSSimpleTypeDecl.java 2001/11/19 20:13:01 1.1
+++ XSSimpleTypeDecl.java 2001/11/28 17:54:52 1.2
@@ -77,7 +77,7 @@
* @author Sandy Gao, IBM
* @author Neeraj Bajaj, Sun Microsystems, inc.
*
- * @version $Id: XSSimpleTypeDecl.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: XSSimpleTypeDecl.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
class XSSimpleTypeDecl implements XSAtomicSimpleType, XSListSimpleType, XSUnionSimpleType {
@@ -175,6 +175,8 @@
private Object fMinExclusive;
private Object fMinInclusive;
+ private ValidatedInfo fTempInfo = new ValidatedInfo();
+
//Create a new built-in primitive types (and id/idref/entity)
protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, short validateDV) {
fBase = base;
@@ -299,6 +301,10 @@
return (fValidationDV == DV_ID);
}
+ public boolean isNOTATIONType(){
+ return (fValidationDV == DV_NOTATION);
+ }
+
// REVISIT
public XSSimpleType getPrimitiveType() {
if (fVariety == VARIETY_ATOMIC)
@@ -324,9 +330,9 @@
/**
* If <restriction> is chosen
*/
- public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet)
+ public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, ValidationContext context)
throws InvalidDatatypeFacetException {
- applyFacets(facets, presentFacet, fixedFacet, (short)0);
+ applyFacets(facets, presentFacet, fixedFacet, (short)0, context);
}
/**
@@ -335,7 +341,7 @@
void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet) {
try {
- applyFacets(facets, presentFacet, fixedFacet, (short)0);
+ applyFacets(facets, presentFacet, fixedFacet, (short)0, null);
} catch (InvalidDatatypeFacetException e) {
// should never gets here, internel error
throw new RuntimeException("internal error");
@@ -348,7 +354,7 @@
void applyFacets1(XSFacets facets, short presentFacet, short fixedFacet, short tokenType) {
try {
- applyFacets(facets, presentFacet, fixedFacet, tokenType);
+ applyFacets(facets, presentFacet, fixedFacet, tokenType, null);
} catch (InvalidDatatypeFacetException e) {
// should never gets here, internel error
throw new RuntimeException("internal error");
@@ -358,7 +364,7 @@
/**
* If <restriction> is chosen, or built-in derived types by restriction
*/
- void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, short tokenType)
+ void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, short tokenType, ValidationContext context)
throws InvalidDatatypeFacetException {
// clear facets. because we always inherit facets in the constructor
@@ -440,7 +446,7 @@
Vector enumVals = facets.enumeration;
for (int i = enumVals.size()-1; i >= 0; i--) {
try {
- fEnumeration.addElement(getActualValue((String)enumVals.elementAt(i), null, null));
+ fEnumeration.addElement(getActualValue((String)enumVals.elementAt(i), context, fTempInfo));
} catch (InvalidDatatypeValueException ide) {
reportError("Value of enumeration '" + enumVals.elementAt(i) + "' must be from the value space of base");
}
@@ -467,7 +473,7 @@
reportError("non-supported facet");
} else {
try {
- fMaxInclusive = getActualValue(facets.maxInclusive, null, null);
+ fMaxInclusive = getActualValue(facets.maxInclusive, context, fTempInfo);
fFacetsDefined |= FACET_MAXINCLUSIVE;
if ((fixedFacet & FACET_MAXINCLUSIVE) != 0)
fFixedFacet |= FACET_MAXINCLUSIVE;
@@ -482,7 +488,7 @@
reportError("non-supported facet");
} else {
try {
- fMaxExclusive = getActualValue(facets.maxExclusive, null, null);
+ fMaxExclusive = getActualValue(facets.maxExclusive, context, fTempInfo);
fFacetsDefined |= FACET_MAXEXCLUSIVE;
if ((fixedFacet & FACET_MAXEXCLUSIVE) != 0)
fFixedFacet |= FACET_MAXEXCLUSIVE;
@@ -497,7 +503,7 @@
reportError("non-supported facet");
} else {
try {
- fMinExclusive = getActualValue(facets.minExclusive, null, null);
+ fMinExclusive = getActualValue(facets.minExclusive, context, fTempInfo);
fFacetsDefined |= FACET_MINEXCLUSIVE;
if ((fixedFacet & FACET_MINEXCLUSIVE) != 0)
fFixedFacet |= FACET_MINEXCLUSIVE;
@@ -512,7 +518,7 @@
reportError("non-supported facet");
} else {
try {
- fMinInclusive = getActualValue(facets.minInclusive, null, null);
+ fMinInclusive = getActualValue(facets.minInclusive, context, fTempInfo);
fFacetsDefined |= FACET_MININCLUSIVE;
if ((fixedFacet & FACET_MININCLUSIVE) != 0)
fFixedFacet |= FACET_MININCLUSIVE;
@@ -1006,10 +1012,50 @@
* validate a value, and return the compiled form
*/
public Object validate(String content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException {
+
+ // first normalize string value, and convert it to actual value
+ Object ob = getActualValue(content, context, fTempInfo);
+
+ validate(context, fTempInfo);
+
+ if (validatedInfo != null) {
+ validatedInfo.actualValue = fTempInfo.actualValue;
+ validatedInfo.normalizedValue = fTempInfo.normalizedValue;
+ validatedInfo.memberType = fTempInfo.memberType;
+ validatedInfo.memberTypes = fTempInfo.memberTypes;
+ }
+
+ return ob;
+
+ }
+
+ /**
+ * validate an actual value against this DV
+ *
+ * @param value the actual value that needs to be validated
+ * @param context the validation context
+ * @param validatedInfo used to provide the actual value and member types
+ */
+ public void validate(ValidationContext context, ValidatedInfo validatedInfo)
+ throws InvalidDatatypeValueException {
+
+ // then validate the actual value against the facets
+ if (context.needFacetChecking() &&
+ (fFacetsDefined != 0 && fFacetsDefined != FACET_WHITESPACE)) {
+ checkFacets(validatedInfo);
+ }
+
+ // now check extra rules: for ID/IDREF/ENTITY
+ if (context.needExtraChecking()) {
+ checkExtraRules(context, validatedInfo);
+ }
+
+ }
+
+ private void checkFacets(ValidatedInfo validatedInfo) throws InvalidDatatypeValueException {
- // step 1: validate the value against the facets. we need to use the
- // get***, compare, isEqual methods from TypeValidator
- Object ob = getActualValue(content, context, validatedInfo);
+ Object ob = validatedInfo.actualValue;
+ String content = validatedInfo.normalizedValue;
if ( (fFacetsDefined & FACET_PATTERN ) != 0 ) {
RegularExpression regex;
@@ -1184,14 +1230,44 @@
SPECIAL_TOKEN_STRING[fTokenType]);
}
}
+ }
- // check extra rules: for ID/IDREF/ENTITY
- fDVs[fValidationDV].checkExtraRules(ob, context);
+ private void checkExtraRules(ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException {
- return ob;
+ Object ob = validatedInfo.actualValue;
+
+ if (fVariety == VARIETY_ATOMIC) {
+
+ fDVs[fValidationDV].checkExtraRules(ob, context);
- }// validate()
+ } else if (fVariety == VARIETY_LIST) {
+ Object[] values = (Object[])ob;
+ if (fItemType.fVariety == VARIETY_UNION) {
+ XSSimpleTypeDecl[] memberTypes = (XSSimpleTypeDecl[])validatedInfo.memberTypes;
+ XSSimpleType memberType = validatedInfo.memberType;
+ for (int i = values.length-1; i >= 0; i--) {
+ validatedInfo.actualValue = values[i];
+ validatedInfo.memberType = memberTypes[i];
+ fItemType.checkExtraRules(context, validatedInfo);
+ }
+ validatedInfo.memberType = memberType;
+ } else { // (fVariety == VARIETY_ATOMIC)
+ for (int i = values.length-1; i >= 0; i--) {
+ validatedInfo.actualValue = values[i];
+ fItemType.checkExtraRules(context, validatedInfo);
+ }
+ }
+ validatedInfo.actualValue = values;
+
+ } else { // (fVariety == VARIETY_UNION)
+
+ ((XSSimpleTypeDecl)validatedInfo.memberType).checkExtraRules(context, validatedInfo);
+
+ }
+
+ }// checkExtraRules()
+
//we can still return object for internal use.
private Object getActualValue(String content, ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException{
@@ -1200,11 +1276,8 @@
String nvalue = normalize(content, fWhiteSpace);
Object avalue = fDVs[fValidationDV].getActualValue(nvalue, context);
- if (validatedInfo != null) {
- validatedInfo.actualValue = avalue;
- validatedInfo.normalizedValue = nvalue;
- validatedInfo.memberType = null;
- }
+ validatedInfo.actualValue = avalue;
+ validatedInfo.normalizedValue = nvalue;
return avalue;
@@ -1214,15 +1287,15 @@
StringTokenizer parsedList = new StringTokenizer(nvalue);
int countOfTokens = parsedList.countTokens() ;
Object[] avalue = new Object[countOfTokens];
+ XSSimpleTypeDecl[] memberTypes = new XSSimpleTypeDecl[countOfTokens];
for(int i = 0 ; i < countOfTokens ; i ++){
- avalue[i] = fItemType.validate(parsedList.nextToken(), context, null);
+ avalue[i] = fItemType.validate(parsedList.nextToken(), context, validatedInfo);
+ memberTypes[i] = (XSSimpleTypeDecl)validatedInfo.memberType;
}
- if (validatedInfo != null) {
- validatedInfo.actualValue = avalue;
- validatedInfo.normalizedValue = nvalue;
- validatedInfo.memberType = null;
- }
+ validatedInfo.actualValue = avalue;
+ validatedInfo.normalizedValue = nvalue;
+ validatedInfo.memberTypes = memberTypes;
return avalue;
@@ -1232,8 +1305,7 @@
try {
//it should throw exception if anything goes wrong
Object aValue = fMemberTypes[i].validate(content, context, validatedInfo);
- if (validatedInfo != null)
- validatedInfo.memberType = fMemberTypes[i];
+ validatedInfo.memberType = fMemberTypes[i];
return aValue;
} catch(InvalidDatatypeValueException invalidValue) {
}
1.2 +1 -0 xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/YearMonthDV.java
Index: YearMonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs_new/YearMonthDV.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- YearMonthDV.java 2001/11/19 20:13:01 1.1
+++ YearMonthDV.java 2001/11/28 17:54:52 1.2
@@ -66,7 +66,7 @@
* @author Elena Litani
* @author Gopal Sharma, SUN Microsystem Inc.
*
- * @version $Id: YearMonthDV.java,v 1.1 2001/11/19 20:13:01 sandygao Exp $
+ * @version $Id: YearMonthDV.java,v 1.2 2001/11/28 17:54:52 sandygao Exp $
*/
public class YearMonthDV extends AbstractDateTimeDV{
@@ -104,6 +104,7 @@
// get date
getYearMonth(fStart, fEnd, date);
+ date[D] = DAY;
parseTimeZone (fEnd, date);
//validate and normalize
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org