You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2011/08/08 22:02:50 UTC
svn commit: r1155073 - in
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: ./
models/ traversers/
Author: knoaman
Date: Mon Aug 8 20:02:50 2011
New Revision: 1155073
URL: http://svn.apache.org/viewvc?rev=1155073&view=rev
Log:
Element Delcaration Consistent
When matching a wildcard, the type of the matched global declaration must be same or validly derived from the type of any local element delcaration with the same name
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Mon Aug 8 20:02:50 2011
@@ -410,7 +410,9 @@ public class XMLSchemaValidator
* While parsing a document, keep the location of the document.
*/
private XMLLocator fLocator;
-
+
+ private ArrayList fXSITypeErrors = new ArrayList(4);
+
private IDContext fIDContext = null;
/**
@@ -2230,6 +2232,8 @@ public class XMLSchemaValidator
}
// if no decl/type found for the current element
+ final boolean isSchema11 = (fSchemaVersion == Constants.SCHEMA_VERSION_1_1);
+ boolean needToPushErrorContext = false;
if (fCurrentType == null && xsiType == null) {
// if this is the validation root, report an error, because
// we can't find eith decl or type for this element
@@ -2289,17 +2293,35 @@ public class XMLSchemaValidator
// push error reporter context: record the current position
// This has to happen after we process skip contents,
// otherwise push and pop won't be correctly paired.
- fXSIErrorReporter.pushContext();
+ if (isSchema11) {
+ needToPushErrorContext = true;
+ }
+ else {
+ fXSIErrorReporter.pushContext();
+ }
} else {
// push error reporter context: record the current position
// This has to happen after we process skip contents,
// otherwise push and pop won't be correctly paired.
- fXSIErrorReporter.pushContext();
+ if (isSchema11) {
+ needToPushErrorContext = true;
+ }
+ else {
+ fXSIErrorReporter.pushContext();
+ }
// get xsi:type
if (xsiType != null) {
XSTypeDefinition oldType = fCurrentType;
- fCurrentType = getAndCheckXsiType(element, xsiType, attributes);
+ if (isSchema11) {
+ if (fXSITypeErrors.size() > 0) {
+ fXSITypeErrors.clear();
+ }
+ fCurrentType = getAndCheckXsiType(element, xsiType, attributes, fXSITypeErrors);
+ }
+ else {
+ fCurrentType = getAndCheckXsiType(element, xsiType, attributes);
+ }
// If it fails, use the old type. Use anyType if ther is no old type.
if (fCurrentType == null) {
if (oldType == null)
@@ -2325,6 +2347,39 @@ public class XMLSchemaValidator
}
}
+ // EDC rule
+ if (isSchema11) {
+ if (wildcard != null && fCurrentCM != null) {
+ XSElementDecl elemDecl = fCurrentCM.findMatchingElemDecl(element, fSubGroupHandler);
+ if (elemDecl != null) {
+ final XSTypeDefinition elemType = elemDecl.getTypeDefinition();
+ // types need to be equivalent
+ if (fCurrentType != elemType) {
+ short block = elemDecl.fBlock;
+ if (elemType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
+ block |= ((XSComplexTypeDecl) elemType).fBlock;
+ }
+ if (!fXSConstraints.checkTypeDerivationOk(fCurrentType, elemType, block)) {
+ reportSchemaError(
+ "cvc-elt.4.cos-element-consistent.4.a",
+ new Object[] { element.rawname, fCurrentType, elemType.getName()});
+ }
+ }
+ }
+ }
+
+ if (needToPushErrorContext) {
+ fXSIErrorReporter.pushContext();
+ final int errorSize = fXSITypeErrors.size();
+ if (errorSize > 0) {
+ for (int i=0; i<errorSize; ++i) {
+ reportSchemaError((String)fXSITypeErrors.get(i), (Object[])fXSITypeErrors.get(++i));
+ }
+ fXSITypeErrors.clear();
+ }
+ }
+ }
+
// Element Locally Valid (Element)
// 2 Its {abstract} must be false.
if (fCurrentElemDecl != null && fCurrentElemDecl.getAbstract())
@@ -3082,6 +3137,81 @@ public class XMLSchemaValidator
return type;
} //getAndCheckXsiType
+
+ XSTypeDefinition getAndCheckXsiType(QName element, String xsiType, XMLAttributes attributes,
+ ArrayList errorList) {
+ // This method also deals with clause 1.2.1.2 of the constraint
+ // Validation Rule: Schema-Validity Assessment (Element)
+
+ // Element Locally Valid (Element)
+ // 4 If there is an attribute information item among the element information item's [attributes] whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and whose [local name] is type, then all of the following must be true:
+ // 4.1 The normalized value of that attribute information item must be valid with respect to the built-in QName simple type, as defined by String Valid (3.14.4);
+ QName typeName = null;
+ try {
+ typeName = (QName) fQNameDV.validate(xsiType, fValidationState, null);
+ } catch (InvalidDatatypeValueException e) {
+ errorList.add(e.getKey());
+ errorList.add(e.getArgs());
+ errorList.add("cvc-elt.4.1");
+ errorList.add(new Object[] {
+ element.rawname,
+ SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_TYPE,
+ xsiType });
+ return null;
+ }
+
+ // 4.2 The local name and namespace name (as defined in QName Interpretation (3.15.3)), of the actual value of that attribute information item must resolve to a type definition, as defined in QName resolution (Instance) (3.15.4)
+ XSTypeDefinition type = null;
+ // if the namespace is schema namespace, first try built-in types
+ if (typeName.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA) {
+ if (isValidBuiltInTypeName(typeName.localpart)) {
+ SchemaGrammar s4s = SchemaGrammar.getS4SGrammar(fSchemaVersion);
+ type = s4s.getGlobalTypeDecl(typeName.localpart);
+ }
+ }
+ // if it's not schema built-in types, then try to get a grammar
+ if (type == null) {
+ //try to find schema grammar by different means....
+ SchemaGrammar grammar =
+ findSchemaGrammar(
+ XSDDescription.CONTEXT_XSITYPE,
+ typeName.uri,
+ element,
+ typeName,
+ attributes);
+
+ if (grammar != null)
+ type = grammar.getGlobalTypeDecl(typeName.localpart);
+ }
+ // still couldn't find the type, report an error
+ if (type == null) {
+ errorList.add("cvc-elt.4.2");
+ errorList.add(new Object[] { element.rawname, xsiType });
+ return null;
+ }
+
+ // if there is no current type, set this one as current.
+ // and we don't need to do extra checking
+ if (fCurrentType != null) {
+ short block = XSConstants.DERIVATION_NONE;
+ // 4.3 The local type definition must be validly derived from the {type definition} given the union of the {disallowed substitutions} and the {type definition}'s {prohibited substitutions}, as defined in Type Derivation OK (Complex) (3.4.6) (if it is a complex type definition), or given {disallowed substitutions} as defined in Type Derivation OK (Simple) (3.14.6) (if it is a simple type definition).
+ // Note: It's possible to have fCurrentType be non-null and fCurrentElemDecl
+ // be null, if the current type is set using the property "root-type-definition".
+ // In that case, we don't disallow any substitutions. -PM
+ if (fCurrentElemDecl != null) {
+ block = fCurrentElemDecl.fBlock;
+ }
+ if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
+ block |= ((XSComplexTypeDecl) fCurrentType).fBlock;
+ }
+ if (!fXSConstraints.checkTypeDerivationOk(type, fCurrentType, block)) {
+ errorList.add("cvc-elt.4.3");
+ errorList.add(new Object[] { element.rawname, xsiType, fCurrentType.getName()});
+ }
+ }
+
+ return type;
+ } //getAndCheckXsiType
boolean getXsiNil(QName element, String xsiNil) {
// Element Locally Valid (Element)
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java Mon Aug 8 20:02:50 2011
@@ -544,7 +544,7 @@ public abstract class XSConstraints {
}
else if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && !isTypeTablesEquivalent(elem, existingElem)) {
// Type tables are not equivalent
- throw new XMLSchemaException("cos-element-consistent.4", new Object[] {type.fName, elem.fName});
+ throw new XMLSchemaException("cos-element-consistent.4.b", new Object[] {type.fName, elem.fName});
}
}
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java Mon Aug 8 20:02:50 2011
@@ -162,7 +162,7 @@ public class XS11AllCM implements XSCMVa
}
// convenient method: to find a matching element decl
- XSElementDecl findMatchingElemDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) {
+ public XSElementDecl findMatchingElemDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) {
for (int i = 1; i < fNumElements; i++) {
final XSElementDecl matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, fElements[i], Constants.SCHEMA_VERSION_1_1);
if (matchingDecl != null) {
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java Mon Aug 8 20:02:50 2011
@@ -19,6 +19,7 @@ package org.apache.xerces.impl.xs.models
import java.util.Vector;
+import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
import org.apache.xerces.impl.xs.XMLSchemaException;
import org.apache.xerces.impl.xs.XSConstraints;
@@ -228,5 +229,16 @@ public class XSAllCM implements XSCMVali
public boolean isCompactedForUPA() {
return false;
}
+
+ public XSElementDecl findMatchingElemDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) {
+ for (int i = 1; i < fNumElements; i++) {
+ final XSElementDecl matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, fAllElements[i], Constants.SCHEMA_VERSION_1_0);
+ if (matchingDecl != null) {
+ return matchingDecl;
+ }
+ }
+
+ return null;
+ }
} // class XSAllCM
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java Mon Aug 8 20:02:50 2011
@@ -22,6 +22,7 @@ import java.util.Vector;
import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
import org.apache.xerces.impl.xs.XMLSchemaException;
import org.apache.xerces.impl.xs.XSConstraints;
+import org.apache.xerces.impl.xs.XSElementDecl;
import org.apache.xerces.impl.xs.XSElementDeclHelper;
import org.apache.xerces.xni.QName;
@@ -128,4 +129,6 @@ public interface XSCMValidator {
* @return a boolean that says whether this content has been compacted for UPA
*/
public boolean isCompactedForUPA();
+
+ public XSElementDecl findMatchingElemDecl(QName elementName, SubstitutionGroupHandler subGroupHandler);
} // XSCMValidator
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.java Mon Aug 8 20:02:50 2011
@@ -457,7 +457,7 @@ public class XSDFACM
return matchingDecl;
} // findMatchingDecl(QName, int[], SubstitutionGroupHandler, int): Object
- XSElementDecl findMatchingElemDecl(QName curElem, SubstitutionGroupHandler subGroupHandler) {
+ public XSElementDecl findMatchingElemDecl(QName curElem, SubstitutionGroupHandler subGroupHandler) {
XSElementDecl matchingDecl = null;
for (int elemIndex = 0; elemIndex < fNumElements; elemIndex++) {
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java Mon Aug 8 20:02:50 2011
@@ -208,4 +208,8 @@ public class XSEmptyCM implements XSCMVa
public XSOpenContentDecl getOpenContent() {
return fOpenContent;
}
+
+ public XSElementDecl findMatchingElemDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) {
+ return null;
+ }
} // class XSEmptyCM
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java?rev=1155073&r1=1155072&r2=1155073&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java Mon Aug 8 20:02:50 2011
@@ -1381,7 +1381,7 @@ public class XSDHandler {
String qName = currSchemaDoc.fTargetNamespace == null ?
","+lName:
currSchemaDoc.fTargetNamespace +","+lName;
- qName = XMLChar.trim(qName);
+ //qName = XMLChar.trim(qName);
String componentType = DOMUtil.getLocalName(redefineComp);
if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {
checkForDuplicateNames(qName, ATTRIBUTEGROUP_TYPE, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, redefineComp, currSchemaDoc);
@@ -1438,7 +1438,7 @@ public class XSDHandler {
String qName = currSchemaDoc.fTargetNamespace == null?
","+lName:
currSchemaDoc.fTargetNamespace +","+lName;
- qName = XMLChar.trim(qName);
+ //qName = XMLChar.trim(qName);
if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) {
checkForDuplicateNames(qName, ATTRIBUTE_TYPE, fUnparsedAttributeRegistry, fUnparsedAttributeRegistrySub, globalComp, currSchemaDoc);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org