Author: mukulg
Date: Wed Apr  6 10:38:01 2011
New Revision: 1089391

URL: http://svn.apache.org/viewvc?rev=1089391&view=rev
Log:
i think it's good if we show in schema 1.1 assert error messages, the error 
details relevant to the XPath static or dynamic context errors (for example 
incorrect function names & arity, undeclared namespace prefixes etc used in 
XPath expressions).

this commit makes this improvement.

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/XMLAssertPsychopathXPath2Impl.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=1089391&r1=1089390&r2=1089391&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 Apr  6 10:38:01 2011
@@ -107,11 +107,11 @@
         cvc-type.3.1.3 = cvc-type.3.1.3: The value ''{1}'' of element ''{0}'' 
is not valid.
         cvc-assertion = cvc-assertion: Assertion evaluation (''{1}'') for 
element ''{0}'' on schema type ''{2}'' did not succeed. {3}
         cvc-assertion-failure-mesg = cvc-assertion-failure-mesg: {0} {1}
-        cvc-assertions-valid = cvc-assertions-valid: Value ''{0}'' is not 
facet-valid with respect to assertion ''{1}''.                
+        cvc-assertions-valid = cvc-assertions-valid: Value ''{0}'' is not 
facet-valid with respect to assertion ''{1}''. {2}                
         cvc-assertions-valid-context = cvc-assertions-valid-context: Assertion 
evaluation (''{1}'') for element ''{0}'' on schema type ''{2}'' did not succeed 
(undefined context). {3}
         cvc-assertions-valid-union-elem = cvc-assertions-valid-union-elem: 
Value ''{0}'' is not facet-valid with respect to the specified assertions, on 
type ''{2}'' on element ''{1}''.
         cvc-assertions-valid-union-attr = cvc-assertions-valid-union-attr: 
Value ''{0}'' is not facet-valid with respect to the specified assertions, on 
type ''{3}'' on attribute ''{2}'/@'{1}''.         
-        cvc-xpath.3.13.4.2a = cvc-xpath.3.13.4.2a: Assertion XPath expression 
(''{0}'') on the schema type ''{1}'' couldn''t compile successfully.
+        cvc-xpath.3.13.4.2a = cvc-xpath.3.13.4.2a: XPST0003 - Assertion XPath 
expression (''{0}'') on the schema type ''{1}'' couldn''t compile successfully.
         cvc-xpath.3.13.4.2b = cvc-xpath.3.13.4.2b: Assertion XPath expression 
(''{0}'') on the schema type ''{1}'' is invalid. An assert XPath expression 
cannot begin with / or //, since an assert tree is rooted at a parentless 
element.
         
 #schema valid (3.X.3)

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java?rev=1089391&r1=1089390&r2=1089391&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
 Wed Apr  6 10:38:01 2011
@@ -50,6 +50,7 @@ import org.apache.xerces.xs.XSSimpleType
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
+import org.eclipse.wst.xml.xpath2.processor.StaticError;
 import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -508,20 +509,23 @@ public class XMLAssertPsychopathXPath2Im
             
             if (!result) {
                // assertion evaluation is false
-               assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList); 
+               assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList, null); 
             }
         }
         catch (DynamicError ex) {
             if ("XPDY0002".equals(ex.code())) {
                // ref: http://www.w3.org/TR/xpath20/#eval_context
-               assertionError = new 
AssertionError("cvc-assertions-valid-context", element, assertImpl, value, 
isList);
+               assertionError = new 
AssertionError("cvc-assertions-valid-context", element, assertImpl, value, 
isList, ex);
             }
             else {
-               assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList);
+               assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList, ex);
             }
         }
+        catch (StaticError ex) {
+            assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList, ex);  
+        }
         catch(Exception ex) {
-            assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList);   
+            assertionError = new AssertionError("cvc-assertion", element, 
assertImpl, value, isList, ex);   
         }
         
         return assertionError;
@@ -612,6 +616,19 @@ public class XMLAssertPsychopathXPath2Im
         XSAssertImpl assertImpl = assertError.getAssertion();
         boolean isList = assertError.isList();
         String value = assertError.getValue();
+        
+        // construct the message fragment in case of XPath DynamicError or 
StaticError  
+        String exceptionMesg = "";
+        Exception exception = assertError.getException();        
+        if (exception instanceof DynamicError) {
+            exceptionMesg = ((DynamicError) exception).code() + " - " + 
((DynamicError) exception).getMessage();   
+        }
+        else if (exception instanceof StaticError) {
+            exceptionMesg = ((StaticError) exception).code() + " - " + 
((StaticError) exception).getMessage();
+        }
+        if (!"".equals(exceptionMesg) && !exceptionMesg.endsWith(".")) {
+            exceptionMesg = exceptionMesg + ".";  
+        }
                
         String typeNameStr = 
