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/12/31 22:58:20 UTC
svn commit: r730488 - in
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl: msg/
xs/ xs/identity/ xs/traversers/
Author: knoaman
Date: Wed Dec 31 13:58:19 2008
New Revision: 730488
URL: http://svn.apache.org/viewvc?rev=730488&view=rev
Log:
[Jira bug 1344] https://issues.apache.org/jira/browse/XERCESJ-1344
XML Schema 1.1 - Revised Identity Constraints. Patch by John Chan.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
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/XSElementDecl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/Field.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/IdentityConstraint.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/KeyRef.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/UniqueOrKey.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/ValueStore.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties Wed Dec 31 13:58:19 2008
@@ -128,6 +128,8 @@
src-element.4.3.1 = src-element.4.3.1: Since element ''{0}'' contains the 'targetNamespace' attribute and <schema> does not have a 'targetNamespace' attribute or its value is different from the value of 'targetNamespace' of ''{0}'', ''{0}'' must have a <complexType> as an ancestor.
src-element.4.3.2 = src-element.4.3.2: Since element ''{0}'' contains the 'targetNamespace' attribute and <schema> does not have a 'targetNamespace' attribute or its value is different from the value of 'targetNamespace' of ''{0}'', there must be a <restriction> ancestor between ''{0}'' and the nearest <complexType> ancestor, and the value of the 'base' attribute of <restriction> does not match the name of 'xs:anyType'.
src-element.5 = src-element.5: Element ''{0}'' has a type alternative with a missing ''test'' attribute. Only the last type alternative in the type table is allowed to be without a ''test'' attribute.
+ src-identity-constraint.1 = src-identity-constraint.1: One of ''ref'' or ''name'' must be present in an identity constraint declaration.
+ src-identity-constraint.5 = src-identity-constraint.5: The identity-constraint category of the identity-constraint definition resolved to by the actual value of the ''ref'' attribute does not match the name of the element information item ''{0}''.
src-import.1.1 = src-import.1.1: The namespace attribute ''{0}'' of an <import> element information item must not be the same as the targetNamespace of the schema it exists in.
src-import.1.2 = src-import.1.2: If the namespace attribute is not present on an <import> element information item then the enclosing schema must have a targetNamespace.
src-import.2 = src-import.2: The root element of document ''{0}'' has to have the namespace name ''http://www.w3.org/2001/XMLSchema'' and the local name ''schema''.
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=730488&r1=730487&r2=730488&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 Wed Dec 31 13:58:19 2008
@@ -3597,6 +3597,7 @@
protected IdentityConstraint fIdentityConstraint;
protected int fFieldCount = 0;
protected Field[] fFields = null;
+ protected String fElementName;
/** current data */
protected Object[] fLocalValues = null;
protected short[] fLocalValueTypes = null;
@@ -3626,7 +3627,8 @@
//
/** Constructs a value store for the specified identity constraint. */
- protected ValueStoreBase(IdentityConstraint identityConstraint) {
+ protected ValueStoreBase(IdentityConstraint identityConstraint, String elementName) {
+ fElementName = elementName;
fIdentityConstraint = identityConstraint;
fFieldCount = fIdentityConstraint.getFieldCount();
fFields = new Field[fFieldCount];
@@ -3684,9 +3686,8 @@
if (fValuesCount == 0) {
if (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY) {
String code = "AbsentKeyValue";
- String eName = fIdentityConstraint.getElementName();
String cName = fIdentityConstraint.getIdentityConstraintName();
- reportSchemaError(code, new Object[] { eName, cName });
+ reportSchemaError(code, new Object[] { fElementName, cName });
}
return;
}
@@ -3701,9 +3702,8 @@
if (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY) {
String code = "KeyNotEnoughValues";
UniqueOrKey key = (UniqueOrKey) fIdentityConstraint;
- String eName = fIdentityConstraint.getElementName();
String cName = key.getIdentityConstraintName();
- reportSchemaError(code, new Object[] { eName, cName });
+ reportSchemaError(code, new Object[] { fElementName, cName });
}
return;
}
@@ -3759,9 +3759,8 @@
// do we even know this field?
if (i == -1) {
String code = "UnknownField";
- String eName = fIdentityConstraint.getElementName();
String cName = fIdentityConstraint.getIdentityConstraintName();
- reportSchemaError(code, new Object[] { field.toString(), eName, cName });
+ reportSchemaError(code, new Object[] { field.toString(), fElementName, cName });
return;
}
if (!mayMatch) {
@@ -3787,6 +3786,22 @@
} // addValue(String,Field)
/**
+ * Sets the name of the element which holds the identity constraint
+ * that is stored in this value store
+ */
+ public void setElementName(String elementName) {
+ fElementName = elementName;
+ }
+
+ /**
+ * Returns the name of the element which holds the identity constraint
+ * that is stored in this value store
+ */
+ public String getElementName() {
+ return fElementName;
+ } // getElementName():String
+
+ /**
* Returns true if this value store contains the locally scoped value stores
*/
public boolean contains() {
@@ -4033,8 +4048,8 @@
//
/** Constructs a unique value store. */
- public UniqueValueStore(UniqueOrKey unique) {
- super(unique);
+ public UniqueValueStore(UniqueOrKey unique, String elementName) {
+ super(unique, elementName);
} // <init>(Unique)
//
@@ -4049,9 +4064,8 @@
if (contains()) {
String code = "DuplicateUnique";
String value = toString(fLocalValues);
- String eName = fIdentityConstraint.getElementName();
String cName = fIdentityConstraint.getIdentityConstraintName();
- reportSchemaError(code, new Object[] { value, eName, cName });
+ reportSchemaError(code, new Object[] { value, fElementName, cName });
}
} // duplicateValue(Hashtable)
@@ -4071,8 +4085,8 @@
//
/** Constructs a key value store. */
- public KeyValueStore(UniqueOrKey key) {
- super(key);
+ public KeyValueStore(UniqueOrKey key, String elementName) {
+ super(key, elementName);
} // <init>(Key)
//
@@ -4086,9 +4100,8 @@
if (contains()) {
String code = "DuplicateKey";
String value = toString(fLocalValues);
- String eName = fIdentityConstraint.getElementName();
String cName = fIdentityConstraint.getIdentityConstraintName();
- reportSchemaError(code, new Object[] { value, eName, cName });
+ reportSchemaError(code, new Object[] { value, fElementName, cName });
}
} // duplicateValue(Hashtable)
@@ -4113,8 +4126,8 @@
//
/** Constructs a key value store. */
- public KeyRefValueStore(KeyRef keyRef, KeyValueStore keyValueStore) {
- super(keyRef);
+ public KeyRefValueStore(KeyRef keyRef, KeyValueStore keyValueStore, String elementName) {
+ super(keyRef, elementName);
fKeyValueStore = keyValueStore;
} // <init>(KeyRef)
@@ -4146,9 +4159,8 @@
if (errorIndex != -1) {
String code = "KeyNotFound";
String values = toString(fValues, errorIndex, fFieldCount);
- String element = fIdentityConstraint.getElementName();
String name = fIdentityConstraint.getName();
- reportSchemaError(code, new Object[] { name, values, element });
+ reportSchemaError(code, new Object[] { name, values, fElementName });
}
} // endDocumentFragment()
@@ -4291,10 +4303,11 @@
UniqueValueStore uniqueValueStore =
(UniqueValueStore) fIdentityConstraint2ValueStoreMap.get(toHash);
if (uniqueValueStore == null) {
- uniqueValueStore = new UniqueValueStore(unique);
+ uniqueValueStore = new UniqueValueStore(unique, eDecl.getName());
fIdentityConstraint2ValueStoreMap.put(toHash, uniqueValueStore);
} else {
uniqueValueStore.clear();
+ uniqueValueStore.setElementName(eDecl.getName());
}
fValueStores.addElement(uniqueValueStore);
activateSelectorFor(icArray[i]);
@@ -4306,10 +4319,11 @@
KeyValueStore keyValueStore =
(KeyValueStore) fIdentityConstraint2ValueStoreMap.get(toHash);
if (keyValueStore == null) {
- keyValueStore = new KeyValueStore(key);
+ keyValueStore = new KeyValueStore(key, eDecl.getName());
fIdentityConstraint2ValueStoreMap.put(toHash, keyValueStore);
} else {
keyValueStore.clear();
+ keyValueStore.setElementName(eDecl.getName());
}
fValueStores.addElement(keyValueStore);
activateSelectorFor(icArray[i]);
@@ -4321,10 +4335,11 @@
KeyRefValueStore keyRefValueStore =
(KeyRefValueStore) fIdentityConstraint2ValueStoreMap.get(toHash);
if (keyRefValueStore == null) {
- keyRefValueStore = new KeyRefValueStore(keyRef, null);
+ keyRefValueStore = new KeyRefValueStore(keyRef, null, eDecl.getName());
fIdentityConstraint2ValueStoreMap.put(toHash, keyRefValueStore);
} else {
keyRefValueStore.clear();
+ keyRefValueStore.setElementName(eDecl.getName());
}
fValueStores.addElement(keyRefValueStore);
activateSelectorFor(icArray[i]);
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java Wed Dec 31 13:58:19 2008
@@ -401,6 +401,13 @@
return ((fMiscFlags & ABSTRACT) != 0);
}
+ public void addAnnotation(XSAnnotation annotation) {
+ if (fAnnotations == XSObjectListImpl.EMPTY_LIST) {
+ fAnnotations = new XSObjectListImpl();
+ }
+ ((XSObjectListImpl)fAnnotations).add(annotation);
+ }
+
/**
* Optional. Annotation.
*/
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/Field.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/Field.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/Field.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/Field.java Wed Dec 31 13:58:19 2008
@@ -234,7 +234,7 @@
if(isNil && (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY)) {
String code = "KeyMatchesNillable";
fStore.reportError(code,
- new Object[]{fIdentityConstraint.getElementName(), fIdentityConstraint.getIdentityConstraintName()});
+ new Object[]{fStore.getElementName(), fIdentityConstraint.getIdentityConstraintName()});
}
fStore.addValue(Field.this, fMayMatch, actualValue, convertToPrimitiveKind(valueType), convertToPrimitiveKind(itemValueType));
// once we've stored the value for this field, we set the mayMatch
@@ -293,7 +293,7 @@
// the content must be simpleType content
fStore.reportError( "cvc-id.3", new Object[] {
fIdentityConstraint.getName(),
- fIdentityConstraint.getElementName()});
+ fStore.getElementName()});
}
fMatchedString = actualValue;
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/IdentityConstraint.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/IdentityConstraint.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/IdentityConstraint.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/IdentityConstraint.java Wed Dec 31 13:58:19 2008
@@ -49,9 +49,6 @@
/** Identity constraint name. */
protected final String fIdentityConstraintName;
- /** name of owning element */
- protected final String fElementName;
-
/** Selector. */
protected Selector fSelector;
@@ -72,10 +69,9 @@
//
/** Default constructor. */
- protected IdentityConstraint(String namespace, String identityConstraintName, String elemName) {
+ protected IdentityConstraint(String namespace, String identityConstraintName) {
fNamespace = namespace;
fIdentityConstraintName = identityConstraintName;
- fElementName = elemName;
} // <init>(String,String)
//
@@ -116,11 +112,6 @@
return fFields[index];
} // getFieldAt(int):Field
- // get the name of the owning element
- public String getElementName () {
- return fElementName;
- } // getElementName(): String
-
//
// Object methods
//
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/KeyRef.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/KeyRef.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/KeyRef.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/KeyRef.java Wed Dec 31 13:58:19 2008
@@ -43,8 +43,8 @@
/** Constructs a keyref with the specified name. */
public KeyRef(String namespace, String identityConstraintName,
- String elemName, UniqueOrKey key) {
- super(namespace, identityConstraintName, elemName);
+ UniqueOrKey key) {
+ super(namespace, identityConstraintName);
fKey = key;
type = IC_KEYREF;
} // <init>(String,String,String)
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/UniqueOrKey.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/UniqueOrKey.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/UniqueOrKey.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/UniqueOrKey.java Wed Dec 31 13:58:19 2008
@@ -37,8 +37,8 @@
/** Constructs a unique or a key identity constraint. */
public UniqueOrKey(String namespace, String identityConstraintName,
- String elemName, short type) {
- super(namespace, identityConstraintName, elemName);
+ short type) {
+ super(namespace, identityConstraintName);
this.type = type;
} // <init>(String,String)
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/ValueStore.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/ValueStore.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/ValueStore.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/identity/ValueStore.java Wed Dec 31 13:58:19 2008
@@ -67,5 +67,16 @@
*/
public void reportError(String key, Object[] args);
+ /**
+ * Sets the name of the element which holds the identity constraint
+ * @param elemenName The name of the element which holds the identity constraint.
+ */
+ public void setElementName(String elementName);
+
+ /**
+ * @return the name of the element which holds the identity constraint that is stored in this value store
+ */
+ public String getElementName();
+
} // interface ValueStore
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java Wed Dec 31 13:58:19 2008
@@ -79,6 +79,9 @@
private static final String ELEMENT_R = "element_r";
private static final String ATTRIBUTE_N = "attribute_n";
private static final String ATTRIBUTE_R = "attribute_r";
+ private static final String UNIQUE_R = "unique_r";
+ private static final String KEY_R = "key_r";
+ private static final String KEYREF_R = "keyref_r";
private static int ATTIDX_COUNT = 0;
public static final int ATTIDX_ABSTRACT = ATTIDX_COUNT++;
@@ -825,7 +828,7 @@
attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]);
fEleAttrsMapL.put(SchemaSymbols.ELT_ANY, attrList);
- // for element "unique" - local
+ // for element "unique" with the name attribute - local
attrList = Container.getContainer(2);
// id = ID
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
@@ -852,6 +855,18 @@
// XML Schema 1.1
fEleAttrs11MapL.put(SchemaSymbols.ELT_KEYREF, attrList);
+ // for element "unique" with the ref attribute
+ attrList = Container.getContainer(2);
+ // id = ID
+ attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
+ // ref = QName
+ attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]);
+ fEleAttrs11MapL.put(UNIQUE_R, attrList);
+ // for element "key" with the ref attribute - same list
+ fEleAttrs11MapL.put(KEY_R, attrList);
+ // for element "keyref" with the ref attribute - same list
+ fEleAttrs11MapL.put(KEYREF_R, attrList);
+
// for element "selector" - local
attrList = Container.getContainer(2);
// id = ID
@@ -1370,6 +1385,13 @@
lookupName = ATTRIBUTE_R;
else
lookupName = ATTRIBUTE_N;
+ } else if (fSchemaHandler.fSchemaVersion==Constants.SCHEMA_VERSION_1_1 && DOMUtil.getAttr(element, SchemaSymbols.ATT_REF)!=null) {
+ if (elName.equals(SchemaSymbols.ELT_UNIQUE))
+ lookupName = UNIQUE_R;
+ else if (elName.equals(SchemaSymbols.ELT_KEY))
+ lookupName = KEY_R;
+ else if (elName.equals(SchemaSymbols.ELT_KEYREF))
+ lookupName = KEYREF_R;
}
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java Wed Dec 31 13:58:19 2008
@@ -18,12 +18,17 @@
package org.apache.xerces.impl.xs.traversers;
import org.apache.xerces.impl.xpath.XPathException;
+import org.apache.xerces.impl.xs.SchemaGrammar;
import org.apache.xerces.impl.xs.SchemaSymbols;
+import org.apache.xerces.impl.xs.XSElementDecl;
import org.apache.xerces.impl.xs.identity.Field;
import org.apache.xerces.impl.xs.identity.IdentityConstraint;
import org.apache.xerces.impl.xs.identity.Selector;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
import org.apache.xerces.util.DOMUtil;
import org.apache.xerces.util.XMLChar;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xs.XSAnnotation;
import org.w3c.dom.Element;
/**
@@ -181,5 +186,81 @@
}
} // traverseIdentityConstraint(IdentityConstraint,Element, XSDocumentInfo)
+
+ void traverseIdentityConstraintReferral(Element icElem, XSElementDecl element,
+ XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
+
+ // General Attribute Checking
+ Object[] attrValues = fAttrChecker.checkAttributes(icElem, false, schemaDoc);
+ QName referredIcQName = (QName)attrValues[XSAttributeChecker.ATTIDX_REF];
+
+ IdentityConstraint referredIc = (IdentityConstraint)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.IDENTITYCONSTRAINT_TYPE, referredIcQName, icElem);
+ // TODO: If the referredIc had a problem such as the refer attribute did not resolve to a unique/key,
+ // the referredIc will not have been built but it will be hidden.
+ // When we try to get its declaration, it will display Internal error.
+ // Same thing happens when a keyref has refer attribute which is its own name. But the internal error would be correct.
+
+ if (referredIc == null) {
+ fAttrChecker.returnAttrArray(attrValues, schemaDoc);
+ return;
+ }
+
+ short referralIcCategory;
+ String icCategoryName = DOMUtil.getLocalName(icElem);
+
+ // Check that the category of referred ic is same as this
+ if (icCategoryName.equals(SchemaSymbols.ELT_UNIQUE)) {
+ referralIcCategory = IdentityConstraint.IC_UNIQUE;
+ } else if (icCategoryName.equals(SchemaSymbols.ELT_KEY)) {
+ referralIcCategory = IdentityConstraint.IC_KEY;
+ } else {
+ referralIcCategory = IdentityConstraint.IC_KEYREF;
+ }
+
+ if (referredIc.getCategory() != referralIcCategory) {
+ reportSchemaError("src-identity-constraint.5", new Object[]{DOMUtil.getLocalName(icElem)}, icElem);
+ fAttrChecker.returnAttrArray(attrValues, schemaDoc);
+ return;
+ }
+
+ // Check ic structure; the only child allowed is annotation
+ Element annoElem = DOMUtil.getFirstChildElement(icElem);
+ if (annoElem != null) {
+ if (DOMUtil.getLocalName(annoElem).equals(SchemaSymbols.ELT_ANNOTATION)) {
+ // when annotation is found, we add it to the annotation list of the enclosing element directly
+ element.addAnnotation(traverseAnnotationDecl(annoElem, attrValues, false, schemaDoc));
+ annoElem = DOMUtil.getNextSiblingElement(annoElem);
+ } else {
+ reportSchemaError("s4s-elt-must-match.1", new Object [] {icElem.getLocalName(), "(annotation?)", DOMUtil.getLocalName(annoElem)}, annoElem);
+ return;
+ }
+ if (annoElem != null) {
+ reportSchemaError("s4s-elt-must-match.1", new Object [] {icElem.getLocalName(), "(annotation?)", DOMUtil.getLocalName(annoElem)}, annoElem);
+ return;
+ }
+ } else {
+ String text = DOMUtil.getSyntheticAnnotation(icElem);
+ if (text != null) {
+ element.addAnnotation(traverseSyntheticAnnotation(icElem, text, attrValues, false, schemaDoc));
+ }
+ }
+
+ // Add the annotations of the ic to the enclosing element
+ /*XSObjectListImpl annotationsList = (XSObjectListImpl)referredIc.getAnnotations();
+ if (annotationsList != XSObjectListImpl.EMPTY_LIST) {
+ // copy the ic annotations into the enclosing element
+ for (int i=0; i<annotationsList.getLength(); i++) {
+ element.addAnnotation((XSAnnotation)annotationsList.item(i));
+ }
+ }*/
+
+ // add ic reference to element decl
+ // and stuff this in the grammar
+ grammar.addIDConstraintDecl(element, referredIc);
+
+ // and put back attributes
+ fAttrChecker.returnAttrArray(attrValues, schemaDoc);
+ } // traverseIdentityConstraintReferral(Element, XSElementDecl, XSDocumentInfo, SchemaGrammar)
+
} // XSDAbstractIDConstraintTraverser
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java Wed Dec 31 13:58:19 2008
@@ -440,7 +440,12 @@
childName.equals(SchemaSymbols.ELT_KEYREF) ||
childName.equals(SchemaSymbols.ELT_UNIQUE))) {
- if (childName.equals(SchemaSymbols.ELT_KEY) ||
+ // if the identity constraint contains the ref attribute,
+ // defer traversal until all the named identity constraints have been traversed
+ if (DOMUtil.getAttr(child, SchemaSymbols.ATT_REF) != null) {
+ fSchemaHandler.storeIdentityConstraintReferral(child, schemaDoc, element);
+ }
+ else if (childName.equals(SchemaSymbols.ELT_KEY) ||
childName.equals(SchemaSymbols.ELT_UNIQUE)) {
// need to set <key>/<unique> to hidden before traversing it,
// because it has global scope
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=730488&r1=730487&r2=730488&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 Wed Dec 31 13:58:19 2008
@@ -419,6 +419,21 @@
private XSDocumentInfo [] fKeyrefsMapXSDocumentInfo = new XSDocumentInfo[INIT_KEYREF_STACK];
private XSElementDecl [] fKeyrefElems = new XSElementDecl [INIT_KEYREF_STACK];
private String [][] fKeyrefNamespaceContext = new String[INIT_KEYREF_STACK][1];
+
+ // these data members are needed for the deferred traversal
+ // of referral identity constraints.
+
+ // the initial size of the array to store deferred referral identity constraints
+ private static final int INIT_IC_REFERRAL_STACK = 2;
+ // the incremental size of the array to store deferred referral identity constraints
+ private static final int INC_IC_REFERRAL_STACK_AMOUNT = 2;
+ // current position of the array (# of deferred referral identity constraints)
+ private int fICReferralStackPos = 0;
+
+ private Element[] fICReferrals = new Element[INIT_IC_REFERRAL_STACK];
+ private XSDocumentInfo [] fICReferralsMapXSDocumentInfo = new XSDocumentInfo[INIT_IC_REFERRAL_STACK];
+ private XSElementDecl [] fICReferralElems = new XSElementDecl [INIT_IC_REFERRAL_STACK];
+ private String [][] fICReferralNamespaceContext = new String[INIT_IC_REFERRAL_STACK][1];
// Constructors
public XSDHandler(short schemaVersion, XSConstraints xsConstraints){
@@ -562,11 +577,14 @@
// fifth phase: handle Keyrefs
resolveKeyRefs();
- // sixth phase: validate attribute of non-schema namespaces
+ // sixth phase: handle identity constraint referral declarations
+ resolveIdentityConstraintReferrals();
+
+ // seventh phase: validate attribute of non-schema namespaces
// REVISIT: skip this for now. we really don't want to do it.
//fAttributeChecker.checkNonSchemaAttributes(fGrammarBucket);
- // seventh phase: store imported grammars
+ // eighth phase: store imported grammars
// for all grammars with <import>s
for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
// get its target namespace
@@ -1623,6 +1641,24 @@
fKeyrefTraverser.traverse(fKeyrefs[i], fKeyrefElems[i], keyrefSchemaDoc, keyrefGrammar);
}
} // end resolveKeyRefs
+
+ // In xsd 1.1, identity constraint declarations can refer to other identity constraints.
+ // Because we do not wish to traverse all our DOM trees looking for ID constraints while
+ // we're building our global name registries, we need to resolve identity constraint
+ // referrals after all named identity constraints parsing have been complete.
+ protected void resolveIdentityConstraintReferrals() {
+ for (int i=0; i<fICReferralStackPos; i++) {
+ XSDocumentInfo icReferralSchemaDoc = fICReferralsMapXSDocumentInfo[i];
+ icReferralSchemaDoc.fNamespaceSupport.makeGlobal();
+ icReferralSchemaDoc.fNamespaceSupport.setEffectiveContext( fICReferralNamespaceContext[i] );
+ SchemaGrammar icReferralGrammar = fGrammarBucket.getGrammar(icReferralSchemaDoc.fTargetNamespace);
+ // need to set the identity constraint to hidden before traversing it,
+ // because it has global scope
+ DOMUtil.setHidden(fICReferrals[i], fHiddenNodes);
+ // using the uniqueOrKey traverser to access the method located in abstractIDConstraintTraverser
+ fUniqueOrKeyTraverser.traverseIdentityConstraintReferral(fICReferrals[i], fICReferralElems[i], icReferralSchemaDoc, icReferralGrammar);
+ }
+ } // end resolveIdentityConstraintReferrals
// an accessor method. Just makes sure callers
// who want the Identity constraint registry vaguely know what they're about.
@@ -1671,7 +1707,32 @@
fKeyrefsMapXSDocumentInfo[fKeyrefStackPos++] = schemaDoc;
} // storeKeyref (Element, XSDocumentInfo, XSElementDecl): void
-
+
+ // This method squirrels away referral identity cosntraint declarations (for xsd 1.1) along with the element
+ // decls and namespace bindings they might find handy.
+ protected void storeIdentityConstraintReferral (Element icToStore, XSDocumentInfo schemaDoc,
+ XSElementDecl currElemDecl) {
+ // set up all the registries we'll need...
+ if (fICReferralStackPos == fICReferrals.length) {
+ Element [] elemArray = new Element [fICReferralStackPos + INC_IC_REFERRAL_STACK_AMOUNT];
+ System.arraycopy(fICReferrals, 0, elemArray, 0, fICReferralStackPos);
+ fICReferrals = elemArray;
+ XSElementDecl [] declArray = new XSElementDecl [fICReferralStackPos + INC_IC_REFERRAL_STACK_AMOUNT];
+ System.arraycopy(fICReferralElems, 0, declArray, 0, fICReferralStackPos);
+ fICReferralElems = declArray;
+ String[][] stringArray = new String [fICReferralStackPos + INC_IC_REFERRAL_STACK_AMOUNT][];
+ System.arraycopy(fICReferralNamespaceContext, 0, stringArray, 0, fICReferralStackPos);
+ fICReferralNamespaceContext = stringArray;
+
+ XSDocumentInfo [] xsDocumentInfo = new XSDocumentInfo [fICReferralStackPos + INC_IC_REFERRAL_STACK_AMOUNT];
+ System.arraycopy(fICReferralsMapXSDocumentInfo, 0, xsDocumentInfo, 0, fICReferralStackPos);
+ fICReferralsMapXSDocumentInfo = xsDocumentInfo;
+ }
+ fICReferrals[fICReferralStackPos] = icToStore;
+ fICReferralElems[fICReferralStackPos] = currElemDecl;
+ fICReferralNamespaceContext[fICReferralStackPos] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext();
+ fICReferralsMapXSDocumentInfo[fICReferralStackPos++] = schemaDoc;
+ } // storeIdentityConstraintReferral (Element, XSDocumentInfo, XSElementDecl): void
/**
* resolveSchema method is responsible for resolving location of the schema (using XMLEntityResolver),
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java Wed Dec 31 13:58:19 2008
@@ -81,7 +81,7 @@
return;
}
- KeyRef keyRef = new KeyRef(schemaDoc.fTargetNamespace, krName, element.fName, key);
+ KeyRef keyRef = new KeyRef(schemaDoc.fTargetNamespace, krName, key);
// add to element decl
traverseIdentityConstraint(keyRef, krElem, schemaDoc, attrValues);
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java?rev=730488&r1=730487&r2=730488&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java Wed Dec 31 13:58:19 2008
@@ -60,9 +60,9 @@
UniqueOrKey uniqueOrKey = null;
if(DOMUtil.getLocalName(uElem).equals(SchemaSymbols.ELT_UNIQUE)) {
- uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace, uName, element.fName, IdentityConstraint.IC_UNIQUE);
+ uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace, uName, IdentityConstraint.IC_UNIQUE);
} else {
- uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace, uName, element.fName, IdentityConstraint.IC_KEY);
+ uniqueOrKey = new UniqueOrKey(schemaDoc.fTargetNamespace, uName, IdentityConstraint.IC_KEY);
}
// it's XSDElementTraverser's job to ensure that there's no
// duplication (or if there is that restriction is involved
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org