Better error reporting for identity constraint errors
-----------------------------------------------------

         Key: XERCESJ-1092
         URL: http://issues.apache.org/jira/browse/XERCESJ-1092
     Project: Xerces2-J
        Type: Improvement
  Components: XML Schema Structures  
    Versions: 2.7.1    
 Environment: All
    Reporter: George Cristian Bina


Most of the identity constraint errors are reported without specifying the 
identity constraint name, this becames a problem if there a many identity 
constraints defined as finding the one that fails can be difficult. Also a 
couple of error messages do not follow the format that most of the schema error 
message have, that is to specify the error code at the message start.

A proposed patch to fix these follows after a short description of the changes.

    Message Key - actions
    ====================================================
    AbsentKeyValue - added constraint name, place the error code first. 
    DuplicateField - NOT FOUND!
    DuplicateKey - added constraint name.
    DuplicateUnique - added constraint name.
    FieldMultipleMatch - added constraint name.
    FixedDiffersFromActual -
    KeyMatchesNillable - added constraint name, place the error code first.
    KeyNotEnoughValues - 
    KeyNotFound -
    KeyRefNotEnoughValues - 
    KeyRefOutOfScope - 
    KeyRefReferNotFound - NOT FOUND!
    UniqueNotEnoughValues - added constraint name.
    UnknownField - added constraint name and element name.

Patch (made against Xerces 2.7.1):

Index: src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
===================================================================
RCS file: 
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties,v
retrieving revision 1.78
diff -u -r1.78 XMLSchemaMessages.properties
--- src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties 14 Jun 2005 
04:24:24 -0000      1.78
+++ src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties 4 Aug 2005 
11:38:17 -0000
@@ -14,20 +14,20 @@
 
 # Identity constraints
 
-        AbsentKeyValue = Identity Constraint error 
(cvc-identity-constraint.4.2.1):  element \"{0}\" has a key with no value.
+        AbsentKeyValue = cvc-identity-constraint.4.2.1: Element \"{0}\" has no 
value for the key \"{1}\".
         DuplicateField = Duplicate match in scope for field \"{0}\".
-        DuplicateKey = Duplicate key value [{0}] declared for identity 
constraint of element \"{1}\".
-        DuplicateUnique = Duplicate unique value [{0}] declared for identity 
constraint of element \"{1}\".
-        FieldMultipleMatch = Identity constraint error:  field \"{0}\" matches 
more than one value within the scope of its selector; fields must match unique 
values.
+        DuplicateKey = Duplicate key value [{0}] declared for identity 
constraint \"{2}\" of element \"{1}\".
+        DuplicateUnique = Duplicate unique value [{0}] declared for identity 
constraint \"{2}\" of element \"{1}\".
+        FieldMultipleMatch = Identity constraint error for contatint \"{1}\":  
field \"{0}\" matches more than one value within the scope of its selector; 
fields must match unique values.
         FixedDiffersFromActual = The content of this element is not equivalent 
to the value of the \"fixed\" attribute in the element's declaration in the 
schema.
-        KeyMatchesNillable = Identity Constraint error 
(cvc-identity-constraint.4.2.3):  element \"{0}\" has a key which matches an 
element which has nillable set to true.
+        KeyMatchesNillable = cvc-identity-constraint.4.2.3:  element \"{0}\" 
has the key \"{1}\" which matches an element which has nillable set to true.
         KeyNotEnoughValues = Not enough values specified for <key 
name=\"{1}\"> identity constraint specified for element \"{0}\".
         KeyNotFound = Key ''{0}'' with value ''{1}'' not found for identity 
constraint of element ''{2}''.
         KeyRefNotEnoughValues = Not enough values specified for <keyref 
name=\"{1}\"> identity constraint specified for element \"{0}\".
         KeyRefOutOfScope = Identity Constraint error:  identity constraint 
\"{0}\" has a keyref which refers to a key or unique that is out of scope.
         KeyRefReferNotFound = Key reference declaration \"{0}\" refers to 
unknown key with name \"{1}\".
-        UniqueNotEnoughValues = Not enough values specified for <unique> 
identity constraint specified for element \"{0}\".
-        UnknownField = Internal identity constraint error; unknown field 
\"{0}\".
+        UniqueNotEnoughValues = Not enough values specified for <unique> 
identity constraint \"{1}\" specified for element \"{0}\".
+        UnknownField = Internal identity constraint error; unknown field 
\"{0}\" for identity constraint \"{1}\" specified for element \"{2}\".
 
 # Ideally, we should only use the following error keys, not the ones under
 # "Identity constraints". And we should cover all of the following errors.
