You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ca...@apache.org on 2007/03/28 17:23:55 UTC

svn commit: r523363 - in /xerces/c/branches/xerces-2.7/src/xercesc: internal/IGXMLScanner.cpp internal/IGXMLScanner2.cpp internal/SGXMLScanner.cpp validators/schema/SchemaValidator.cpp validators/schema/TraverseSchema.cpp

Author: cargilld
Date: Wed Mar 28 08:23:51 2007
New Revision: 523363

URL: http://svn.apache.org/viewvc?view=rev&rev=523363
Log:
various schema fixes

Modified:
    xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner2.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/internal/SGXMLScanner.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/SchemaValidator.cpp
    xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/TraverseSchema.cpp

Modified: xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner.cpp?view=diff&rev=523363&r1=523362&r2=523363
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner.cpp Wed Mar 28 08:23:51 2007
@@ -2737,6 +2737,9 @@
 
             }
         }
+        else if (fGrammarType == Grammar::SchemaGrammarType) {
+            ((SchemaValidator*)fValidator)->setNillable(false);
+        }
 
         if (fGrammarType == Grammar::SchemaGrammarType)
         {

Modified: xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner2.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner2.cpp?view=diff&rev=523363&r1=523362&r2=523363
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner2.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/internal/IGXMLScanner2.cpp Wed Mar 28 08:23:51 2007
@@ -53,6 +53,7 @@
 #include <xercesc/validators/schema/SubstitutionGroupComparator.hpp>
 #include <xercesc/validators/schema/XSDDOMParser.hpp>
 #include <xercesc/validators/schema/identity/IdentityConstraintHandler.hpp>
+#include <xercesc/util/XMLStringTokenizer.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -189,7 +190,142 @@
         XMLAttDef::AttTypes attType;
         DatatypeValidator *attrValidator = 0;
         PSVIAttribute *psviAttr = 0;
-        if (!isNSAttr || fGrammarType == Grammar::DTDGrammarType)
+        bool otherXSI = false;
+
+        if (isNSAttr && fGrammarType == Grammar::SchemaGrammarType)
+        {
+            if(fUndeclaredAttrRegistryNS->containsKey(suffPtr, uriId))
+            {
+                emitError
+                ( 
+                    XMLErrs::AttrAlreadyUsedInSTag
+                    , namePtr
+                    , elemDecl->getFullName()
+                );
+                fPSVIElemContext.fErrorOccurred = true;
+            }
+            else
+            {
+                bool ValueValidate = false;
+                bool tokenizeBuffer = false;
+
+                if (uriId == fXMLNSNamespaceId)
+                {
+                    attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
+                }
+                else if (XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI))
+                {
+                    if (XMLString::equals(suffPtr, SchemaSymbols::fgATT_NILL))
+                    {
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_BOOLEAN);
+
+                        ValueValidate = true;
+                    }
+                    else if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_SCHEMALOCACTION))
+                    {
+                        // use anyURI as the validator
+                        // tokenize the data and use the anyURI data for each piece
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
+                        //We should validate each value in the schema location however
+                        //this lead to a performance degradation of around 4%.  Since
+                        //the first value of each pair needs to match what is in the
+                        //schema document and the second value needs to be valid in
+                        //order to open the document we won't validate it.  Need to
+                        //do performance analysis of the anyuri datatype.
+                        //ValueValidate = true;
+                        ValueValidate = false;
+                        tokenizeBuffer = true;
+                    }
+                    else if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_NONAMESPACESCHEMALOCACTION))
+                    {
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
+                        //We should validate this value however
+                        //this lead to a performance degradation of around 4%.  Since
+                        //the value needs to be valid in
+                        //order to open the document we won't validate it.  Need to
+                        //do performance analysis of the anyuri datatype.
+                        //ValueValidate = true;
+                        ValueValidate = false;
+                    }
+                    else if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_TYPE))
+                    {
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_QNAME);
+
+                        ValueValidate = true;
+                    }
+                    else {
+                        otherXSI = true;                       
+                    }
+                }
+
+                if (!otherXSI) {
+                    fUndeclaredAttrRegistryNS->put((void *)suffPtr, uriId, 0);
+
+                    // Just normalize as CDATA
+                    attType = XMLAttDef::CData;
+                    normalizeAttRawValue
+                    (
+                        namePtr
+                        , curPair->getValue()
+                        , normBuf
+                    );                    
+
+                    if (fValidate && attrValidator && ValueValidate)
+                    {
+                        ValidationContext* const    theContext =
+                            getValidationContext();
+
+                        if (theContext)
+                        {
+                            try
+                            {
+                                if (tokenizeBuffer) {
+                                    XMLStringTokenizer tokenizer(normBuf.getRawBuffer(), fMemoryManager);                                    
+                                    while (tokenizer.hasMoreTokens()) {                                       
+                                        attrValidator->validate(
+                                            tokenizer.nextToken(),
+                                            theContext,
+                                            fMemoryManager);
+                                    }                                  
+                                }
+                                else {
+                                    attrValidator->validate(
+                                        normBuf.getRawBuffer(),
+                                        theContext,
+                                        fMemoryManager);
+                                }
+                            }
+                            catch (const XMLException& idve)
+                            {
+                                fValidator->emitError (XMLValid::DatatypeError, idve.getCode(), idve.getType(), idve.getMessage());
+                            }
+                        }
+                    }
+
+                    if(getPSVIHandler())
+                    {
+	                    psviAttr = fPSVIAttrList->getPSVIAttributeToFill(suffPtr, fURIStringPool->getValueForId(uriId)); 
+	                    XSSimpleTypeDefinition *validatingType = (attrValidator)
+                            ? (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator)
+                            : 0;
+                        // no attribute declarations for these...
+	                    psviAttr->reset(
+	                        fRootElemName
+	                        , PSVIItem::VALIDITY_NOTKNOWN
+	                        , PSVIItem::VALIDATION_NONE
+	                        , validatingType
+	                        , 0
+	                        , 0
+                            , false
+	                        , 0
+                            , attrValidator
+                            );
+                    }
+                }
+            }
+        }
+        
+        if (!isNSAttr || fGrammarType == Grammar::DTDGrammarType || otherXSI)
         {
             // Some checking for attribute wild card first (for schema)
             bool laxThisOne = false;
@@ -564,39 +700,6 @@
                 }
 	        }
 	    }
