AddChoice() public méthode

public AddChoice ( ) : void
Résultat void
 private bool BuildParticleContentModel(ParticleContentValidator contentValidator, XmlSchemaParticle particle)
 {
     bool flag = false;
     if (particle is XmlSchemaElement)
     {
         XmlSchemaElement element = (XmlSchemaElement) particle;
         contentValidator.AddName(element.QualifiedName, element);
     }
     else if (particle is XmlSchemaAny)
     {
         flag = true;
         XmlSchemaAny any = (XmlSchemaAny) particle;
         contentValidator.AddNamespaceList(any.NamespaceList, any);
     }
     else if (particle is XmlSchemaGroupBase)
     {
         XmlSchemaObjectCollection items = ((XmlSchemaGroupBase) particle).Items;
         bool flag2 = particle is XmlSchemaChoice;
         contentValidator.OpenGroup();
         bool flag3 = true;
         for (int i = 0; i < items.Count; i++)
         {
             if (flag3)
             {
                 flag3 = false;
             }
             else if (flag2)
             {
                 contentValidator.AddChoice();
             }
             else
             {
                 contentValidator.AddSequence();
             }
             flag = this.BuildParticleContentModel(contentValidator, (XmlSchemaParticle) items[i]);
         }
         contentValidator.CloseGroup();
     }
     if ((particle.MinOccurs != 1M) || (particle.MaxOccurs != 1M))
     {
         if ((particle.MinOccurs == 0M) && (particle.MaxOccurs == 1M))
         {
             contentValidator.AddQMark();
             return flag;
         }
         if ((particle.MinOccurs == 0M) && (particle.MaxOccurs == 79228162514264337593543950335M))
         {
             contentValidator.AddStar();
             return flag;
         }
         if ((particle.MinOccurs == 1M) && (particle.MaxOccurs == 79228162514264337593543950335M))
         {
             contentValidator.AddPlus();
             return flag;
         }
         contentValidator.AddLeafRange(particle.MinOccurs, particle.MaxOccurs);
     }
     return flag;
 }
Exemple #2
0
        private void ParseElementMixedContent(ParticleContentValidator pcv, int startParenEntityId)
        {
            bool hasNames = false;
            int connectorEntityId = -1;
            int contentEntityId = _currentEntityId;

            for (;;)
            {
                switch (GetToken(false))
                {
                    case Token.RightParen:
                        pcv.CloseGroup();
                        if (_validate && _currentEntityId != startParenEntityId)
                        {
                            SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                        }
                        if (GetToken(false) == Token.Star && hasNames)
                        {
                            pcv.AddStar();
                        }
                        else if (hasNames)
                        {
                            ThrowUnexpectedToken(_curPos, "*");
                        }
                        return;
                    case Token.Or:
                        if (!hasNames)
                        {
                            hasNames = true;
                        }
                        else
                        {
                            pcv.AddChoice();
                        }
                        if (_validate)
                        {
                            connectorEntityId = _currentEntityId;
                            if (contentEntityId < connectorEntityId)
                            {  // entity repl.text starting with connector
                                SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                            }
                        }

                        if (GetToken(false) != Token.QName)
                        {
                            goto default;
                        }

                        XmlQualifiedName name = GetNameQualified(true);
                        if (pcv.Exists(name) && _validate)
                        {
                            SendValidationEvent(XmlSeverityType.Error, SR.Sch_DupElement, name.ToString());
                        }
                        pcv.AddName(name, null);

                        if (_validate)
                        {
                            contentEntityId = _currentEntityId;
                            if (contentEntityId < connectorEntityId)
                            { // entity repl.text ending with connector
                                SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                            }
                        }
                        continue;
                    default:
                        OnUnexpectedError();
                        break;
                }
            }
        }
