Author: amassari
Date: Tue Jul 15 07:14:56 2008
New Revision: 676924

URL: http://svn.apache.org/viewvc?rev=676924&view=rev
Log:
Fixed regression due to incomplete backport (XERCESC-1817)

Added:
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xml
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xsd
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xml
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xsd
Modified:
    xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp
    xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet

Modified: xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp?rev=676924&r1=676923&r2=676924&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp (original)
+++ xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp Tue Jul 15 
07:14:56 2008
@@ -207,7 +207,7 @@
                 {
                     nextState = fTransTable[curState][elemIndex];
                     if (nextState != XMLContentModel::gInvalidTrans)
-                            break;
+                        break;
                 }
                 else if ((type & 0x0f) == ContentSpecNode::Any_NS)
                 {
@@ -251,8 +251,94 @@
             if (o != 0) {
                 if (curState == nextState) {
                     if (++loopCount > (unsigned int)o->maxOccurs && 
o->maxOccurs != -1) {
-                        *indexFailingChild=childIndex;
-                        return false;
+
+                        // It's likely that we looped too many times on the 
current state
+                        // however it's possible that we actually matched 
another particle
+                        // which allows the same name.
+                        //
+                        // Consider:
+                        //
+                        // <xs:sequence>
+                        //  <xs:element name="foo" type="xs:string" 
minOccurs="3" maxOccurs="3"/>
+                        //  <xs:element name="foo" type="xs:string" 
fixed="bar"/>
+                        // </xs:sequence>
+                        //
+                        // and
+                        //
+                        // <xs:sequence>
+                        //  <xs:element name="foo" type="xs:string" 
minOccurs="3" maxOccurs="3"/>
+                        //  <xs:any namespace="##any" processContents="skip"/>
+                        // </xs:sequence>
+                        //
+                        // In the DFA there will be two transitions from the 
current state which 
+                        // allow "foo". Note that this is not a UPA violation. 
The ambiguity of which
+                        // transition to take is resolved by the current value 
of the counter. Since 
+                        // we've already seen enough instances of the first 
"foo" perhaps there is
+                        // another element declaration or wildcard deeper in 
the element map which
+                        // matches.
+                        unsigned int tempNextState = 0;
+                        
+                        while (++elemIndex < fElemMapSize) {
+                            const QName* inElem  = fElemMap[elemIndex];
+                            if (fDTD) {
+                                if (XMLString::equals(inElem->getRawName(), 
curElemRawName)) {
+                                    tempNextState = 
fTransTable[curState][elemIndex];
+                                    if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                        break;
+                                }
+                            }
+                            else {
+                                ContentSpecNode::NodeTypes type = 
fElemMapType[elemIndex] ;
+                                if (type == ContentSpecNode::Leaf) {
+                                    if ((inElem->getURI() == 
curElem->getURI()) &&
+                                    (XMLString::equals(inElem->getLocalPart(), 
curElem->getLocalPart()))) {
+                                        tempNextState = 
fTransTable[curState][elemIndex];
+                                        if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                            break;
+                                    }
+                                }
+                                else if ((type & 0x0f)== ContentSpecNode::Any)
+                                {
+                                    tempNextState = 
fTransTable[curState][elemIndex];
+                                    if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                        break;
+                                }
+                                else if ((type & 0x0f) == 
ContentSpecNode::Any_NS)
+                                {
+                                    if (inElem->getURI() == curElem->getURI())
+                                    {
+                                        tempNextState = 
fTransTable[curState][elemIndex];
+                                        if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                            break;
+                                    }
+                                }
+                                else if ((type & 0x0f) == 
ContentSpecNode::Any_Other)
+                                {
+                                    // Here we assume that empty string has id 
1.
+                                    //
+                                    unsigned int uriId = curElem->getURI();
+                                    if (uriId != 1 && uriId != 
inElem->getURI()) {
+                                        tempNextState = 
fTransTable[curState][elemIndex];
+                                        if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                            break;
+                                    }
+                                }
+                            }
+                        }
+                        
+                        // if we still can't find a match, report the error
+                        if (elemIndex == fElemMapSize) {
+                            *indexFailingChild=childIndex;
+                            return false;
+                        }
+                        
+                        // if we found a match, set the next state and reset 
the 
+                        // counter if the next state is a counting state.
+                        nextState = tempNextState;
+                        Occurence* o = fCountingStates[nextState];
+                        if (o != 0) {
+                            loopCount = (elemIndex == o->elemIndex) ? 1 : 0;
+                        }
                     }
                 }
                 else if (loopCount < (unsigned int)o->minOccurs) {
@@ -413,8 +499,87 @@
             if (o != 0) {
                 if (curState == nextState) {
                     if (++loopCount > (unsigned int)o->maxOccurs && 
o->maxOccurs != -1) {
-                        *indexFailingChild=childIndex;
-                        return false;
+                        // It's likely that we looped too many times on the 
current state
+                        // however it's possible that we actually matched 
another particle
+                        // which allows the same name.
+                        //
+                        // Consider:
+                        //
+                        // <xs:sequence>
+                        //  <xs:element name="foo" type="xs:string" 
minOccurs="3" maxOccurs="3"/>
+                        //  <xs:element name="foo" type="xs:string" 
fixed="bar"/>
+                        // </xs:sequence>
+                        //
+                        // and
+                        //
+                        // <xs:sequence>
+                        //  <xs:element name="foo" type="xs:string" 
minOccurs="3" maxOccurs="3"/>
+                        //  <xs:any namespace="##any" processContents="skip"/>
+                        // </xs:sequence>
+                        //
+                        // In the DFA there will be two transitions from the 
current state which 
+                        // allow "foo". Note that this is not a UPA violation. 
The ambiguity of which
+                        // transition to take is resolved by the current value 
of the counter. Since 
+                        // we've already seen enough instances of the first 
"foo" perhaps there is
+                        // another element declaration or wildcard deeper in 
the element map which
+                        // matches.
+                        unsigned int tempNextState = 0;
+                        
+                        while (++elemIndex < fElemMapSize) {
+                            QName* inElem  = fElemMap[elemIndex];
+                            ContentSpecNode::NodeTypes type = 
fElemMapType[elemIndex];
+                            if (type == ContentSpecNode::Leaf)
+                            {
+                                if (comparator.isEquivalentTo(curElem, inElem) 
)
+                                {
+                                    tempNextState = 
fTransTable[curState][elemIndex];
+                                    if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                        break;
+                                }
+
+                            }
+                            else if ((type & 0x0f)== ContentSpecNode::Any)
+                            {
+                                tempNextState = 
fTransTable[curState][elemIndex];
+                                if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                    break;
+                            }
+                            else if ((type & 0x0f) == ContentSpecNode::Any_NS)
+                            {
+                                if (inElem->getURI() == curElem->getURI())
+                                {
+                                    tempNextState = 
fTransTable[curState][elemIndex];
+                                    if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                        break;
+                                }
+                            }
+                            else if ((type & 0x0f) == 
ContentSpecNode::Any_Other)
+                            {
+                                // Here we assume that empty string has id 1.
+                                //
+                                unsigned int uriId = curElem->getURI();
+                                if (uriId != 1 && uriId != inElem->getURI())
+                                {
+                                    tempNextState = 
fTransTable[curState][elemIndex];
+                                    if (tempNextState != 
XMLContentModel::gInvalidTrans)
+                                        break;
+                                }
+                            }
+                        }
+                        
+                        // if we still can't find a match, report the error
+                        if (elemIndex == fElemMapSize) {
+                            *indexFailingChild=childIndex;
+                            return false;
+                        }
+                        
+                        // if we found a match, set the next state and reset 
the 
+                        // counter if the next state is a counting state.
+                        nextState = tempNextState;
+                        Occurence* o = fCountingStates[nextState];
+                        if (o != 0) {
+                            loopCount = (elemIndex == o->elemIndex) ? 1 : 0;
+                        }
                     }
                 }
                 else if (loopCount < (unsigned int)o->minOccurs) {

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xml
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xml?rev=676924&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xml 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xml Tue 
Jul 15 07:14:56 2008
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<t:Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+             xmlns:t="test"
+             xsi:schemaLocation="test test.xsd">
+            
+<t:Book>Weekly Want Ads</t:Book>
+<t:Book>McLeans</t:Book>
+<t:Book>Software Developers Monthly</t:Book>
+
+<t:Book>McLeans</t:Book>
+<t:Book>Weekly Want Ads</t:Book>
+<t:Book>Software Developers Monthly</t:Book>
+<t:Book>O</t:Book>
+
+</t:Library>

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xsd
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xsd?rev=676924&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xsd 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test.xsd Tue 
Jul 15 07:14:56 2008
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+        xmlns:t="test"
+        targetNamespace="test">
+
+<element name="Book" type="string"/>
+
+<element name="Library">
+  <complexType>
+    <sequence>
+       <element ref="t:Book" minOccurs="3" maxOccurs="3"/>
+       <element ref="t:Book" minOccurs="4" maxOccurs="4"/>
+    </sequence>
+  </complexType>
+</element>
+
+</schema>

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xml
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xml?rev=676924&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xml 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xml Tue 
Jul 15 07:14:56 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!-- =========================================================================
+Test Type : Schema Valid ( <element> )
+Description: A valid instance document used to test a valid schema with
+             example of <element>s with substitutionGroup=.
+========================================================================== -->
+<svi:Library xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance";
+             xmlns:svi ="http://www.schemaTest.org/m3_3v";
+             xsi:schemaLocation="http://www.schemaTest.org/m3_3v
+                                 test2.xsd">
+
+<svi:Periodical>Weekly Want Ads</svi:Periodical>
+
+<svi:Periodical>Weekly Want Ads</svi:Periodical>
+<svi:Magazine>McLeans</svi:Magazine>
+<svi:Newsletter>Software Developers Monthly</svi:Newsletter>
+
+<svi:Magazine>McLeans</svi:Magazine>
+<svi:Periodical>Weekly Want Ads</svi:Periodical>
+<svi:Newsletter>Software Developers Monthly</svi:Newsletter>
+<svi:Book>O</svi:Book>
+
+<svi:Newsletter>Software Developers Monthly</svi:Newsletter>
+
+</svi:Library> 
\ No newline at end of file

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xsd
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xsd?rev=676924&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xsd 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-1817/test2.xsd Tue 
Jul 15 07:14:56 2008
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<!-- =========================================================================
+Test Type : Schema Valid ( <element> )
+Description: Tests valid substitutionGroup= for <element>s with valid derived
+             <simpleType> definitions.
+========================================================================== -->
+<schema xmlns ="http://www.w3.org/2001/XMLSchema";
+        xmlns:sv ="http://www.schemaTest.org/m3_3v";
+        targetNamespace="http://www.schemaTest.org/m3_3v";>
+
+<element name="Magazine" type="sv:strMin5" substitutionGroup="sv:Book"/>
+
+<element name="Book" type="string"/>
+
+<element name="Periodical" type="sv:strMin10" substitutionGroup="sv:Magazine"/>
+
+<element name="Newsletter" substitutionGroup="sv:Magazine">
+<simpleType>
+<restriction base="sv:strMin5">
+<minLength value="15"/>
+</restriction>
+</simpleType>
+</element>
+
+<simpleType name="strMin5">
+<restriction base="string">
+<minLength value="5"/>
+</restriction>
+</simpleType>
+
+<simpleType name="strMin10">
+<restriction base="sv:strMin5">
+<minLength value="10"/>
+</restriction>
+</simpleType>
+
+<element name="Library">
+<complexType>
+<sequence>
+<element ref="sv:Periodical"/>
+<element ref="sv:Magazine" minOccurs="3" maxOccurs="3"/>
+<element ref="sv:Book" minOccurs="4" maxOccurs="4"/>
+<element ref="sv:Newsletter"/>
+</sequence>
+</complexType>
+</element>
+
+</schema>
\ No newline at end of file

Modified: xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet?rev=676924&r1=676923&r2=676924&view=diff
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet (original)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet Tue Jul 15 
07:14:56 2008
@@ -467,4 +467,36 @@
                        <current status="accepted" date="2008-06-24"/>
                </instanceTest>
        </testGroup>
+       <testGroup name="XERCESC-1817-1">
+               <annotation>
+                       <documentation>Regression - Schema Error for valid 
Substition Group</documentation>
+               </annotation>
+               <documentationReference 
xlink:href="https://issues.apache.org/jira/browse/XERCESC-1817"/>
+               <schemaTest name="XERCESC-1817-1-1">
+                       <schemaDocument xlink:href="./XERCESC-1817/test.xsd"/>
+                       <expected validity="valid"/>
+                       <current status="accepted" date="2008-07-15"/>
+               </schemaTest>
+                <instanceTest name="XERCESC-1817-1-2">
+                       <instanceDocument xlink:href="./XERCESC-1817/test.xml"/>
+                       <expected validity="valid"/>
+                       <current status="accepted" date="2008-07-15"/>
+               </instanceTest>
+       </testGroup>
+       <testGroup name="XERCESC-1817-2">
+               <annotation>
+                       <documentation>Regression - Schema Error for valid 
Substition Group</documentation>
+               </annotation>
+               <documentationReference 
xlink:href="https://issues.apache.org/jira/browse/XERCESC-1817"/>
+               <schemaTest name="XERCESC-1817-2-1">
+                       <schemaDocument xlink:href="./XERCESC-1817/test2.xsd"/>
+                       <expected validity="valid"/>
+                       <current status="accepted" date="2008-07-15"/>
+               </schemaTest>
+                <instanceTest name="XERCESC-1817-2-2">
+                       <instanceDocument 
xlink:href="./XERCESC-1817/test2.xml"/>
+                       <expected validity="valid"/>
+                       <current status="accepted" date="2008-07-15"/>
+               </instanceTest>
+       </testGroup>
 </testSet>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to