-        else
-        {
-            // Just normalize as CDATA
-            attType = XMLAttDef::CData;
-            normalizeAttRawValue
-            (
-                namePtr
-                , curPair->getValue()
-                , normBuf
-            );
-            if((uriId == fXMLNSNamespaceId)
-                  || XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI))
-                attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
-            if(getPSVIHandler() && fGrammarType == Grammar::SchemaGrammarType)
-            {
-	            psviAttr = fPSVIAttrList->getPSVIAttributeToFill(suffPtr, fURIStringPool->getValueForId(uriId)); 
-	            XSSimpleTypeDefinition *validatingType = (attrValidator)
-                            ? (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator)
-                            : 0;
-                // no attribute declarations for these...
-	            psviAttr->reset(
-	                fRootElemName
-	                , PSVIItem::VALIDITY_NOTKNOWN
-	                , PSVIItem::VALIDATION_NONE
-	                , validatingType
-	                , 0
-	                , 0
-                    , false
-	                , 0
-                    , attrValidator
-                );
-            }
-        }
 
         //  Add this attribute to the attribute list that we use to pass them
         //  to the handler. We reuse its existing elements but expand it as

Modified: xerces/c/branches/xerces-2.7/src/xercesc/internal/SGXMLScanner.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-2.7/src/xercesc/internal/SGXMLScanner.cpp?view=diff&rev=523363&r1=523362&r2=523363
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/internal/SGXMLScanner.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/internal/SGXMLScanner.cpp Wed Mar 28 08:23:51 2007
@@ -46,6 +46,7 @@
 #include <xercesc/validators/schema/identity/IC_Selector.hpp>
 #include <xercesc/util/OutOfMemoryException.hpp>
 #include <xercesc/util/HashPtr.hpp>
