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 2008/09/15 18:48:13 UTC
svn commit: r695545 - in
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs:
XMLSchemaValidator.java XSWildcardDecl.java models/CMBuilder.java
models/XSDFACM.java
Author: knoaman
Date: Mon Sep 15 09:48:12 2008
New Revision: 695545
URL: http://svn.apache.org/viewvc?rev=695545&view=rev
Log:
Add validation support for XML Schema 1.1 open content
NOTE: for <all>, support will be included with the <all> model group changes
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/XSWildcardDecl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/CMBuilder.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.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=695545&r1=695544&r2=695545&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 Sep 15 09:48:12 2008
@@ -1834,7 +1834,7 @@
if (fSkipValidationDepth >= 0) {
fElementDepth++;
if (fAugPSVI)
- augs = getEmptyAugs(augs);
+ augs = getEmptyAugs(augs);
return augs;
}
@@ -1908,6 +1908,8 @@
if (decl != null) {
if (decl instanceof XSElementDecl) {
fCurrentElemDecl = (XSElementDecl) decl;
+ } else if (decl instanceof XSOpenContentDecl) {
+ wildcard = (XSWildcardDecl) ((XSOpenContentDecl)decl).getWildcard();
} else {
wildcard = (XSWildcardDecl) decl;
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java?rev=695545&r1=695544&r2=695545&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java Mon Sep 15 09:48:12 2008
@@ -25,6 +25,7 @@
import org.apache.xerces.xs.XSWildcard;
import org.apache.xerces.impl.xs.util.StringListImpl;
import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.xni.QName;
/**
* The XML representation for a wildcard declaration
@@ -112,6 +113,16 @@
}
/**
+ * XML Schema 1.1
+ *
+ * Validation Rule: Wildcard allows QName
+ */
+ public boolean allowQName(QName name) {
+ // TODO: apply 1.1 rules
+ return allowNamespace(name.uri);
+ }
+
+ /**
* Schema Component Constraint: Wildcard Subset
*/
public boolean isSubsetOf(XSWildcardDecl superWildcard) {
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/CMBuilder.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/CMBuilder.java?rev=695545&r1=695544&r2=695545&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/CMBuilder.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/CMBuilder.java Mon Sep 15 09:48:12 2008
@@ -24,6 +24,7 @@
import org.apache.xerces.impl.xs.XSDeclarationPool;
import org.apache.xerces.impl.xs.XSElementDecl;
import org.apache.xerces.impl.xs.XSModelGroupImpl;
+import org.apache.xerces.impl.xs.XSOpenContentDecl;
import org.apache.xerces.impl.xs.XSParticleDecl;
/**
@@ -100,7 +101,7 @@
cmValidator = createAllCM(particle);
}
else {
- cmValidator = createDFACM(particle, forUPA);
+ cmValidator = createDFACM(particle, forUPA, (XSOpenContentDecl) typeDecl.getOpenContent());
}
//now we are throught building content model and have passed sucessfully of the nodecount check
@@ -132,7 +133,7 @@
return allContent;
}
- XSCMValidator createDFACM(XSParticleDecl particle, boolean forUPA) {
+ XSCMValidator createDFACM(XSParticleDecl particle, boolean forUPA, XSOpenContentDecl openContent) {
fLeafCount = 0;
fParticleCount = 0;
// convert particle tree to CM tree
@@ -140,7 +141,7 @@
if (node == null)
return null;
// build DFA content model from the CM tree
- return new XSDFACM(node, fLeafCount);
+ return new XSDFACM(node, fLeafCount, fSchemaVersion, openContent);
}
// 1. convert particle tree to CM tree:
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=695545&r1=695544&r2=695545&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 Sep 15 09:48:12 2008
@@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.Vector;
+import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.dtd.models.CMNode;
import org.apache.xerces.impl.dtd.models.CMStateSet;
import org.apache.xerces.impl.xs.SchemaSymbols;
@@ -28,6 +29,7 @@
import org.apache.xerces.impl.xs.XSConstraints;
import org.apache.xerces.impl.xs.XSElementDecl;
import org.apache.xerces.impl.xs.XSModelGroupImpl;
+import org.apache.xerces.impl.xs.XSOpenContentDecl;
import org.apache.xerces.impl.xs.XSParticleDecl;
import org.apache.xerces.impl.xs.XSWildcardDecl;
import org.apache.xerces.xni.QName;
@@ -58,6 +60,9 @@
/** Set to true to debug content model validation. */
private static final boolean DEBUG_VALIDATE_CONTENT = false;
+ // open content - suffix mode
+ private static final short STATE_SUFFIX = 1;
+
//
// Data
//
@@ -137,6 +142,16 @@
private int fTransTable[][] = null;
/**
+ * The open content model
+ */
+ private XSOpenContentDecl fOpenContent = null;
+
+ /**
+ * The XML Schema version
+ */
+ private short fSchemaVersion;
+
+ /**
* Array containing occurence information for looping states
* which use counters to check minOccurs/maxOccurs.
*/
@@ -181,12 +196,18 @@
* @exception RuntimeException Thrown if DFA can't be built.
*/
- public XSDFACM(CMNode syntaxTree, int leafCount) {
+ public XSDFACM(CMNode syntaxTree, int leafCount, short schemaVersion, XSOpenContentDecl openContent) {
// Store away our index and pools in members
fLeafCount = leafCount;
fIsCompactedForUPA = syntaxTree.isCompactedForUPA();
+ // Store the XML Schema version
+ fSchemaVersion = schemaVersion;
+
+ // Store open content
+ fOpenContent = openContent;
+
//
// Create some string pool indexes that represent the names of some
// magical nodes in the syntax tree.
@@ -253,15 +274,28 @@
if(curState == XSCMValidator.FIRST_ERROR || curState == XSCMValidator.SUBSEQUENT_ERROR) {
// there was an error last time; so just go find correct Object in fElemmMap.
// ... after resetting state[0].
- if(curState == XSCMValidator.FIRST_ERROR)
+ if (curState == XSCMValidator.FIRST_ERROR) {
state[0] = XSCMValidator.SUBSEQUENT_ERROR;
+ }
return findMatchingDecl(curElem, subGroupHandler);
}
+ // apply open content - suffix mode
+ else if (state[3] == STATE_SUFFIX) {
+ if (fOpenContent.fWildcard.allowQName(curElem)) {
+ return fOpenContent;
+ }
+ else {
+ state[1] = curState;
+ state[0] = XSCMValidator.FIRST_ERROR;
+ return findMatchingDecl(curElem, subGroupHandler);
+ }
+ }
int nextState = 0;
int elemIndex = 0;
Object matchingDecl = null;
+ boolean toMatchElementDecl = false;
for (; elemIndex < fElemMapSize; elemIndex++) {
nextState = fTransTable[curState][elemIndex];
@@ -277,14 +311,69 @@
else if (type == XSParticleDecl.PARTICLE_WILDCARD) {
if (((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri)) {
matchingDecl = fElemMap[elemIndex];
+ // XML Schema 1.1 - and element has precedence over a wildcard
+ // if no occurences or we reached minOccurs, keep looking for
+ // and element declaration
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+ if (fCountingStates == null || fCountingStates[curState] == null || state[2] == fCountingStates[curState].minOccurs) {
+ toMatchElementDecl = true;
+ }
+ }
break;
}
}
}
+ // XML Schema 1.1
+ // We matched against a wildcard, but need to also check
+ // if we can find a matching element declaration
+ if (toMatchElementDecl) {
+ int newState = 0;
+ Object newMatchingDecl = null;
+ while (++elemIndex < fElemMapSize) {
+ newState = fTransTable[curState][elemIndex];
+ if (newState != -1 && fElemMapType[elemIndex] == XSParticleDecl.PARTICLE_ELEMENT) {
+ newMatchingDecl = subGroupHandler.getMatchingElemDecl(curElem, (XSElementDecl)fElemMap[elemIndex]);
+ if (newMatchingDecl != null) {
+ matchingDecl = newMatchingDecl;
+ nextState = newState;
+ break;
+ }
+ }
+ }
+ }
+
// if we still can't find a match, set the state to first_error
// and return null
- if (elemIndex == fElemMapSize) {
+ if (matchingDecl == null) {
+ // XML Schema 1.1
+ // Validate against Open Content
+ if (fOpenContent != null) {
+ // if suffix mode, we should have reached a final state
+ if (fOpenContent.fMode == XSOpenContentDecl.MODE_SUFFIX) {
+ if (fFinalStateFlags[curState]) {
+ if (fCountingStates != null) {
+ Occurence o = fCountingStates[curState];
+ if (o != null && state[2] < o.minOccurs) {
+ // not enough loops on the current state to be considered final.
+ state[1] = state[0];
+ state[0] = XSCMValidator.FIRST_ERROR;
+ return findMatchingDecl(curElem, subGroupHandler);
+ }
+ }
+ state[3] = STATE_SUFFIX;
+ }
+ else {
+ state[1] = state[0];
+ state[0] = XSCMValidator.FIRST_ERROR;
+ return findMatchingDecl(curElem, subGroupHandler);
+ }
+ }
+ if (fOpenContent.fWildcard.allowQName(curElem)) {
+ return fOpenContent;
+ }
+ }
+
state[1] = state[0];
state[0] = XSCMValidator.FIRST_ERROR;
return findMatchingDecl(curElem, subGroupHandler);
@@ -366,8 +455,9 @@
}
}
else if (type == XSParticleDecl.PARTICLE_WILDCARD) {
- if(((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri))
+ if (((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri)) {
return fElemMap[elemIndex];
+ }
}
}
@@ -422,14 +512,15 @@
// [1] : if [0] is an error state then the
// last valid state before the error
// [2] : occurence counter for counting states
- return new int [3];
+ // [3] : suffix state of open conten
+ return new int [4];
} // startContentModel():int[]
// this method returns whether the last state was a valid final state
public boolean endContentModel(int[] state) {
final int curState = state[0];
if (fFinalStateFlags[curState]) {
- if (fCountingStates != null) {
+ if (fCountingStates != null && state[3] != STATE_SUFFIX) {
Occurence o = fCountingStates[curState];
if (o != null && state[2] < o.minOccurs) {
// not enough loops on the current state to be considered final.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org