Exemple #3
0
        private void ParseElementOnlyContent(ParticleContentValidator pcv, int startParenEntityId)
        {
            Stack<ParseElementOnlyContent_LocalFrame> localFrames = new Stack<ParseElementOnlyContent_LocalFrame>();
            ParseElementOnlyContent_LocalFrame currentFrame = new ParseElementOnlyContent_LocalFrame(startParenEntityId);
            localFrames.Push(currentFrame);

        RecursiveCall:

        Loop:
            switch (GetToken(false))
            {
                case Token.QName:
                    pcv.AddName(GetNameQualified(true), null);
                    ParseHowMany(pcv);
                    break;
                case Token.LeftParen:
                    pcv.OpenGroup();

                    // We could just do this:
                    // ParseElementOnlyContent( pcv, currentEntityId );
                    // 
                    // But that would be recursion - so we will simulate the call using our localFrames stack 
                    //   instead. 
                    currentFrame =
                        new ParseElementOnlyContent_LocalFrame(_currentEntityId);
                    localFrames.Push(currentFrame);
                    goto RecursiveCall;
                // And we should return here when we return from recursion call 
                //   but it's the same as returning after the switch statement 

                case Token.GreaterThan:
                    Throw(_curPos, SR.Xml_InvalidContentModel);
                    goto Return;
                default:
                    goto UnexpectedError;
            }

        ReturnFromRecursiveCall:
            switch (GetToken(false))
            {
                case Token.Comma:
                    if (currentFrame.parsingSchema == Token.Or)
                    {
                        Throw(_curPos, SR.Xml_InvalidContentModel);
                    }
                    pcv.AddSequence();
                    currentFrame.parsingSchema = Token.Comma;
                    break;
                case Token.Or:
                    if (currentFrame.parsingSchema == Token.Comma)
                    {
                        Throw(_curPos, SR.Xml_InvalidContentModel);
                    }
                    pcv.AddChoice();
                    currentFrame.parsingSchema = Token.Or;
                    break;
                case Token.RightParen:
                    pcv.CloseGroup();
                    if (_validate && _currentEntityId != currentFrame.startParenEntityId)
                    {
                        SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                    }
                    ParseHowMany(pcv);
                    goto Return;
                case Token.GreaterThan:
                    Throw(_curPos, SR.Xml_InvalidContentModel);
                    goto Return;
                default:
                    goto UnexpectedError;
            }
            goto Loop;

        UnexpectedError:
            OnUnexpectedError();

        Return:
            // This is equivalent to return; statement
            //   we simlate it using our localFrames stack
            localFrames.Pop();
            if (localFrames.Count > 0)
            {
                currentFrame = (ParseElementOnlyContent_LocalFrame)localFrames.Peek();
                goto ReturnFromRecursiveCall;
            }
            else
            {
                return;
            }
        }
 private bool BuildParticleContentModel(ParticleContentValidator contentValidator, XmlSchemaParticle particle) {
     bool hasWildCard = false;
     if (particle is XmlSchemaElement) {
         XmlSchemaElement element = (XmlSchemaElement)particle;
         contentValidator.AddName(element.QualifiedName, element);       
      }
     else if (particle is XmlSchemaAny) {
         hasWildCard = true;
         XmlSchemaAny any = (XmlSchemaAny)particle;
         contentValidator.AddNamespaceList(any.NamespaceList, any);
     }
     else if (particle is XmlSchemaGroupBase) {
         XmlSchemaObjectCollection particles = ((XmlSchemaGroupBase)particle).Items;
         bool isChoice = particle is XmlSchemaChoice;
         contentValidator.OpenGroup();
         bool first = true;
         for (int i = 0; i < particles.Count; ++i) {
             Debug.Assert(!((XmlSchemaParticle)particles[i]).IsEmpty);
             if (first) {
                 first = false;
             }
             else if (isChoice) {
                 contentValidator.AddChoice();  
             }
             else {
                 contentValidator.AddSequence();
             }
             hasWildCard = BuildParticleContentModel(contentValidator, (XmlSchemaParticle)particles[i]);
         }
         contentValidator.CloseGroup();
     }
     else {
         Debug.Assert(false);
     }
     if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.One) {
         // nothing
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.One) {
         contentValidator.AddQMark();
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddStar();
     }
     else if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddPlus();
     }
     else {
         contentValidator.AddLeafRange(particle.MinOccurs, particle.MaxOccurs);
     }
     return hasWildCard;
 }
        private void ParseElementOnlyContent( ParticleContentValidator pcv, int startParenEntityId ) {
            Token parsingSchema = Token.None;
            int connectorEntityId = startParenEntityId;
            int contentEntityId = -1;

            for (;;) {
                switch ( GetToken( false ) ) {
                    case Token.QName:
        
                        pcv.AddName( GetNameQualified(true), null );

                        if ( validate ) {
                            contentEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) {  // entity repl.text ending with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        ParseHowMany( pcv );
                        break;
                    case Token.LeftParen:
                        pcv.OpenGroup();
                        if ( validate ) {
                            contentEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) {  // entity repl.text ending with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        ParseElementOnlyContent( pcv, currentEntityId );
                        break;
                    case Token.GreaterThan:
                        Throw( curPos, Res.Xml_InvalidContentModel );
                        return;
                    default:
                        goto UnexpectedError;
                }

                switch ( GetToken( false ) ) {
                    case Token.Comma:
                        if ( parsingSchema == Token.Or ) {
                            Throw( curPos, Res.Xml_InvalidContentModel );
                        }
                        pcv.AddSequence();
                        parsingSchema = Token.Comma;
                        if ( validate ) {
                            connectorEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) { // entity repl.text starting with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        break;
                    case Token.Or:
                        if ( parsingSchema == Token.Comma ) {
                            Throw( curPos, Res.Xml_InvalidContentModel );
                        }
                        pcv.AddChoice();
                        parsingSchema = Token.Or;
                        if ( validate ) {
                            connectorEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) { // entity repl.text starting with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        break;
                    case Token.RightParen:
                        pcv.CloseGroup();
                        if ( validate && currentEntityId != startParenEntityId ) {
                            SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                        }
                        ParseHowMany( pcv );
                        return;
                    case Token.GreaterThan:
                        Throw( curPos, Res.Xml_InvalidContentModel );
                        return;
                    default:
                        goto UnexpectedError;
                }
            }

        UnexpectedError:
            OnUnexpectedError();
        }
 private void BuildParticleContentModel(ParticleContentValidator contentValidator, XmlSchemaParticle particle) {
     if (particle is XmlSchemaElement) {
         XmlSchemaElement element = (XmlSchemaElement)particle;
         contentValidator.AddName(element.QualifiedName, element);       
     }
     else if (particle is XmlSchemaAny) {
         XmlSchemaAny any = (XmlSchemaAny)particle;
         contentValidator.AddNamespaceList(any.NamespaceList, any);
     }
     else if (particle is XmlSchemaGroupBase) {
         XmlSchemaObjectCollection particles = ((XmlSchemaGroupBase)particle).Items;
         bool isChoice = particle is XmlSchemaChoice;
         contentValidator.OpenGroup();
         bool first = true;
         foreach (XmlSchemaParticle p in particles) {
             Debug.Assert(!p.IsEmpty);
             if (first) {
                 first = false;
             }
             else if (isChoice) {
                 contentValidator.AddChoice();  
             }
             else {
                 contentValidator.AddSequence();
             }
             BuildParticleContentModel(contentValidator, p);
         }
         contentValidator.CloseGroup();
     }
     else {
         Debug.Assert(false);
     }
     if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.One) {
         // nothing
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.One) {
         contentValidator.AddQMark();
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddStar();
     }
     else if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddPlus();
     }
     else {
         contentValidator.AddLeafRange(particle.MinOccurs, particle.MaxOccurs);
     }
 }