XSTypeHelper.getSchemaTypeName(assertImpl.getTypeDefinition());
         
@@ -630,33 +647,34 @@ public class XMLAssertPsychopathXPath2Im
            }
         }
             
-        String message = assertImpl.getMessage();
-        if (message != null) {
+        String mesgSuffix = "".equals(listAssertErrMessage) ? exceptionMesg : 
(listAssertErrMessage + ("".equals(exceptionMesg) ? "" : " " + exceptionMesg));
+        String userDefinedMessage = assertImpl.getMessage();
+        if (userDefinedMessage != null) {
            // substitute all placeholder macro instances of "{$value}" with 
atomic value stored in variable "value"
            if (value != null && !"".equals(value)) {
-               message = 
message.replaceAll(SchemaSymbols.ASSERT_ERRORMSG_PLACEHOLDER_REGEX, value);
+               userDefinedMessage = 
userDefinedMessage.replaceAll(SchemaSymbols.ASSERT_ERRORMSG_PLACEHOLDER_REGEX, 
value);
            }
            
-           if (!message.endsWith(".")) {
-               message = message + ".";    
+           if (!userDefinedMessage.endsWith(".")) {
+               userDefinedMessage = userDefinedMessage + ".";    
            }
            if ("cvc-assertions-valid-context".equals(key)) {
-               message = "Assertion failed (undefined context) for schema type 
'" + typeNameStr + "'. " + message;   
+               userDefinedMessage = "Assertion failed (undefined context) for 
schema type '" + typeNameStr + "'. " + userDefinedMessage;   
            }
            else {
-               message = "Assertion failed for schema type '" + typeNameStr + 
"'. " + message; 
+               userDefinedMessage = "Assertion failed for schema type '" + 
typeNameStr + "'. " + userDefinedMessage;
            }           
-           fXmlSchemaValidator.reportSchemaError("cvc-assertion-failure-mesg", 
new Object[] {message, listAssertErrMessage});    
+           fXmlSchemaValidator.reportSchemaError("cvc-assertion-failure-mesg", 
new Object[] {userDefinedMessage, mesgSuffix});    
         }
         else {
            if (assertImpl.getAssertKind() == XSConstants.ASSERTION) {
               // error for xs:assert component
-              fXmlSchemaValidator.reportSchemaError(key, new Object[] 
{elemNameAnnotation, assertImpl.getTest().getXPath().toString(), typeNameStr, 
listAssertErrMessage});
+              fXmlSchemaValidator.reportSchemaError(key, new Object[] 
{elemNameAnnotation, assertImpl.getTest().getXPath().toString(), typeNameStr, 
mesgSuffix});
            }
            else {
                // errors for xs:assertion facet
-               fXmlSchemaValidator.reportSchemaError("cvc-assertions-valid", 
new Object[] {value, assertImpl.getTest().getXPath().toString()});
-               fXmlSchemaValidator.reportSchemaError(key, new Object[] 
{elemNameAnnotation, assertImpl.getTest().getXPath().toString(), typeNameStr, 
listAssertErrMessage});  
+               fXmlSchemaValidator.reportSchemaError("cvc-assertions-valid", 
new Object[] {value, assertImpl.getTest().getXPath().toString(), 
exceptionMesg});
+               fXmlSchemaValidator.reportSchemaError(key, new Object[] 
{elemNameAnnotation, assertImpl.getTest().getXPath().toString(), typeNameStr, 
mesgSuffix});  
            }
         }
         
@@ -675,15 +693,17 @@ public class XMLAssertPsychopathXPath2Im
         private final String value;
         // does this error concerns "simpleType -> list"
         private final boolean isList;
-        private boolean isTypeDerivedFromList = false; 
+        private boolean isTypeDerivedFromList = false;
+        Exception ex = null;
         
         // class constructor
-        public AssertionError(String errorCode, QName element, XSAssertImpl 
assertImpl, String value, boolean isList) {
+        public AssertionError(String errorCode, QName element, XSAssertImpl 
assertImpl, String value, boolean isList, Exception ex) {
            this.errorCode = errorCode;
            this.element = element;
            this.assertImpl = assertImpl;
            this.value = value;
            this.isList = isList;
+           this.ex = ex;
         }
         
         public void setIsTypeDerivedFromList(boolean isTypeDerivedFromList) {
@@ -714,6 +734,10 @@ public class XMLAssertPsychopathXPath2Im
            return isTypeDerivedFromList; 
         }
         
+        public Exception getException() {
+            return ex;
+        }
+        
     } // class AssertionError
     
 } // class XMLAssertPsychopathXPath2Impl



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to