+#include <xercesc/util/XMLStringTokenizer.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -1722,6 +1723,9 @@
             }
 
         }
+        else if (fGrammarType == Grammar::SchemaGrammarType) {
+            ((SchemaValidator*)fValidator)->setNillable(false);
+        }
 
         if (fPSVIHandler)
         {
@@ -2219,7 +2223,142 @@
         XMLAttDef::AttTypes attType;
         DatatypeValidator *attrValidator = 0;
         PSVIAttribute *psviAttr = 0;
-        if (!isNSAttr)
+        bool otherXSI = false;
+
+        if (isNSAttr)
+        {
+            if(fUndeclaredAttrRegistryNS->containsKey(suffPtr, uriId))
+            {
+                emitError
+                ( 
+                    XMLErrs::AttrAlreadyUsedInSTag
+                    , namePtr
+                    , elemDecl->getFullName()
+                );
+                fPSVIElemContext.fErrorOccurred = true;
+            }
+            else
+            {
+                bool ValueValidate = false;
+                bool tokenizeBuffer = false;
+
+                if (uriId == fXMLNSNamespaceId)
+                {
+                    attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
+                }
+                else if (XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI))
+                {
+                    if (XMLString::equals(suffPtr, SchemaSymbols::fgATT_NILL))
+                    {
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_BOOLEAN);
+
+                        ValueValidate = true;
+                    }
+                    else if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_SCHEMALOCACTION))
+                    {
+                        // use anyURI as the validator
+                        // tokenize the data and use the anyURI data for each piece
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
+                        //We should validate each value in the schema location however
+                        //this lead to a performance degradation of around 4%.  Since
+                        //the first value of each pair needs to match what is in the
+                        //schema document and the second value needs to be valid in
+                        //order to open the document we won't validate it.  Need to
+                        //do performance analysis of the anyuri datatype.
+                        //ValueValidate = true;
+                        ValueValidate = false;
+                        tokenizeBuffer = true;                        
+                    }
+                    else if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_NONAMESPACESCHEMALOCACTION))
+                    {
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
+                        //We should validate this value however
+                        //this lead to a performance degradation of around 4%.  Since
+                        //the value needs to be valid in
+                        //order to open the document we won't validate it.  Need to
+                        //do performance analysis of the anyuri datatype.
+                        //ValueValidate = true;
+                        ValueValidate = false;
+                    }
+                    else if (XMLString::equals(suffPtr, SchemaSymbols::fgXSI_TYPE))
+                    {
+                        attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_QNAME);
+
+                        ValueValidate = true;
+                    }
+                    else {
+                        otherXSI = true;                       
+                    }
+                }
+
+                if (!otherXSI) {
+                    fUndeclaredAttrRegistryNS->put((void *)suffPtr, uriId, 0);
+
+                    // Just normalize as CDATA
+                    attType = XMLAttDef::CData;
+                    normalizeAttRawValue
+                    (
+                        namePtr
+                        , curPair->getValue()
+                        , normBuf
+                    );                    
+
+                    if (fValidate && attrValidator && ValueValidate)
+                    {
+                        ValidationContext* const    theContext =
+                            getValidationContext();
+
+                        if (theContext)
+                        {
+                            try
+                            {
+                                if (tokenizeBuffer) {
+                                    XMLStringTokenizer tokenizer(normBuf.getRawBuffer(), fMemoryManager);                                    
+                                    while (tokenizer.hasMoreTokens()) {                                       
+                                        attrValidator->validate(
+                                            tokenizer.nextToken(),
+                                            theContext,
+                                            fMemoryManager);
+                                    }                                  
+                                }
+                                else {
+                                    attrValidator->validate(
+                                        normBuf.getRawBuffer(),
+                                        theContext,
+                                        fMemoryManager);
+                                }
+                            }
+                            catch (const XMLException& idve)
+                            {
+                                fValidator->emitError (XMLValid::DatatypeError, idve.getCode(), idve.getType(), idve.getMessage());
+                            }
+                        }
+                    }
+
+                    if(getPSVIHandler() && fGrammarType == Grammar::SchemaGrammarType)
+                    {
+	                    psviAttr = fPSVIAttrList->getPSVIAttributeToFill(suffPtr, fURIStringPool->getValueForId(uriId)); 
+	                    XSSimpleTypeDefinition *validatingType = (attrValidator)
+                            ? (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator)
+                            : 0;
+                        // no attribute declarations for these...
+	                    psviAttr->reset(
+	                        fRootElemName
+	                        , PSVIItem::VALIDITY_NOTKNOWN
+	                        , PSVIItem::VALIDATION_NONE
+	                        , validatingType
+	                        , 0
+	                        , 0
+                            , false
+	                        , 0
+                            , attrValidator
+                        );
+                    }
+                }
+            }
+        }
+
+        if (!isNSAttr || otherXSI)        
         {
             // Some checking for attribute wild card first (for schema)
             bool laxThisOne = false;
@@ -2549,39 +2688,6 @@
 	                );
                 }
 	        }
