You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mu...@apache.org on 2009/12/10 13:06:24 UTC

svn commit: r889224 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: XMLAssertPsychopathImpl.java XMLSchemaValidator.java assertion/XSAssertImpl.java

Author: mukulg
Date: Thu Dec 10 12:06:13 2009
New Revision: 889224

URL: http://svn.apache.org/viewvc?rev=889224&view=rev
Log:
fix to assertion processing on attributes, where attributes have user-defined simple types, which have assertion facets (in this case, xpath context is undefined, and the assert facet operates only on, context variable $value). this further improves XSD 1.1 assertion processing compliance, within xerces.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
    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/assertion/XSAssertImpl.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=889224&r1=889223&r2=889224&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java Thu Dec 10 12:06:13 2009
@@ -214,7 +214,7 @@
             // assertions from a complex type definition
             if (value != null) {
               // complex type with simple content
-              setValueOf$value(value);
+              setValueOf$value(value, null);
             } else {
               // complex type with complex content                
               // $value should be, the XPath2 "empty sequence" ... TO DO 
@@ -226,21 +226,29 @@
                if (assertImpl.getType() == XSConstants.ASSERTION) {
                   // not an assertion facet
                   xpathContextExists = true;   
-               }               
+               }
+               // check if this is an assertion, from the attribute
+               if (assertImpl.getAttrValue() != null) {
+                  // reassign value (the attribute's value) to variable
+                  // $value.
+                  value = assertImpl.getAttrValue();
+                  setValueOf$value(value, assertImpl.getTypeDefinition());
+               }
                evaluateAssertion(element,
                                  assertImpl,
                                  value,
                                  xpathContextExists);
             }