Index: src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
===================================================================
RCS file: 
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v
retrieving revision 1.179
diff -u -r1.179 XMLSchemaValidator.java
--- src/org/apache/xerces/impl/xs/XMLSchemaValidator.java       24 Jul 2005 
22:55:21 -0000      1.179
+++ src/org/apache/xerces/impl/xs/XMLSchemaValidator.java       4 Aug 2005 
11:38:18 -0000
@@ -3400,7 +3400,8 @@
                 if (fIdentityConstraint.getCategory() == 
IdentityConstraint.IC_KEY) {
                     String code = "AbsentKeyValue";
                     String eName = fIdentityConstraint.getElementName();
-                    reportSchemaError(code, new Object[] { eName });
+                    String cName = 
fIdentityConstraint.getIdentityConstraintName();
+                    reportSchemaError(code, new Object[] { eName, cName });
                 }
                 return;
             }
@@ -3412,7 +3413,8 @@
                         {
                             String code = "UniqueNotEnoughValues";
                             String ename = 
fIdentityConstraint.getElementName();
-                            reportSchemaError(code, new Object[] { ename });
+                            String cName = 
fIdentityConstraint.getIdentityConstraintName();
+                            reportSchemaError(code, new Object[] { ename, 
cName });
                             break;
                         }
                     case IdentityConstraint.IC_KEY :
@@ -3420,8 +3422,8 @@
                             String code = "KeyNotEnoughValues";
                             UniqueOrKey key = (UniqueOrKey) 
fIdentityConstraint;
                             String ename = 
fIdentityConstraint.getElementName();
-                            String kname = key.getIdentityConstraintName();
-                            reportSchemaError(code, new Object[] { ename, 
kname });
+                            String cName = key.getIdentityConstraintName();
+                            reportSchemaError(code, new Object[] { ename, 
cName });
                             break;
                         }
                     case IdentityConstraint.IC_KEYREF :
@@ -3429,8 +3431,8 @@
                             String code = "KeyRefNotEnoughValues";
                             KeyRef keyref = (KeyRef) fIdentityConstraint;
                             String ename = 
fIdentityConstraint.getElementName();
-                            String kname = 
(keyref.getKey()).getIdentityConstraintName();
-                            reportSchemaError(code, new Object[] { ename, 
kname });
+                            String cName = 
(keyref.getKey()).getIdentityConstraintName();
+                            reportSchemaError(code, new Object[] { ename, 
cName });
                             break;
                         }
                 }
@@ -3484,13 +3486,16 @@
             }
             // do we even know this field?
             if (i == -1) {
-                String code = "UnknownField";
-                reportSchemaError(code, new Object[] { field.toString()});
+                String code = "UnknownField";                
+                String cName = fIdentityConstraint.getIdentityConstraintName();
+                String eName = fIdentityConstraint.getElementName();
+                reportSchemaError(code, new Object[] { field.toString(), 
cName, eName});
                 return;
             }
             if (Boolean.TRUE != mayMatch(field)) {
                 String code = "FieldMultipleMatch";
-                reportSchemaError(code, new Object[] { field.toString()});
+                String cName = fIdentityConstraint.getIdentityConstraintName();
+                reportSchemaError(code, new Object[] { field.toString(), 
cName});
             } else {
                 fValuesCount++;
             }
@@ -3772,7 +3777,8 @@
                 String code = "DuplicateUnique";
                 String value = toString(fLocalValues);
                 String ename = fIdentityConstraint.getElementName();
-                reportSchemaError(code, new Object[] { value, ename });
+                String cName = fIdentityConstraint.getIdentityConstraintName();
+                reportSchemaError(code, new Object[] { value, ename, cName });
             }
         } // duplicateValue(Hashtable)
 
@@ -3808,7 +3814,8 @@
                 String code = "DuplicateKey";
                 String value = toString(fLocalValues);
                 String ename = fIdentityConstraint.getElementName();
-                reportSchemaError(code, new Object[] { value, ename });
+                String cName = fIdentityConstraint.getIdentityConstraintName();
+                reportSchemaError(code, new Object[] { value, ename, cName });
             }
         } // duplicateValue(Hashtable)
 
Index: src/org/apache/xerces/impl/xs/identity/Field.java
===================================================================
RCS file: 
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Field.java,v
retrieving revision 1.20
diff -u -r1.20 Field.java
--- src/org/apache/xerces/impl/xs/identity/Field.java   25 May 2005 02:28:39 
-0000      1.20
+++ src/org/apache/xerces/impl/xs/identity/Field.java   4 Aug 2005 11:38:18 
-0000
@@ -173,7 +173,8 @@
             super.matched(actualValue, valueType, itemValueType, isNil);
             if(isNil && (fIdentityConstraint.getCategory() == 
IdentityConstraint.IC_KEY)) {
                 String code = "KeyMatchesNillable";
-                fStore.reportError(code, new 
Object[]{fIdentityConstraint.getElementName()});
+                fStore.reportError(code, 
+                    new Object[]{fIdentityConstraint.getElementName(), 
fIdentityConstraint.getIdentityConstraintName()});
             }
             fStore.addValue(Field.this, actualValue, 
convertToPrimitiveKind(valueType), convertToPrimitiveKind(itemValueType));
             // once we've stored the value for this field, we set the mayMatch



Thanks,
George

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to