You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by bo...@apache.org on 2008/02/13 09:14:42 UTC

svn commit: r627303 - /xerces/c/branches/xerces-2/src/xercesc/validators/schema/SchemaValidator.cpp

Author: borisk
Date: Wed Feb 13 00:14:41 2008
New Revision: 627303

URL: http://svn.apache.org/viewvc?rev=627303&view=rev
Log:
In restriction checking, when looking for a declaration of a base element, use the schema grammar corresponding to the type this element is declared in (XERCESC-1777)

Modified:
    xerces/c/branches/xerces-2/src/xercesc/validators/schema/SchemaValidator.cpp

Modified: xerces/c/branches/xerces-2/src/xercesc/validators/schema/SchemaValidator.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-2/src/xercesc/validators/schema/SchemaValidator.cpp?rev=627303&r1=627302&r2=627303&view=diff
==============================================================================
--- xerces/c/branches/xerces-2/src/xercesc/validators/schema/SchemaValidator.cpp (original)
+++ xerces/c/branches/xerces-2/src/xercesc/validators/schema/SchemaValidator.cpp Wed Feb 13 00:14:41 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -193,15 +193,15 @@
                         //  the notation pool (after the Grammar is parsed), then obviously
                         //  this value will be legal since it matches one of them.
                         int colonPos = -1;
-                        unsigned int uriId = getScanner()->resolveQName(value, *fNotationBuf, ElemStack::Mode_Element, colonPos);                        
+                        unsigned int uriId = getScanner()->resolveQName(value, *fNotationBuf, ElemStack::Mode_Element, colonPos);
 
                         const XMLCh* uriText = getScanner()->getURIText(uriId);
                         if (uriText && *uriText) {
                             fNotationBuf->set(uriText);
-                            fNotationBuf->append(chColon);                                
+                            fNotationBuf->append(chColon);
                             fNotationBuf->append(&value[colonPos + 1]);
                             value = fNotationBuf->getRawBuffer();
-                        }                        
+                        }
                     }
 
                     if (elemDefaultValue)
@@ -421,7 +421,7 @@
                 const XMLCh* uriText = getScanner()->getURIText(uriId);
                 if (uriText && *uriText) {
                     notationBuf.set(uriText);
-                    notationBuf.append(chColon);                                
+                    notationBuf.append(chColon);
                     notationBuf.append(&attrValue[colonPos + 1]);
                 }
                 else {
@@ -441,7 +441,7 @@
         }
         catch (XMLException& idve) {
             fErrorOccurred = true;
-            emitError (XMLValid::DatatypeError, idve.getCode(), idve.getType(), idve.getMessage());       
+            emitError (XMLValid::DatatypeError, idve.getCode(), idve.getType(), idve.getMessage());
         }
         catch(const OutOfMemoryException&)
         {
@@ -452,7 +452,7 @@
             fMostRecentAttrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
             fErrorOccurred = true;
             throw;
-        } 
+        }
         fMostRecentAttrValidator = attDefDV;
         // now we can look for ID's, entities, ...
 
@@ -560,7 +560,7 @@
                         fErrorOccurred = true;
                     }
                     else {
-                        if (elemTypeInfo || (fCurrentDatatypeValidator  
+                        if (elemTypeInfo || (fCurrentDatatypeValidator
                                 && !fCurrentDatatypeValidator->isSubstitutableBy(xsiTypeDV))) {
                             // the type is not derived from ancestor
                             emitError(XMLValid::NonDerivedXsiType, fXsiType->getRawName(), elemDef->getFullName());
@@ -1192,7 +1192,7 @@
                 {
                     ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::PD_InvalidContentType, fMemoryManager);
                 }
-            }		
+            }
         }
     case ContentSpecNode::Any:
     case ContentSpecNode::Any_Other:
@@ -1441,20 +1441,21 @@
         return;
     }
 
-    SchemaGrammar* aGrammar = currentGrammar;
-    const XMLCh* schemaURI = fGrammarResolver->getStringPool()->getValueForId(derivedURI);
+    SchemaGrammar* dGrammar = currentGrammar;
 
-    if (derivedURI != getScanner()->getEmptyNamespaceId()) {
-        aGrammar= (SchemaGrammar*) fGrammarResolver->getGrammar(schemaURI);
+    if (derivedURI != getScanner()->getEmptyNamespaceId())
+    {
+        const XMLCh* dURI = fGrammarResolver->getStringPool()->getValueForId(derivedURI);
+        dGrammar= (SchemaGrammar*) fGrammarResolver->getGrammar(dURI);
     }
 
-    if (!aGrammar) { //something is wrong
+    if (!dGrammar) { //something is wrong
         return;
     }
-   
-    const XMLCh* derivedName = derivedSpecNode->getElement()->getLocalPart();    
 
-    SchemaElementDecl* derivedElemDecl = findElement(derivedScope, derivedURI, derivedName, aGrammar);
+    const XMLCh* derivedName = derivedSpecNode->getElement()->getLocalPart();
+
+    SchemaElementDecl* derivedElemDecl = findElement(derivedScope, derivedURI, derivedName, dGrammar);
 
     if (!derivedElemDecl) {
         return;
@@ -1480,15 +1481,33 @@
         }
 
         subsGroup = true;
-    } 
+    }
 
     if (!isOccurrenceRangeOK(derivedSpecNode->getMinOccurs(), derivedSpecNode->getMaxOccurs(),
                              baseSpecNode->getMinOccurs(), baseSpecNode->getMaxOccurs())) {
         ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::PD_OccurRangeE, derivedName, fMemoryManager);
     }
 
