Author: mukulg
Date: Tue Mar 22 04:24:36 2011
New Revision: 1084065

URL: http://svn.apache.org/viewvc?rev=1084065&view=rev
Log:
committing few improvements to schema 1.1 assertion evaluations.

the changes in this commit are following,
1) considering assertions from base type of a complexType (with extension 
derivation), where the base type has variety simpleType->list.
2) few minor improvements to error messages for assertions.

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
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.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=1084065&r1=1084064&r2=1084065&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
 Tue Mar 22 04:24:36 2011
@@ -105,9 +105,9 @@
         cvc-type.3.1.1 = cvc-type.3.1.1: Element ''{0}'' is a simple type, so 
it cannot have attributes, excepting those whose namespace name is identical to 
''http://www.w3.org/2001/XMLSchema-instance'' and whose [local name] is one of 
''type'', ''nil'', ''schemaLocation'' or ''noNamespaceSchemaLocation''. 
However, the attribute, ''{1}'' was found.
         cvc-type.3.1.2 = cvc-type.3.1.2: Element ''{0}'' is a simple type, so 
it must have no element information item [children].
         cvc-type.3.1.3 = cvc-type.3.1.3: The value ''{1}'' of element ''{0}'' 
is not valid.
-        cvc-assertion.3.13.4.1 = cvc-assertion.3.13.4.1: Assertion evaluation 
(''{1}'') for element ''{0}'' with type ''{2}'' did not succeed. {3}
+        cvc-assertion.3.13.4.1 = cvc-assertion.3.13.4.1: Assertion evaluation 
(''{1}'') for element ''{0}'' on schema type ''{2}'' did not succeed. {3}
         cvc-assertion.3.13.4.1-failure-mesg = 
cvc-assertion.3.13.4.1-failure-mesg: {0} {1}                  
-        cvc-assertions-valid-context = cvc-assertions-valid-context: Assertion 
evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed 
(undefined context). {3}
+        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.

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=1084065&r1=1084064&r2=1084065&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
 Tue Mar 22 04:24:36 2011
@@ -384,6 +384,12 @@ public class XMLAssertPsychopathXPath2Im
                 else {
                     simpleTypeDefn = (XSSimpleTypeDefinition) xsTypeDefn;  
                 }
+                ElementPSVI elemPSVI = (ElementPSVI) 
augs.getItem(Constants.ELEMENT_PSVI);
+                XSComplexTypeDefinition complexTypeDef = 
(XSComplexTypeDefinition)elemPSVI.getTypeDefinition();
+                if 
(XSTypeHelper.isComplexTypeDerivedFromSTListByExt(complexTypeDef)) {
+                    // reassign value to simple type instance
+                    simpleTypeDefn = 
(XSSimpleTypeDefinition)complexTypeDef.getBaseType(); 
+                }
                 final boolean isTypeDerivedFromList = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_LIST;
                 final boolean isTypeDerivedFromUnion = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
                 if (simpleTypeDefn.getVariety() == 
XSSimpleTypeDefinition.VARIETY_ATOMIC) {
@@ -396,7 +402,7 @@ public class XMLAssertPsychopathXPath2Im
                 }
                 else if (simpleTypeDefn.getVariety() == 
XSSimpleTypeDefinition.VARIETY_LIST) {
                     // evaluating assertions for "simpleType -> list"          
          
-                    evaluateAssertionOnSTListValue(element, value, assertImpl, 
false, simpleTypeDefn, isTypeDerivedFromList);
+                    evaluateAssertionOnSTListValue(element, value, assertImpl, 
false, simpleTypeDefn.getItemType(), isTypeDerivedFromList);
                 }
                 else if (((Boolean) 
augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION")).booleanValue()) {
                     // evaluating assertions for "simpleType -> union" 
@@ -406,9 +412,9 @@ public class XMLAssertPsychopathXPath2Im
                     }
                 }                
                 // evaluate assertions on itemType of xs:list
-                XSSimpleTypeDefinition attrItemType = 
simpleTypeDefn.getItemType();
-                if (isTypeDerivedFromList && attrItemType != null) {
-                    evaluateAssertsFromItemTypeOfSTList(element, attrItemType, 
value);
+                XSSimpleTypeDefinition listItemType = 
simpleTypeDefn.getItemType();
+                if (isTypeDerivedFromList && listItemType != null) {
+                    evaluateAssertsFromItemTypeOfSTList(element, listItemType, 
value);
                 }
             }            
         }
@@ -944,12 +950,12 @@ public class XMLAssertPsychopathXPath2Im
         String value = assertError.getValue();
         
         XSTypeDefinition typeDef = assertImpl.getTypeDefinition();        
