ankitp 2005/05/09 14:03:33
Modified: java/src/org/apache/xerces/impl/xs/identity ValueStore.java
XPathMatcher.java Selector.java Field.java
java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java
Log:
Jira Bug#993 Fix:Identity-constraint validation on cross datatypes is
incorrect
Revision Changes Path
1.9 +5 -3
xml-xerces/java/src/org/apache/xerces/impl/xs/identity/ValueStore.java
Index: ValueStore.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/identity/ValueStore.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ValueStore.java 6 Oct 2004 15:14:51 -0000 1.8
+++ ValueStore.java 9 May 2005 21:03:33 -0000 1.9
@@ -1,5 +1,5 @@
/*
- * Copyright 2001, 2002,2004 The Apache Software Foundation.
+ * Copyright 2001, 2002,2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.apache.xerces.impl.xs.identity;
+import org.apache.xerces.xs.ShortList;
+
/**
* Interface for storing values associated to an identity constraint.
@@ -51,7 +53,7 @@
* once within a selection scope.
* @param actualValue The value to add.
*/
- public void addValue(Field field, Object actualValue);
+ public void addValue(Field field, Object actualValue, short valueType,
ShortList itemValueType);
/**
* Since the valueStore will have access to an error reporter, this
1.26 +10 -8
xml-xerces/java/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java
Index: XPathMatcher.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- XPathMatcher.java 6 Oct 2004 15:14:51 -0000 1.25
+++ XPathMatcher.java 9 May 2005 21:03:33 -0000 1.26
@@ -1,5 +1,5 @@
/*
- * Copyright 2001, 2002,2004 The Apache Software Foundation.
+ * Copyright 2001, 2002,2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,11 +18,13 @@
import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.xpath.XPath;
-import org.apache.xerces.xs.XSTypeDefinition;
import org.apache.xerces.util.IntStack;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xs.AttributePSVI;
+import org.apache.xerces.xs.ShortList;
+import org.apache.xerces.xs.XSTypeDefinition;
+import org.xml.sax.SAXException;
/**
@@ -151,7 +153,7 @@
// a place-holder method; to be overridden by subclasses
// that care about matching element content.
- protected void handleContent(XSTypeDefinition type, boolean nillable,
Object value) {
+ protected void handleContent(XSTypeDefinition type, boolean nillable,
Object value, short valueType, ShortList itemValueType) {
}
/**
@@ -159,7 +161,7 @@
* XPath expression. Subclasses can override this method to
* provide default handling upon a match.
*/
- protected void matched(Object actualValue, boolean isNil) {
+ protected void matched(Object actualValue, short valueType, ShortList
itemValueType, boolean isNil) {
if (DEBUG_METHODS3) {
System.out.println(toString()+"#matched(\""+actualValue+"\")");
}
@@ -326,7 +328,7 @@
if(j==i) {
AttributePSVI attrPSVI =
(AttributePSVI)attributes.getAugmentations(aIndex).getItem(Constants.ATTRIBUTE_PSVI);
fMatchedString =
attrPSVI.getActualNormalizedValue();
- matched(fMatchedString, false);
+ matched(fMatchedString,
attrPSVI.getActualNormalizedValueType(), attrPSVI.getItemValueTypes(), false);
}
}
break;
@@ -367,7 +369,7 @@
* @param value - actual value
* the typed value of the content of this element.
*/
- public void endElement(QName element, XSTypeDefinition type, boolean
nillable, Object value ) {
+ public void endElement(QName element, XSTypeDefinition type, boolean
nillable, Object value, short valueType, ShortList itemValueType) {
if (DEBUG_METHODS2) {
System.out.println(toString()+"#endElement("+
"element={"+element+"},"+
@@ -394,7 +396,7 @@
// match element content. This permits
// them a way to override this to do nothing
// and hopefully save a few operations.
- handleContent(type, nillable, value);
+ handleContent(type, nillable, value, valueType,
itemValueType);
fMatched[i] = 0;
}
1.20 +7 -6
xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Selector.java
Index: Selector.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Selector.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Selector.java 6 Oct 2004 15:14:51 -0000 1.19
+++ Selector.java 9 May 2005 21:03:33 -0000 1.20
@@ -1,5 +1,5 @@
/*
- * Copyright 2001, 2002,2004 The Apache Software Foundation.
+ * Copyright 2001, 2002,2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +17,12 @@
package org.apache.xerces.impl.xs.identity;
import org.apache.xerces.impl.xpath.XPathException;
-import org.apache.xerces.xs.XSTypeDefinition;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xs.ShortList;
+import org.apache.xerces.xs.XSTypeDefinition;
/**
* Schema identity constraint selector.
@@ -227,8 +228,8 @@
} // startElement(QName,XMLAttrList,int)
- public void endElement(QName element, XSTypeDefinition type, boolean
nillable, Object actualValue) {
- super.endElement(element, type, nillable, actualValue);
+ public void endElement(QName element, XSTypeDefinition type, boolean
nillable, Object actualValue, short valueType, ShortList itemValueType) {
+ super.endElement(element, type, nillable, actualValue,
valueType, itemValueType);
if (fElementDepth-- == fMatchedDepth) {
fMatchedDepth = -1;
fFieldActivator.endValueScopeFor(fIdentityConstraint,
fInitialDepth);
1.19 +57 -9
xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Field.java
Index: Field.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Field.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Field.java 6 Oct 2004 15:14:51 -0000 1.18
+++ Field.java 9 May 2005 21:03:33 -0000 1.19
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +17,13 @@
package org.apache.xerces.impl.xs.identity;
import org.apache.xerces.impl.xpath.XPathException;
-import org.apache.xerces.xs.XSComplexTypeDefinition;
-import org.apache.xerces.xs.XSTypeDefinition;
+import org.apache.xerces.impl.xs.util.ShortListImpl;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.xni.NamespaceContext;
+import org.apache.xerces.xs.ShortList;
+import org.apache.xerces.xs.XSComplexTypeDefinition;
+import org.apache.xerces.xs.XSConstants;
+import org.apache.xerces.xs.XSTypeDefinition;
/**
* Schema identity constraint field.
@@ -166,20 +169,65 @@
* This method is called when the XPath handler matches the
* XPath expression.
*/
- protected void matched(Object actualValue, boolean isNil) {
- super.matched(actualValue, isNil);
+ protected void matched(Object actualValue, short valueType,
ShortList itemValueType, boolean isNil) {
+ super.matched(actualValue, valueType, itemValueType, isNil);
if(isNil && (fIdentityConstraint.getCategory() ==
IdentityConstraint.IC_KEY)) {
String code = "KeyMatchesNillable";
fStore.reportError(code, new
Object[]{fIdentityConstraint.getElementName()});
}
- fStore.addValue(Field.this, actualValue);
+ fStore.addValue(Field.this, actualValue,
convertToPrimitiveKind(valueType), convertToPrimitiveKind(itemValueType));
// once we've stored the value for this field, we set the
mayMatch
// member to false so that, in the same scope, we don't match
any more
// values (and throw an error instead).
fFieldActivator.setMayMatch(Field.this, Boolean.FALSE);
} // matched(String)
- protected void handleContent(XSTypeDefinition type, boolean
nillable, Object actualValue) {
+ private short convertToPrimitiveKind(short valueType) {
+ switch(valueType) {
+
+ case XSConstants.ID_DT:
+ case XSConstants.IDREF_DT:
+ case XSConstants.ENTITY_DT:
+ case XSConstants.NCNAME_DT:
+ case XSConstants.NAME_DT:
+ case XSConstants.LANGUAGE_DT:
+ case XSConstants.NMTOKEN_DT:
+ case XSConstants.TOKEN_DT:
+ case XSConstants.NORMALIZEDSTRING_DT:
+ return XSConstants.STRING_DT;
+
+ case XSConstants.UNSIGNEDBYTE_DT:
+ case XSConstants.UNSIGNEDINT_DT:
+ case XSConstants.UNSIGNEDLONG_DT:
+ case XSConstants.UNSIGNEDSHORT_DT:
+ case XSConstants.BYTE_DT:
+ case XSConstants.SHORT_DT:
+ case XSConstants.INT_DT:
+ case XSConstants.POSITIVEINTEGER_DT:
+ case XSConstants.NEGATIVEINTEGER_DT:
+ case XSConstants.NONNEGATIVEINTEGER_DT:
+ case XSConstants.NONPOSITIVEINTEGER_DT:
+ case XSConstants.LONG_DT:
+ case XSConstants.INTEGER_DT:
+ return XSConstants.DECIMAL_DT;
+
+ default:
+ return valueType;
+ }
+ }
+
+ private ShortList convertToPrimitiveKind(ShortList itemValueType) {
+ if(itemValueType != null) {
+ short[] arr = new short[itemValueType.getLength()];
+ for(int i = 0;i < arr.length; i++) {
+ arr[i] = convertToPrimitiveKind(itemValueType.item(i));
+ }
+ return new ShortListImpl(arr, arr.length);
+ }
+ return itemValueType;
+ }
+
+ protected void handleContent(XSTypeDefinition type, boolean
nillable, Object actualValue, short valueType, ShortList itemValueType) {
if (type == null ||
type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE &&
((XSComplexTypeDefinition) type).getContentType()
@@ -192,7 +240,7 @@
}
fMatchedString = actualValue;
- matched(fMatchedString, nillable);
+ matched(fMatchedString, valueType, itemValueType, nillable);
} // handleContent(XSElementDecl, String)
} // class Matcher
1.167 +66 -17
xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
Index: XMLSchemaValidator.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -r1.166 -r1.167
--- XMLSchemaValidator.java 10 Feb 2005 17:07:54 -0000 1.166
+++ XMLSchemaValidator.java 9 May 2005 21:03:33 -0000 1.167
@@ -18,8 +18,8 @@
import java.io.IOException;
import java.util.Enumeration;
-import java.util.Hashtable;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Stack;
import java.util.Vector;
@@ -43,9 +43,6 @@
import org.apache.xerces.impl.xs.models.CMBuilder;
import org.apache.xerces.impl.xs.models.CMNodeFactory;
import org.apache.xerces.impl.xs.models.XSCMValidator;
-import org.apache.xerces.xs.XSConstants;
-import org.apache.xerces.xs.XSObjectList;
-import org.apache.xerces.xs.XSTypeDefinition;
import org.apache.xerces.util.AugmentationsImpl;
import org.apache.xerces.util.IntStack;
import org.apache.xerces.util.SymbolTable;
@@ -72,6 +69,12 @@
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xs.AttributePSVI;
import org.apache.xerces.xs.ElementPSVI;
+import org.apache.xerces.xs.ShortList;
+import org.apache.xerces.xs.XSConstants;
+import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSTypeDefinition;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
/**
* The XML Schema validator. The validator implements a document
@@ -333,8 +336,9 @@
// should be called when starting process an element or an attribute.
// store the starting position for the current context
public void pushContext() {
- if (!fAugPSVI)
+ if (!fAugPSVI) {
return;
+ }
// resize array if necessary
if (fContextCount == fContext.length) {
int newSize = fContextCount + INC_STACK_SIZE;
@@ -348,8 +352,9 @@
// should be called on endElement: get all errors of the current
element
public String[] popContext() {
- if (!fAugPSVI)
+ if (!fAugPSVI) {
return null;
+ }
// get starting position of the current element
int contextPos = fContext[--fContextCount];
// number of errors of the current element
@@ -371,8 +376,9 @@
// this attribute, but leave the errors to the containing element
// also called after an element was strictly assessed.
public String[] mergeContext() {
- if (!fAugPSVI)
+ if (!fAugPSVI) {
return null;
+ }
// get starting position of the current element
int contextPos = fContext[--fContextCount];
// number of errors of the current element
@@ -2120,7 +2126,7 @@
for (int i = oldCount - 1; i >= 0; i--) {
XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
if (fCurrentElemDecl == null)
- matcher.endElement(element, null, false,
fValidatedInfo.actualValue);
+ matcher.endElement(element, null, false,
fValidatedInfo.actualValue, fValidatedInfo.actualValueType,
fValidatedInfo.itemValueTypes);
else
matcher.endElement(
@@ -2129,7 +2135,13 @@
fCurrentElemDecl.getNillable(),
fDefaultValue == null
? fValidatedInfo.actualValue
- : fCurrentElemDecl.fDefault.actualValue);
+ : fCurrentElemDecl.fDefault.actualValue,
+ fDefaultValue == null
+ ? fValidatedInfo.actualValueType
+ : fCurrentElemDecl.fDefault.actualValueType,
+ fDefaultValue == null
+ ? fValidatedInfo.itemValueTypes
+ : fCurrentElemDecl.fDefault.itemValueTypes);
}
if (fMatcherStack.size() > 0) {
@@ -3249,12 +3261,18 @@
protected Field[] fFields = null;
/** current data */
protected Object[] fLocalValues = null;
+ protected int[] fLocalValueTypes = null;
+ protected ShortList[] fLocalItemValueTypes = null;
/** Current data value count. */
protected int fValuesCount;
/** global data */
public final Vector fValues = new Vector();
+
+ public final Vector fValueTypes = new Vector();
+
+ public final Vector fItemValueTypes = new Vector();
/** buffer for error messages */
final StringBuffer fTempBuffer = new StringBuffer();
@@ -3269,6 +3287,8 @@
fFieldCount = fIdentityConstraint.getFieldCount();
fFields = new Field[fFieldCount];
fLocalValues = new Object[fFieldCount];
+ fLocalValueTypes = new int[fFieldCount];
+ fLocalItemValueTypes = new ShortList[fFieldCount];
for (int i = 0; i < fFieldCount; i++) {
fFields[i] = fIdentityConstraint.getFieldAt(i);
}
@@ -3297,6 +3317,8 @@
fValuesCount = 0;
for (int i = 0; i < fFieldCount; i++) {
fLocalValues[i] = null;
+ fLocalValueTypes[i] = 0;
+ fLocalItemValueTypes[i] = null;
}
} // startValueScope()
@@ -3382,7 +3404,7 @@
* once within a selection scope.
* @param actualValue The value to add.
*/
- public void addValue(Field field, Object actualValue) {
+ public void addValue(Field field, Object actualValue, short
valueType, ShortList itemValueType) {
int i;
for (i = fFieldCount - 1; i > -1; i--) {
if (fFields[i] == field) {
@@ -3402,11 +3424,15 @@
fValuesCount++;
}
fLocalValues[i] = actualValue;
+ fLocalValueTypes[i] = valueType;
+ fLocalItemValueTypes[i] = itemValueType;
if (fValuesCount == fFieldCount) {
checkDuplicateValues();
// store values
for (i = 0; i < fFieldCount; i++) {
fValues.addElement(fLocalValues[i]);
+ fValueTypes.addElement(new Integer(fLocalValueTypes[i]));
+ fItemValueTypes.add(fLocalItemValueTypes[i]);
}
}
} // addValue(String,Field)
@@ -3423,10 +3449,19 @@
next = i + fFieldCount;
for (int j = 0; j < fFieldCount; j++) {
Object value1 = fLocalValues[j];
- Object value2 = fValues.elementAt(i++);
- if (value1 == null || value2 == null ||
!(value1.equals(value2))) {
+ Object value2 = fValues.elementAt(i);
+ int valueType1 = fLocalValueTypes[j];
+ int valueType2 =
((Integer)fValueTypes.elementAt(i)).intValue();
+ if (value1 == null || value2 == null || valueType1 !=
valueType2 || !(value1.equals(value2))) {
continue LOOP;
}
+ else if(valueType1 == XSConstants.LIST_DT || valueType1
== XSConstants.LISTOFUNION_DT) {
+ ShortList list1 = fLocalItemValueTypes[j];
+ ShortList list2 =
(ShortList)fItemValueTypes.elementAt(i);
+ if(list1 == null || list2 == null ||
!list1.equals(list2))
+ continue LOOP;
+ }
+ i++;
}
// found it
return true;
@@ -3440,14 +3475,20 @@
* values, otherwise the index of the first field in the
* key sequence.
*/
- public int contains(Vector values) {
+ public int contains(Vector values, Vector valueTypes, Vector
itemValueTypes) {
final int size1 = values.size();
if (fFieldCount <= 1) {
for (int i = 0; i < size1; ++i) {
- if (!fValues.contains(values.elementAt(i))) {
+ Integer val = (Integer)valueTypes.elementAt(i);
+ if (!fValueTypes.contains(val) ||
!fValues.contains(values.elementAt(i))) {
return i;
}
+ else if(val.intValue() == XSConstants.LIST_DT ||
val.intValue() == XSConstants.LISTOFUNION_DT) {
+ ShortList list1 =
(ShortList)itemValueTypes.elementAt(i);
+ if(!fItemValueTypes.contains(list1))
+ return i;
+ }
}
}
/** Handle n-tuples. **/
@@ -3460,9 +3501,17 @@
for (int k = 0; k < fFieldCount; ++k) {
final Object value1 = values.elementAt(i+k);
final Object value2 = fValues.elementAt(j+k);
- if (value1 != value2 && (value1 == null ||
!value1.equals(value2))) {
+ final int valueType1 =
((Integer)valueTypes.elementAt(i+k)).intValue();
+ final int valueType2 =
((Integer)fValueTypes.elementAt(j+k)).intValue();
+ if (value1 != value2 && (valueType1 !=
valueType2 || value1 == null || !value1.equals(value2))) {
continue INNER;
}
+ else if(valueType1 == XSConstants.LIST_DT ||
valueType1 == XSConstants.LISTOFUNION_DT) {
+ ShortList list1 =
(ShortList)itemValueTypes.elementAt(i+k);
+ ShortList list2 =
(ShortList)fItemValueTypes.elementAt(j+k);
+ if(list1 == null || list2 == null ||
!list1.equals(list2))
+ continue INNER;
+ }
}
continue OUTER;
}
@@ -3667,7 +3716,7 @@
reportSchemaError(code, new Object[] { value });
return;
}
- int errorIndex = fKeyValueStore.contains(fValues);
+ int errorIndex = fKeyValueStore.contains(fValues, fValueTypes,
fItemValueTypes);
if (errorIndex != -1) {
String code = "KeyNotFound";
String values = toString(fValues, errorIndex, fFieldCount);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]