+    // Find the schema grammar for the base element using the base type as
+    // a reference if it is available (it is unavailable if we are checking
+    // element group restriction which happens in redefine).
+    //
+    SchemaGrammar* bGrammar = dGrammar;
+
+    if (baseInfo)
+    {
+        const XMLCh* baseTypeURI = baseInfo->getTypeUri ();
+
+        if (baseTypeURI != 0 && *baseTypeURI != 0) // Non-empty namespace.
+            bGrammar= (SchemaGrammar*) fGrammarResolver->getGrammar(baseTypeURI);
+
+        if (!bGrammar) { //something is wrong
+            return;
+        }
+    }
+
     SchemaElementDecl* baseElemDecl =
-        findElement(baseScope, baseURI, baseName, aGrammar, baseInfo);
+        findElement(baseScope, baseURI, baseName, bGrammar, baseInfo);
 
     if (!baseElemDecl) {
         return;
@@ -1654,13 +1673,13 @@
                                        ValueVectorOf<ContentSpecNode*>* const baseNodes,
                                        const ComplexTypeInfo* const baseInfo) {
 
-    ContentSpecNode::NodeTypes baseType = baseSpecNode->getType();    
+    ContentSpecNode::NodeTypes baseType = baseSpecNode->getType();
     bool toLax = false;
 
     //Treat the element as if it were in a group of the same variety as base
     ContentSpecNode derivedGroupNode(baseType, derivedSpecNodeIn, 0, false, true, fMemoryManager);
     const ContentSpecNode* const derivedSpecNode = &derivedGroupNode;
-    
+
     if ((baseSpecNode->getType() & 0x0f) == ContentSpecNode::Choice) {
         toLax = true;
     }
@@ -1668,16 +1687,16 @@
     // Instead of calling this routine, inline it
     // checkRecurse(currentGrammar, &derivedGroupNode, derivedScope, &derivedNodes,
     //             baseSpecNode, baseScope, baseNodes, baseInfo, toLax);
- 
+
     if (!isOccurrenceRangeOK(derivedSpecNode->getMinOccurs(), derivedSpecNode->getMaxOccurs(),
                              baseSpecNode->getMinOccurs(), baseSpecNode->getMaxOccurs())) {
         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::PD_Recurse1, fMemoryManager);
     }
 
     // check for mapping of children
-    XMLExcepts::Codes codeToThrow = XMLExcepts::NoError;   
+    XMLExcepts::Codes codeToThrow = XMLExcepts::NoError;
     unsigned int count2= baseNodes->size();
-    unsigned int current = 0;    
+    unsigned int current = 0;
 
     {
         bool matched = false;
@@ -1706,7 +1725,7 @@
 
         // did not find a match
         if (!matched) {
-            codeToThrow = XMLExcepts::PD_Recurse2;            
+            codeToThrow = XMLExcepts::PD_Recurse2;
         }
     }
 
@@ -1715,7 +1734,7 @@
     if (!toLax && codeToThrow == XMLExcepts::NoError) {
         for (unsigned int j = current; j < count2; j++) {
             if (baseNodes->elementAt(j)->getMinTotalRange() * baseSpecNode->getMinOccurs()) { //!emptiable
-                codeToThrow =  XMLExcepts::PD_Recurse2;                
+                codeToThrow =  XMLExcepts::PD_Recurse2;
                 break;
             }
         }
@@ -1746,7 +1765,7 @@
     XMLExcepts::Codes codeToThrow = XMLExcepts::NoError;
     unsigned int count1= derivedNodes->size();
     unsigned int count2= baseNodes->size();
-    unsigned int current = 0;    
+    unsigned int current = 0;
 
     for (unsigned int i=0; i<count1; i++) {
 
@@ -1786,8 +1805,8 @@
     // in case of Sequence or All
     if (!toLax && codeToThrow == XMLExcepts::NoError) {
         for (unsigned int j = current; j < count2; j++) {
-            if (baseNodes->elementAt(j)->getMinTotalRange()) { //!emptiable                
-                codeToThrow =  XMLExcepts::PD_Recurse2;                
+            if (baseNodes->elementAt(j)->getMinTotalRange()) { //!emptiable
+                codeToThrow =  XMLExcepts::PD_Recurse2;
                 break;
             }
         }



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