-        } else if (assertions instanceof Vector) {
+         }
+         else if (assertions instanceof Vector) {
             // assertions from a simple type definition
-            setValueOf$value(value);
+            setValueOf$value(value, null);
             Vector assertList = (Vector) assertions;                    
             for (int i = 0; i < assertList.size(); i++) {
                 XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
                 evaluateAssertion(element, assertImpl, value, false);
             }
-        }
+         }
     }
 
     /*
@@ -281,7 +289,12 @@
             
             if (!result) {
                // assertion evaluation is false
-               reportError("cvc-assertion.3.13.4.1", element, assertImpl);
+                if (assertImpl.getAttrName() == null) {
+                   reportError("cvc-assertion.3.13.4.1", element, assertImpl);
+                }
+                else {
+                   reportError("cvc-assertion.3.13.4.1", element, assertImpl); 
+                }
             }
         }
         catch (DynamicError ex) {
@@ -314,21 +327,37 @@
            typeString = "#anonymous"; 
         }
         
-        validator.reportSchemaError(key, new Object[] { element.rawname,
+        String elemErrorAnnotation = element.rawname;
+        if (assertImpl.getAttrName() != null) {
+           elemErrorAnnotation = element.rawname + " (attribute => " +
+                                              assertImpl.getAttrName()+ ")";    
+        }
+        
+        validator.reportSchemaError(key, new Object[] { elemErrorAnnotation,
                                assertImpl.getTest().getXPath().toString(),
                                typeString } );
     }
     
     // assign value to the XPath2 "dynamic context" variable, $value
-    private void setValueOf$value(String value) {
-       PSVIElementNSImpl currentAssertPSVINode = (PSVIElementNSImpl)
+    private void setValueOf$value(String value, XSTypeDefinition attrType) {
+        String xsdTypeName = "";
+        
+        if (attrType != null) {
+           // is value of an attribute
+           xsdTypeName = getXSDtypeOf$Value(attrType);  
+        }
+        else {
+          // is "simple type" value of an element
+          PSVIElementNSImpl currentAssertPSVINode = (PSVIElementNSImpl)
                                                  currentAssertDomNode;
        
-       String xsdTypeName = getXSDtypeOf$Value(currentAssertPSVINode.
-                                               getTypeDefinition());       
-       Object psychoPathType = abstrPsychopathImpl.getPsychoPathTypeForXSDType
+          xsdTypeName = getXSDtypeOf$Value(currentAssertPSVINode.
+                                               getTypeDefinition()); 
+        }
+        
+        Object psychoPathType = abstrPsychopathImpl.getPsychoPathTypeForXSDType
                                                          (xsdTypeName, value);       
-       fDynamicContext.set_variable(
+        fDynamicContext.set_variable(
                new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
                        "value"), (AnyAtomicType) psychoPathType);
     }

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=889224&r1=889223&r2=889224&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 Thu Dec 10 12:06:13 2009
@@ -2436,8 +2436,8 @@
         if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
             fInhrAttrCountStack.push(fInheritableAttrList.size());
             if (attributes.getLength() > 0) {
-               // get inheritable attributes, only if an element has a complex type (i.e, has
-               // > 0 attributes.
+               // get inheritable attributes, only if an element has a complex
+               // type (i.e, has > 0 attributes).
                saveInheritableAttributes(attributes);
             }
         }
@@ -2511,20 +2511,48 @@
                assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
             }
           }
+          
+          // there could be assertions, to be evaluated on attributes. add these
+          // assertions to the assertions to be processed.
+          for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++) {
+              Augmentations attrAugs = attributes.getAugmentations(attrIndx);
+              AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem
+                                                 (Constants.ATTRIBUTE_PSVI);
+              XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition)attrPSVI.
+                                                        getTypeDefinition();
+              if (attrType != null) {
+                 XSObjectList facets = attrType.getMultiValueFacets();              
+                 for (int i = 0; i < facets.getLength(); i++) {
+                    XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
+                    if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
+                       Vector attrAsserts = facet.getAsserts();
+                       for (int j = 0; j < attrAsserts.size(); j++) {
+                         XSAssertImpl attrAssert = (XSAssertImpl) attrAsserts.elementAt(j);
+                         attrAssert.setAttrName(attributes.getLocalName(attrIndx));
+                         attrAssert.setAttrValue(attributes.getValue(attrIndx));
+                         assertions.addXSObject(attrAssert);    
+                       }                        
+                       break;
+                    }
+                 }
+              }
+          }
               
           if (assertions.size() > 0) {
-            assertObject = assertions;             
-            // instantiate the assertions processor
-            if (fAssertionProcessor == null) {
-              // construct parameter values for the assertion processor
-              Map assertProcessorParams = new HashMap();
-              assertProcessorParams.put("XPATH2_NS_CONTEXT",
-                                        ((XSAssertImpl)assertions.get(0)).getXPath2NamespaceContext());
-              // initialize the assertions processor
-              initializeAssertProcessor(assertProcessorParams);
-            }
+              assertObject = assertions;             
+              // instantiate the assertions processor
+              if (fAssertionProcessor == null) {
+                // construct parameter values for the assertion processor
+                Map assertProcessorParams = new HashMap();
+                assertProcessorParams.put("XPATH2_NS_CONTEXT",
+                                     ((XSAssertImpl)assertions.get(0)).
+                                     getXPath2NamespaceContext());
+                // initialize the assertions processor
+                initializeAssertProcessor(assertProcessorParams);
+              }
           }
-        } else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
+        }
+        else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
             // if elements's governing type is a "simple type"
             XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) typeDef;
             XSObjectList facets = simpleTypeDef.getMultiValueFacets();
@@ -2537,7 +2565,8 @@
                    // construct parameter values for the assertion processor
                    Map assertProcessorParams = new HashMap();
                    assertProcessorParams.put("XPATH2_NS_CONTEXT",
-                           ((XSAssertImpl)facet.getAsserts().get(0)).getXPath2NamespaceContext());
+                                     ((XSAssertImpl)facet.getAsserts().get(0)).
+                                     getXPath2NamespaceContext());
                    // initialize the assertions processor
                    initializeAssertProcessor(assertProcessorParams);
                 }
@@ -2545,7 +2574,7 @@
               }
             }
          }
-
+               
          // invoke the assertions processor method
          if (fAssertionProcessor != null) {
             // construct the augmentations object, for assertions

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java?rev=889224&r1=889223&r2=889224&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java Thu Dec 10 12:06:13 2009
@@ -57,7 +57,17 @@
     /** XPath 2.0 namespace context. Derived from XSDocumentInfo in XSD traversers. */
     protected NamespaceSupport fXPath2NamespaceContext = null;
     
-    // XSDHandler object, passed on from the tarversers 
+    // a non null value of this object indicates, that this assertion is
+    // for an attribute, and value of this object would be the attribute's
+    // name.
+    protected String attrName = null;
+    
+    // a non null value of this object indicates, that this assertion is
+    // for an attribute, and value of this object would be the attribute's
+    // value.
+    protected String attrValue = null;
+    
+    // XSDHandler object, passed on from the traversers 
     protected XSDHandler fSchemaHandler = null;
 
     /** Constructor */
@@ -100,6 +110,21 @@
     public void setType(short assertType) {
         this.assertType = assertType;
     }
+    
+    /**
+     * Sets the attribute name
+     */
+    public void setAttrName(String attrName) {
+        this.attrName = attrName;   
+    }
+    
+    /**
+     * Sets the attribute value
+     */
+    public void setAttrValue(String attrValue) {
+        this.attrValue = attrValue;   
+    }
+    
    
     public XSObjectList getAnnotations() {
         return fAnnotations;
@@ -152,6 +177,20 @@
     public short getType() {
         return assertType;
     }
+    
+    /**
+     * Get the attribute name
+     */
+    public String getAttrName() {
+        return attrName;  
+    }
+    
+    /**
+     * Get the attribute value
+     */
+    public String getAttrValue() {
+        return attrValue;  
+    }
        
     /**
      * Get the XPath 2.0 namespace context



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org