-        }
-        else
-        {
-            // Just normalize as CDATA
-            attType = XMLAttDef::CData;
-            normalizeAttRawValue
-            (
-                namePtr
-                , curPair->getValue()
-                , normBuf
-            );
-            if((uriId == fXMLNSNamespaceId)
-                  || XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI))
-                attrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYURI);
-            if(getPSVIHandler())
-            {
-                psviAttr = fPSVIAttrList->getPSVIAttributeToFill(suffPtr, fURIStringPool->getValueForId(uriId));
-                XSSimpleTypeDefinition *validatingType = 0;
-                if (attrValidator && fModel)
-                    validatingType = (XSSimpleTypeDefinition *)fModel->getXSObject(attrValidator);
-                // no attribute declarations for these...
-	            psviAttr->reset(
-	                fRootElemName
-	                , PSVIItem::VALIDITY_NOTKNOWN
-	                , PSVIItem::VALIDATION_NONE
-	                , validatingType
-	                , 0
-	                , 0
-                    , false
-	                , 0
-                    , attrValidator
-                );
-            }
         }
 
         //  Add this attribute to the attribute list that we use to pass them

Modified: xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/SchemaValidator.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/SchemaValidator.cpp?view=diff&rev=523363&r1=523362&r2=523363
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/SchemaValidator.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/SchemaValidator.cpp Wed Mar 28 08:23:51 2007
@@ -1418,6 +1418,9 @@
                                     const int baseScope,
                                     const ComplexTypeInfo* const baseInfo) {
 
+    if (derivedSpecNode->getMaxOccurs() == 0)
+        return;
+
     unsigned int derivedURI = derivedSpecNode->getElement()->getURI();
 
     // case of mixed complex types with attributes only

Modified: xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/TraverseSchema.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/TraverseSchema.cpp?view=diff&rev=523363&r1=523362&r2=523363
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/TraverseSchema.cpp (original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/validators/schema/TraverseSchema.cpp Wed Mar 28 08:23:51 2007
@@ -1072,15 +1072,15 @@
             reportSchemaError(child, XMLUni::fgValidityDomain, XMLValid::GroupContentRestricted, childName);
         }
 
-        if (contentSpecNode.get()) {
-            hadContent = true;
-        }
-
         if (seeParticle) {
             checkMinMax(contentSpecNode.get(), child, Not_All_Context);
             if (wasAny && contentSpecNode.get()->getMaxOccurs() == 0) {
                 contentSpecNode.reset(0);
             }
+        }
+
+        if (contentSpecNode.get()) {
+            hadContent = true;
         }
 
         if (left.get() == 0) {



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