You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2001/02/20 07:12:29 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema/identity Field.java IdentityConstraint.java Key.java KeyRef.java Unique.java XPathMatcher.java
andyc 01/02/19 22:12:29
Modified: java/src/org/apache/xerces/msg SchemaMessages.java
java/src/org/apache/xerces/validators/common
XMLValidator.java
java/src/org/apache/xerces/validators/schema
SchemaMessageProvider.java TraverseSchema.java
java/src/org/apache/xerces/validators/schema/identity
Field.java IdentityConstraint.java Key.java
KeyRef.java Unique.java XPathMatcher.java
Log:
Fixed some problems with the identity constraint support.
There is still a lot of work to do and I'm waiting for
some clarifications from Schema working group.
Revision Changes Path
1.9 +2 -1 xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java
Index: SchemaMessages.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SchemaMessages.java 2001/02/09 21:47:11 1.8
+++ SchemaMessages.java 2001/02/20 06:12:27 1.9
@@ -63,7 +63,7 @@
* This file contains error and warning messages for the Schema validator
* The messages are arranged in key and value tuples in a ListResourceBundle.
*
- * @version $Id: SchemaMessages.java,v 1.8 2001/02/09 21:47:11 neilg Exp $
+ * @version $Id: SchemaMessages.java,v 1.9 2001/02/20 06:12:27 andyc Exp $
*/
public class SchemaMessages extends ListResourceBundle {
/** The list resource bundle contents. */
@@ -106,6 +106,7 @@
{ "DuplicateKey", "Duplicate key value [{0}] declared for identity constraint of element \"{1}\"." },
{ "KeyNotFound", "Key with value [{0}] not found for identity constraint of element \"{1}\"." },
{ "UnknownField", "Internal identity constraint error; unknown field \"{0}\"." },
+ { "KeyRefReferNotFound", "Key reference declaration \"{0}\" refers to unknown key with name \"{1}\"." },
};
/** Returns the list resource bundle contents. */
1.118 +101 -5 xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java
Index: XMLValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -r1.117 -r1.118
--- XMLValidator.java 2001/02/16 22:58:02 1.117
+++ XMLValidator.java 2001/02/20 06:12:27 1.118
@@ -121,7 +121,7 @@
/**
* This class is the super all-in-one validator used by the parser.
*
- * @version $Id: XMLValidator.java,v 1.117 2001/02/16 22:58:02 elena Exp $
+ * @version $Id: XMLValidator.java,v 1.118 2001/02/20 06:12:27 andyc Exp $
*/
public final class XMLValidator
implements DefaultEntityHandler.EventHandler,
@@ -808,6 +808,17 @@
}
fDatatypeBuffer.append(chars, offset, length);
fDocumentHandler.characters(chars, offset, length);
+
+ // call all active identity constraints
+ int count = fMatcherStack.getMatcherCount();
+ for (int i = 0; i < count; i++) {
+ XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
+ if (DEBUG_IDENTITY_CONSTRAINTS) {
+ String text = new String(chars, offset, length);
+ System.out.println("<IC>: "+matcher.toString()+"#characters("+text+")");
+ }
+ matcher.characters(chars, offset, length);
+ }
}
fTrailing = (spaces > 1)?true:false;
fFirstChunk = false;
@@ -818,6 +829,17 @@
fFirstChunk = false;
fDocumentHandler.characters(chars, offset, length);
+
+ // call all active identity constraints
+ int count = fMatcherStack.getMatcherCount();
+ for (int i = 0; i < count; i++) {
+ XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
+ if (DEBUG_IDENTITY_CONSTRAINTS) {
+ String text = new String(chars, offset, length);
+ System.out.println("<IC>: "+matcher.toString()+"#characters("+text+")");
+ }
+ matcher.characters(chars, offset, length);
+ }
}
/** Process characters. */
@@ -852,6 +874,23 @@
}
}
fDocumentHandler.characters(data);
+
+ // call all active identity constraints
+ int count = fMatcherStack.getMatcherCount();
+ if (count > 0) {
+ String text = fStringPool.toString(data);
+ char[] chars = new char[text.length()];
+ int offset = 0;
+ int length = chars.length;
+ text.getChars(length, length, chars, offset);
+ for (int i = 0; i < count; i++) {
+ XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
+ if (DEBUG_IDENTITY_CONSTRAINTS) {
+ System.out.println("<IC>: "+matcher.toString()+"#characters("+text+")");
+ }
+ matcher.characters(chars, offset, length);
+ }
+ }
}
/** Process whitespace. */
@@ -869,6 +908,17 @@
charDataInContent();
}
fDocumentHandler.characters(chars, offset, length);
+
+ // call all active identity constraints
+ int count = fMatcherStack.getMatcherCount();
+ for (int i = 0; i < count; i++) {
+ XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
+ if (DEBUG_IDENTITY_CONSTRAINTS) {
+ String text = new String(chars, offset, length);
+ System.out.println("<IC>: "+matcher.toString()+"#characters("+text+")");
+ }
+ matcher.characters(chars, offset, length);
+ }
}
} // processWhitespace(char[],int,int)
@@ -887,6 +937,23 @@
charDataInContent();
}
fDocumentHandler.characters(data);
+
+ // call all active identity constraints
+ int count = fMatcherStack.getMatcherCount();
+ if (count > 0) {
+ String text = fStringPool.toString(data);
+ char[] chars = new char[text.length()];
+ int offset = 0;
+ int length = chars.length;
+ text.getChars(length, length, chars, offset);
+ for (int i = 0; i < count; i++) {
+ XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
+ if (DEBUG_IDENTITY_CONSTRAINTS) {
+ System.out.println("<IC>: "+matcher.toString()+"#characters("+text+")");
+ }
+ matcher.characters(chars, offset, length);
+ }
+ }
}
} // processWhitespace(int)
@@ -1450,6 +1517,17 @@
fDocumentHandler.characters(index);
}
+ // call all active identity constraints
+ int matcherCount = fMatcherStack.getMatcherCount();
+ for (int i = 0; i < matcherCount; i++) {
+ XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
+ if (DEBUG_IDENTITY_CONSTRAINTS) {
+ String text = new String(fCharRefData, 0, count);
+ System.out.println("<IC>: "+matcher.toString()+"#characters("+text+")");
+ }
+ matcher.characters(fCharRefData, 0, count);
+ }
+
} // callCharacters(int)
/** Call processing instruction. */
@@ -4183,6 +4261,18 @@
System.out.println("<VS>: "+toString()+"#endValueScope()");
}
+ // is there anything to do?
+ // REVISIT: This check solves the problem with field matchers
+ // that get activated because they are at the same
+ // level as the declaring element (e.g. selector xpath
+ // is ".") but never match.
+ // However, this doesn't help us catch the problem
+ // when we expect a field value but never see it. A
+ // better solution has to be found. -Ac
+ if (fValuesCount == 0) {
+ return;
+ }
+
// do we have enough values?
if (fValuesCount != fIdentityConstraint.getFieldCount()) {
switch (fIdentityConstraint.getType()) {
@@ -4196,7 +4286,7 @@
int code = SchemaMessageProvider.KeyNotEnoughValues;
Key key = (Key)fIdentityConstraint;
String ename = fIdentityConstraint.getElementName();
- String kname = key.getName();
+ String kname = key.getIdentityConstraintName();
reportSchemaError(code, new Object[]{ename,kname});
break;
}
@@ -4204,7 +4294,7 @@
int code = SchemaMessageProvider.KeyRefNotEnoughValues;
KeyRef keyref = (KeyRef)fIdentityConstraint;
String ename = fIdentityConstraint.getElementName();
- String kname = keyref.getName();
+ String kname = keyref.getReferName();
reportSchemaError(code, new Object[]{ename,kname});
break;
}
@@ -4213,12 +4303,14 @@
}
// is this value as a group duplicated?
+//System.out.println("+++ "+toString()+" checking for duplications");
if (contains(fValues)) {
duplicateValue(fValues);
}
// store values
Hashtable values = (Hashtable)fValues.clone();
+//System.out.println("+++ "+toString()+" adding values "+values);
fValueTuples.addElement(values);
} // endValueScope()
@@ -4270,6 +4362,7 @@
}
// store value
+//System.out.println("+++ "+toString()+".addValue("+value+')');
fValuesCount++;
fValues.put(field, value);
@@ -4467,6 +4560,7 @@
// ValueStoreBase methods
//
+ /** End document. */
public void endDocument() throws Exception {
super.endDocument();
@@ -4474,6 +4568,8 @@
int count = fValueTuples.size();
for (int i = 0; i < count; i++) {
Hashtable values = (Hashtable)fValueTuples.elementAt(i);
+ System.out.println(">>> fKeyValueStore: "+fKeyValueStore);
+ System.out.println(">>> values: "+values);
if (!fKeyValueStore.contains(values)) {
int code = SchemaMessageProvider.KeyNotFound;
String value = toString(values);
@@ -4582,7 +4678,7 @@
if (valueStore == null) {
valueStore = new KeyValueStore(key);
fValueStores.addElement(valueStore);
- keyHash.put(key.getName(), valueStore);
+ keyHash.put(key.getIdentityConstraintName(), valueStore);
}
if (DEBUG_VALUE_STORES) {
System.out.println("<VS>: "+key+" -> "+valueStore);
@@ -4597,7 +4693,7 @@
int krcount = krvector.size();
for (int i = 0; i < krcount; i++) {
KeyRef keyRef = (KeyRef)krvector.elementAt(i);
- KeyValueStore keyValueStore = (KeyValueStore)keyHash.get(keyRef.getName());
+ KeyValueStore keyValueStore = (KeyValueStore)keyHash.get(keyRef.getReferName());
KeyRefValueStore keyRefValueStore = null;
int fcount = keyRef.getFieldCount();
for (int j = 0; j < fcount; j++) {
1.9 +3 -1 xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaMessageProvider.java
Index: SchemaMessageProvider.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaMessageProvider.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SchemaMessageProvider.java 2001/02/09 21:47:09 1.8
+++ SchemaMessageProvider.java 2001/02/20 06:12:28 1.9
@@ -171,8 +171,9 @@
DuplicateKey = 34,
KeyNotFound = 35,
UnknownField = 36,
+ KeyRefReferNotFound = 37,
// ...
- MSG_MAX_CODE = 37;
+ MSG_MAX_CODE = 38;
//
// Minor Codes
//
@@ -218,6 +219,7 @@
"DuplicateKey",
"KeyNotFound",
"UnknownField",
+ "KeyRefReferNotFound",
// END
};
}
1.105 +21 -6 xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java
Index: TraverseSchema.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- TraverseSchema.java 2001/02/19 22:52:13 1.104
+++ TraverseSchema.java 2001/02/20 06:12:28 1.105
@@ -124,7 +124,7 @@
*
* @see org.apache.xerces.validators.common.Grammar
*
- * @version $Id: TraverseSchema.java,v 1.104 2001/02/19 22:52:13 elena Exp $
+ * @version $Id: TraverseSchema.java,v 1.105 2001/02/20 06:12:28 andyc Exp $
*/
public class TraverseSchema implements
NamespacesScope.NamespacesHandler{
@@ -4281,11 +4281,12 @@
throws Exception {
// create identity constraint
+ String uname = uelem.getAttribute(SchemaSymbols.ATT_NAME);
if (DEBUG_IDENTITY_CONSTRAINTS) {
- System.out.println("<IC>: traverseUnique(\""+uelem.getNodeName()+"\")");
+ System.out.println("<IC>: traverseUnique(\""+uelem.getNodeName()+"\") ["+uname+']');
}
String ename = getElementNameFor(uelem);
- Unique unique = new Unique(ename);
+ Unique unique = new Unique(uname, ename);
// get selector and fields
traverseIdentityConstraint(unique, uelem);
@@ -4304,7 +4305,7 @@
System.out.println("<IC>: traverseKey(\""+kelem.getNodeName()+"\") ["+kname+']');
}
String ename = getElementNameFor(kelem);
- Key key = new Key(ename, kname);
+ Key key = new Key(kname, ename);
// get selector and fields
traverseIdentityConstraint(key, kelem);
@@ -4319,11 +4320,25 @@
// create identity constraint
String krname = krelem.getAttribute(SchemaSymbols.ATT_NAME);
+ String kname = krelem.getAttribute(SchemaSymbols.ATT_REFER);
if (DEBUG_IDENTITY_CONSTRAINTS) {
- System.out.println("<IC>: traverseKeyRef(\""+krelem.getNodeName()+"\") ["+krname+']');
+ System.out.println("<IC>: traverseKeyRef(\""+krelem.getNodeName()+"\") ["+krname+','+kname+']');
}
+
+ // verify that key reference "refer" attribute is valid
+ Element element = (Element)krelem.getParentNode();
+ Element kelem = XUtil.getFirstChildElement(element,
+ SchemaSymbols.ELT_KEY,
+ SchemaSymbols.ATT_NAME,
+ kname);
+ if (kelem == null) {
+ reportSchemaError(SchemaMessageProvider.KeyRefReferNotFound,
+ new Object[]{krname,kname});
+ return;
+ }
+
String ename = getElementNameFor(krelem);
- KeyRef keyRef = new KeyRef(ename, krname);
+ KeyRef keyRef = new KeyRef(krname, kname, ename);
// add to element decl
traverseIdentityConstraint(keyRef, krelem);
1.4 +2 -2 xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Field.java
Index: Field.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Field.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Field.java 2001/02/01 09:58:43 1.3
+++ Field.java 2001/02/20 06:12:28 1.4
@@ -67,7 +67,7 @@
* Schema identity constraint field.
*
* @author Andy Clark, IBM
- * @version $Id: Field.java,v 1.3 2001/02/01 09:58:43 andyc Exp $
+ * @version $Id: Field.java,v 1.4 2001/02/20 06:12:28 andyc Exp $
*/
public class Field {
@@ -181,7 +181,7 @@
/** Constructs a field matcher. */
public Matcher(Field.XPath xpath, ValueStore store) {
- super(xpath);
+ super(xpath, true);
fStore = store;
} // <init>(Field.XPath,ValueStore)
1.3 +13 -3 xml-xerces/java/src/org/apache/xerces/validators/schema/identity/IdentityConstraint.java
Index: IdentityConstraint.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/IdentityConstraint.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IdentityConstraint.java 2001/01/25 07:18:55 1.2
+++ IdentityConstraint.java 2001/02/20 06:12:28 1.3
@@ -61,7 +61,7 @@
* Base class of Schema identity constraint.
*
* @author Andy Clark, IBM
- * @version $Id: IdentityConstraint.java,v 1.2 2001/01/25 07:18:55 andyc Exp $
+ * @version $Id: IdentityConstraint.java,v 1.3 2001/02/20 06:12:28 andyc Exp $
*/
public abstract class IdentityConstraint {
@@ -82,6 +82,9 @@
// Data
//
+ /** Identity constraint name. */
+ protected String fIdentityConstraintName;
+
/** Element name. */
protected String fElementName;
@@ -99,9 +102,11 @@
//
/** Default constructor. */
- protected IdentityConstraint(String elementName) {
+ protected IdentityConstraint(String identityConstraintName,
+ String elementName) {
+ fIdentityConstraintName = identityConstraintName;
fElementName = elementName;
- } // <init>(String)
+ } // <init>(String,String)
//
// Public methods
@@ -109,6 +114,11 @@
/** Returns the identity constraint type. */
public abstract short getType();
+
+ /** Returns the identity constraint name. */
+ public String getIdentityConstraintName() {
+ return fIdentityConstraintName;
+ } // getIdentityConstraintName():String
/** Returns the element name. */
public String getElementName() {
1.3 +3 -16 xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Key.java
Index: Key.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Key.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Key.java 2001/01/25 07:18:56 1.2
+++ Key.java 2001/02/20 06:12:28 1.3
@@ -61,26 +61,18 @@
* Schema key identity constraint.
*
* @author Andy Clark, IBM
- * @version $Id: Key.java,v 1.2 2001/01/25 07:18:56 andyc Exp $
+ * @version $Id: Key.java,v 1.3 2001/02/20 06:12:28 andyc Exp $
*/
public class Key
extends IdentityConstraint {
//
- // Data
- //
-
- /** Name. */
- protected String fKeyName;
-
- //
// Constructors
//
/** Constructs a key with the specified name. */
- public Key(String elementName, String keyName) {
- super(elementName);
- fKeyName = keyName;
+ public Key(String identityConstraintName, String elementName) {
+ super(identityConstraintName, elementName);
} // <init>(String,String)
//
@@ -91,10 +83,5 @@
public short getType() {
return KEY;
} // getType():short
-
- /** Returns the name. */
- public String getName() {
- return fKeyName;
- } // getName():String
} // class Key
1.3 +12 -11 xml-xerces/java/src/org/apache/xerces/validators/schema/identity/KeyRef.java
Index: KeyRef.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/KeyRef.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KeyRef.java 2001/01/25 07:18:57 1.2
+++ KeyRef.java 2001/02/20 06:12:28 1.3
@@ -61,7 +61,7 @@
* Schema key reference identity constraint.
*
* @author Andy Clark, IBM
- * @version $Id: KeyRef.java,v 1.2 2001/01/25 07:18:57 andyc Exp $
+ * @version $Id: KeyRef.java,v 1.3 2001/02/20 06:12:28 andyc Exp $
*/
public class KeyRef
extends IdentityConstraint {
@@ -70,18 +70,19 @@
// Data
//
- /** Key name. */
- protected String fKeyName;
+ /** The key referal name. */
+ protected String fReferName;
//
// Constructors
//
/** Constructs a keyref with the specified name. */
- public KeyRef(String elementName, String keyName) {
- super(elementName);
- fKeyName = keyName;
- } // <init>(String,String)
+ public KeyRef(String identityConstraintName, String referName,
+ String elementName) {
+ super(identityConstraintName, elementName);
+ fReferName = referName;
+ } // <init>(String,String,String)
//
// Public methods
@@ -92,9 +93,9 @@
return KEYREF;
} // getType():short
- /** Returns the name. */
- public String getName() {
- return fKeyName;
- } // getName():String
+ /** Returns the refer name. */
+ public String getReferName() {
+ return fReferName;
+ } // getReferName():String
} // class KeyRef
1.3 +4 -4 xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Unique.java
Index: Unique.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Unique.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Unique.java 2001/01/25 07:18:59 1.2
+++ Unique.java 2001/02/20 06:12:28 1.3
@@ -61,7 +61,7 @@
* Schema unique identity constraint.
*
* @author Andy Clark, IBM
- * @version $Id: Unique.java,v 1.2 2001/01/25 07:18:59 andyc Exp $
+ * @version $Id: Unique.java,v 1.3 2001/02/20 06:12:28 andyc Exp $
*/
public class Unique
extends IdentityConstraint {
@@ -71,9 +71,9 @@
//
/** Constructs a unique identity constraint. */
- public Unique(String elementName) {
- super(elementName);
- } // <init>(String)
+ public Unique(String identityConstraintName, String elementName) {
+ super(identityConstraintName, elementName);
+ } // <init>(String,String)
//
// Public methods
1.7 +14 -13 xml-xerces/java/src/org/apache/xerces/validators/schema/identity/XPathMatcher.java
Index: XPathMatcher.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/XPathMatcher.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XPathMatcher.java 2001/02/01 09:58:44 1.6
+++ XPathMatcher.java 2001/02/20 06:12:29 1.7
@@ -75,7 +75,7 @@
*
* @author Andy Clark, IBM
*
- * @version $Id: XPathMatcher.java,v 1.6 2001/02/01 09:58:44 andyc Exp $
+ * @version $Id: XPathMatcher.java,v 1.7 2001/02/20 06:12:29 andyc Exp $
*/
public class XPathMatcher {
@@ -165,7 +165,7 @@
*/
public XPathMatcher(XPath xpath) {
this(xpath, false);
- } // <init>(Stringm,SymbolTable,NamespaceContext)
+ } // <init>(XPath)
/**
* Constructs an XPath matcher that implements a document fragment
@@ -182,7 +182,7 @@
if (DEBUG_METHODS) {
System.out.println(toString()+"#<init>()");
}
- } // <init>(String,SymbolTable,NamespaceContext,boolean)
+ } // <init>(XPath,boolean)
//
// Public methods
@@ -417,23 +417,24 @@
"})");
}
- // go back a step
- fCurrentStep = fStepIndexes.pop();
-
- // return, if not matching
+ // don't do anything, if not matching
if (fNoMatchDepth > 0) {
fNoMatchDepth--;
- return;
}
// signal match, if appropriate
- if (fBufferContent) {
- fBufferContent = false;
- fMatchedString = fMatchedBuffer.toString();
- matched(fMatchedString);
+ else {
+ if (fBufferContent) {
+ fBufferContent = false;
+ fMatchedString = fMatchedBuffer.toString();
+ matched(fMatchedString);
+ }
+ clear();
}
- clear();
+ // go back a step
+ fCurrentStep = fStepIndexes.pop();
+
if (DEBUG_STACK) {
System.out.println(toString()+": "+fStepIndexes);
}