-        String typeNameStrAnnotation = "";        
-        if (typeDef != null) {
-            typeNameStrAnnotation = (typeDef.getName() != null) ? 
typeDef.getName() : "#anonymous";   
+        String typeNameStr = "";
+        if (typeDef instanceof XSSimpleTypeDefinition) {
+            typeNameStr = ((XSSimpleTypeDecl)typeDef).getTypeName();
         }
         else {
-            typeNameStrAnnotation = "#anonymous"; 
+            typeNameStr = ((XSComplexTypeDecl)typeDef).getTypeName();
         }
         
         String elemErrorAnnotation = element.rawname;
@@ -978,15 +984,15 @@ public class XMLAssertPsychopathXPath2Im
                message = message + ".";    
            }
            if (key.equals("cvc-assertions-valid-context")) {
-               message = "Assertion failed (undefined context) for schema type 
'" + typeNameStrAnnotation + "'. " + message;   
+               message = "Assertion failed (undefined context) for schema type 
'" + typeNameStr + "'. " + message;   
            }
            else {
-               message = "Assertion failed for schema type '" + 
typeNameStrAnnotation + "'. " + message; 
+               message = "Assertion failed for schema type '" + typeNameStr + 
"'. " + message; 
            }           
            
fXmlSchemaValidator.reportSchemaError("cvc-assertion.3.13.4.1-failure-mesg", 
new Object[] {message, listAssertErrMessage});    
         }
         else {
-           fXmlSchemaValidator.reportSchemaError(key, new Object[] 
{elemErrorAnnotation, assertImpl.getTest().getXPath().toString(), 
typeNameStrAnnotation, listAssertErrMessage});
+           fXmlSchemaValidator.reportSchemaError(key, new Object[] 
{elemErrorAnnotation, assertImpl.getTest().getXPath().toString(), typeNameStr, 
listAssertErrMessage});
         }
         
     } // reportAssertionsError

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java?rev=1084065&r1=1084064&r2=1084065&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
 Tue Mar 22 04:24:36 2011
@@ -182,14 +182,24 @@ public class XSDAssertionValidator {
             }
         }
 
-        // add assertion facets from "complexType -> simpleContent -> 
restriction"
+        // add assertion facets from complexType -> simpleContent. few 
assertions are already available in complexType model object,
+        // and few others are retrieved here.
         XSSimpleTypeDefinition simpleContentType = 
complexTypeDef.getSimpleType();
-        if (simpleContentType != null && complexTypeDef.getDerivationMethod() 
== XSConstants.DERIVATION_RESTRICTION) {
-            Vector simpleContentAsserts = 
XSTypeHelper.getAssertsFromSimpleType(simpleContentType);
-            for (int assertIdx = 0; assertIdx < simpleContentAsserts.size(); 
assertIdx++) {
-                XSAssert simpleContentAssert = (XSAssert) 
simpleContentAsserts.get(assertIdx);
-                complexTypeAsserts.addXSObject(simpleContentAssert);
-            } 
+        if (simpleContentType != null) {                    
+            if (complexTypeDef.getDerivationMethod() == 
XSConstants.DERIVATION_RESTRICTION) {
+                // add assertions for complexType -> simpleContent -> 
restriction cases 
+                Vector simpleContentAsserts = 
XSTypeHelper.getAssertsFromSimpleType(simpleContentType);
+                for (int assertIdx = 0; assertIdx < 
simpleContentAsserts.size(); assertIdx++) {
+                    complexTypeAsserts.addXSObject((XSAssert) 
simpleContentAsserts.get(assertIdx));
+                }
+            }
+            else if 
(XSTypeHelper.isComplexTypeDerivedFromSTListByExt(complexTypeDef)) {
+                // add assertions from the list->itemType of base schema 
simple type
+                Vector baseItemTypeAsserts = 
XSTypeHelper.getAssertsFromSimpleType(((XSSimpleTypeDefinition)complexTypeDef.getBaseType()).getItemType());
+                for (int assertIdx = 0; assertIdx < 
baseItemTypeAsserts.size(); assertIdx++) {
+                    complexTypeAsserts.addXSObject((XSAssert) 
baseItemTypeAsserts.get(assertIdx)); 
+                }
+            }
         }
         
 

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java?rev=1084065&r1=1084064&r2=1084065&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
 Tue Mar 22 04:24:36 2011
@@ -31,6 +31,8 @@ import org.apache.xerces.impl.xs.SchemaS
 import org.apache.xerces.impl.xs.XSMessageFormatter;
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.NamespaceContext;
+import org.apache.xerces.xs.XSComplexTypeDefinition;
+import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSMultiValueFacet;
 import org.apache.xerces.xs.XSObjectList;
 import org.apache.xerces.xs.XSSimpleTypeDefinition;
@@ -206,4 +208,16 @@ public class XSTypeHelper {
         
     } // isListContainsType
     
+    
+    /*
+     * Find if a complexType is derived by extension from a simpleType->list 
component.
+     */
+    public static boolean 
isComplexTypeDerivedFromSTListByExt(XSComplexTypeDefinition complexTypeDef) {
+        
+        return complexTypeDef.getDerivationMethod() == 
XSConstants.DERIVATION_EXTENSION &&
+               complexTypeDef.getBaseType() instanceof XSSimpleTypeDefinition 
&&
+               
((XSSimpleTypeDefinition)complexTypeDef.getBaseType()).getVariety() == 
XSSimpleTypeDefinition.VARIETY_LIST;
+        
+    } // isComplexTypeDerivedFromSTListByExt
+    
 } // class XSTypeHelper



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

Reply via email to