Summary description for XmlSchemaParticle.
Inheritance: XmlSchemaAnnotated
		public XsdValidationState Get (XmlSchemaParticle xsobj)
		{
			XsdValidationState got = table [xsobj] as XsdValidationState;
			if (got == null)
				got = Create (xsobj);
			return got;
		}
 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;
 }
 private void ClearCompiledState()
 {
     this.attributeUses = null;
     this.localElements = null;
     this.attributeWildcard = null;
     this.contentTypeParticle = XmlSchemaParticle.Empty;
     this.blockResolved = XmlSchemaDerivationMethod.None;
 }
Beispiel #4
0
        /// <summary>
        /// Insert an element above an existing any item.
        /// </summary>
        /// <param name="particle">The particle in which the any item should be found.</param>
        /// <param name="element">The element to insert.</param>
        /// <returns>true if the element was inserted; false otherwise.</returns>
        private bool InsertElement(XmlSchemaParticle particle, XmlSchemaElement element)
        {
            if (particle is XmlSchemaChoice)
            {
                XmlSchemaChoice choice = (XmlSchemaChoice)particle;

                for (int i = 0; i < choice.Items.Count; i++)
                {
                    XmlSchemaParticle childParticle = (XmlSchemaParticle)choice.Items[i];

                    if (childParticle is XmlSchemaAny)
                    {
                        // index this any element for later removal
                        this.anys[childParticle] = choice;

                        choice.Items.Insert(i, element);
                        return true;
                    }
                    else
                    {
                        if (this.InsertElement(childParticle, element))
                        {
                            return true;
                        }
                    }
                }
            }
            else if (particle is XmlSchemaSequence)
            {
                XmlSchemaSequence sequence = (XmlSchemaSequence)particle;

                for (int i = 0; i < sequence.Items.Count; i++)
                {
                    XmlSchemaParticle childParticle = (XmlSchemaParticle)sequence.Items[i];

                    if (childParticle is XmlSchemaAny)
                    {
                        // index this any element for later removal
                        this.anys[childParticle] = sequence;

                        sequence.Items.Insert(i, element);
                        return true;
                    }
                    else
                    {
                        if (this.InsertElement(childParticle, element))
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
 internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
 {
     if (this.OptimizedParticle != null)
     {
         return(this.OptimizedParticle);
     }
     if (this.Items.Count == 0 || base.ValidatedMaxOccurs == 0m)
     {
         this.OptimizedParticle = XmlSchemaParticle.Empty;
     }
     else if (!isTop && this.Items.Count == 1 && base.ValidatedMinOccurs == 1m && base.ValidatedMaxOccurs == 1m)
     {
         this.OptimizedParticle = ((XmlSchemaParticle)this.Items[0]).GetOptimizedParticle(false);
     }
     else
     {
         XmlSchemaChoice xmlSchemaChoice = new XmlSchemaChoice();
         this.CopyInfo(xmlSchemaChoice);
         for (int i = 0; i < this.Items.Count; i++)
         {
             XmlSchemaParticle xmlSchemaParticle = this.Items[i] as XmlSchemaParticle;
             xmlSchemaParticle = xmlSchemaParticle.GetOptimizedParticle(false);
             if (xmlSchemaParticle != XmlSchemaParticle.Empty)
             {
                 if (xmlSchemaParticle is XmlSchemaChoice && xmlSchemaParticle.ValidatedMinOccurs == 1m && xmlSchemaParticle.ValidatedMaxOccurs == 1m)
                 {
                     XmlSchemaChoice xmlSchemaChoice2 = xmlSchemaParticle as XmlSchemaChoice;
                     for (int j = 0; j < xmlSchemaChoice2.Items.Count; j++)
                     {
                         xmlSchemaChoice.Items.Add(xmlSchemaChoice2.Items[j]);
                         xmlSchemaChoice.CompiledItems.Add(xmlSchemaChoice2.Items[j]);
                     }
                 }
                 else
                 {
                     xmlSchemaChoice.Items.Add(xmlSchemaParticle);
                     xmlSchemaChoice.CompiledItems.Add(xmlSchemaParticle);
                 }
             }
         }
         if (xmlSchemaChoice.Items.Count == 0)
         {
             this.OptimizedParticle = XmlSchemaParticle.Empty;
         }
         else
         {
             this.OptimizedParticle = xmlSchemaChoice;
         }
     }
     return(this.OptimizedParticle);
 }
Beispiel #6
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;

            if (xmlSchemaAny == null)
            {
                if (raiseError)
                {
                    base.error(h, "Invalid particle derivation by restriction was found.");
                }
                return(false);
            }
            return(this.ValidateOccurenceRangeOK(baseParticle, h, schema, raiseError) && this.wildcard.ValidateWildcardSubset(xmlSchemaAny.wildcard, h, schema, raiseError));
        }
Beispiel #7
0
 internal void CopyOptimizedItems(XmlSchemaGroupBase gb)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
         p = p.GetOptimizedParticle(false);
         if (p == XmlSchemaParticle.Empty)
         {
             continue;
         }
         gb.Items.Add(p);
         gb.CompiledItems.Add(p);
     }
 }
Beispiel #8
0
        private Sequence PopulateSequence(ComplexType ct)
        {
            Particle p = PopulateParticle(ct);
            Sequence s = p as Sequence;

            if (s != null)
            {
                return(s);
            }
            else
            {
                throw Error(ct, String.Format("Target complexType contains unacceptable type of particle {0}", p));
            }
        }
Beispiel #9
0
        public override ArrayList ExpectedParticles(ValidationState context, bool isRequiredOnly, XmlSchemaSet schemaSet)
        {
            ArrayList particles = new ArrayList();
            BitSet    set       = context.CurPos[context.CurrentState.CurPosIndex];

            for (int i = set.NextSet(-1); i != -1; i = set.NextSet(i))
            {
                XmlSchemaParticle p = (XmlSchemaParticle)this.positions[i].particle;
                if (p != null)
                {
                    ContentValidator.AddParticleToExpected(p, schemaSet, particles);
                }
            }
            return(particles);
        }
Beispiel #10
0
 internal virtual bool ValidateOccurenceRangeOK(XmlSchemaParticle other,
                                                ValidationEventHandler h, XmlSchema schema, bool raiseError)
 {
     if ((this.ValidatedMinOccurs < other.ValidatedMinOccurs) ||
         (other.ValidatedMaxOccurs != decimal.MaxValue &&
          this.ValidatedMaxOccurs > other.ValidatedMaxOccurs))
     {
         if (raiseError)
         {
             error(h, "Invalid derivation occurence range was found.");
         }
         return(false);
     }
     return(true);
 }
 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
 {
     if (base.IsValidated(schema.CompilationId))
     {
         return(this.errorCount);
     }
     base.CompiledItems.Clear();
     foreach (XmlSchemaObject xmlSchemaObject in this.Items)
     {
         XmlSchemaParticle xmlSchemaParticle = (XmlSchemaParticle)xmlSchemaObject;
         this.errorCount += xmlSchemaParticle.Validate(h, schema);
         base.CompiledItems.Add(xmlSchemaParticle);
     }
     this.ValidationId = schema.ValidationId;
     return(this.errorCount);
 }
Beispiel #12
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;
            XmlSchemaAll xmlSchemaAll = baseParticle as XmlSchemaAll;

            if (xmlSchemaAny != null)
            {
                return(base.ValidateNSRecurseCheckCardinality(xmlSchemaAny, h, schema, raiseError));
            }
            if (xmlSchemaAll != null)
            {
                return(this.ValidateOccurenceRangeOK(xmlSchemaAll, h, schema, raiseError) && base.ValidateRecurse(xmlSchemaAll, h, schema, raiseError));
            }
            if (raiseError)
            {
                base.error(h, "Invalid -all- particle derivation was found.");
            }
            return(false);
        }
Beispiel #13
0
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (OptimizedParticle != null)
            {
                return(OptimizedParticle);
            }
            if (Items.Count == 0 || ValidatedMaxOccurs == 0)
            {
                OptimizedParticle = XmlSchemaParticle.Empty;
                return(OptimizedParticle);
            }
            else if (Items.Count == 1)
            {
                if (ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1)
                {
                    XmlSchemaSequence seq = new XmlSchemaSequence();
                    this.CopyInfo(seq);
                    XmlSchemaParticle p = (XmlSchemaParticle)Items [0];
                    p = p.GetOptimizedParticle(false);
                    if (p == XmlSchemaParticle.Empty)
                    {
                        OptimizedParticle = p;
                    }
                    else
                    {
                        seq.Items.Add(p);
                        seq.CompiledItems.Add(p);
                        seq.Compile(null, schema);
                        OptimizedParticle = seq;
                    }
                    return(OptimizedParticle);
                }
            }

            XmlSchemaAll all = new XmlSchemaAll();

            CopyInfo(all);
            CopyOptimizedItems(all);
            OptimizedParticle = all;
            all.ComputeEmptiable();

            return(OptimizedParticle);
        }
        public override ArrayList ExpectedElements(ValidationState context, bool isRequiredOnly)
        {
            ArrayList list = null;

            if (context.RunningPositions != null)
            {
                List <RangePositionInfo> runningPositions = context.RunningPositions;
                BitSet set = new BitSet(this.positions.Count);
                for (int i = context.CurrentState.NumberOfRunningPos - 1; i >= 0; i--)
                {
                    set.Or(runningPositions[i].curpos);
                }
                for (int j = set.NextSet(-1); j != -1; j = set.NextSet(j))
                {
                    if (list == null)
                    {
                        list = new ArrayList();
                    }
                    if (this.positions[j].symbol >= 0)
                    {
                        XmlSchemaParticle particle = this.positions[j].particle as XmlSchemaParticle;
                        if (particle == null)
                        {
                            string str = this.symbols.NameOf(this.positions[j].symbol);
                            if (str.Length != 0)
                            {
                                list.Add(str);
                            }
                        }
                        else
                        {
                            string nameString = particle.NameString;
                            if (!list.Contains(nameString))
                            {
                                list.Add(nameString);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Beispiel #15
0
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (OptimizedParticle != null)
            return OptimizedParticle;

            if (Items.Count == 0 || ValidatedMaxOccurs == 0)
            OptimizedParticle = XmlSchemaParticle.Empty;
            // LAMESPEC: Regardless of isTop, it should remove pointless particle. It seems ContentTypeParticle design bug.
            else if (!isTop && Items.Count == 1 && ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1)
            OptimizedParticle = ((XmlSchemaParticle) Items [0]).GetOptimizedParticle (false);
            else
            {
            XmlSchemaChoice c = new XmlSchemaChoice ();
            CopyInfo (c);
            for (int i = 0; i < Items.Count; i++)
            {
                XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
                p = p.GetOptimizedParticle (false);
                if (p == XmlSchemaParticle.Empty)
                    continue;
                else if (p is XmlSchemaChoice && p.ValidatedMinOccurs == 1 && p.ValidatedMaxOccurs == 1)
                {
                    XmlSchemaChoice pc = p as XmlSchemaChoice;
                    for (int ci = 0; ci < pc.Items.Count; ci++)
                    {
                        c.Items.Add (pc.Items [ci]);
                        c.CompiledItems.Add (pc.Items [ci]);
                    }
                }
                else
                {
                    c.Items.Add (p);
                    c.CompiledItems.Add (p);
                }
            }
            if (c.Items.Count == 0)
                OptimizedParticle = XmlSchemaParticle.Empty;
            else
                OptimizedParticle = c;
            }
            return OptimizedParticle;
        }
Beispiel #16
0
        /*
         * private bool ValidateRecurseLax (XmlSchemaGroupBase baseGroup,
         *      ValidationEventHandler h, XmlSchema schema, bool raiseError)
         * {
         *      int index = 0;
         *      for (int i = 0; i < baseGroup.CompiledItems.Count; i++) {
         *              XmlSchemaParticle pb = (XmlSchemaParticle) baseGroup.CompiledItems [i];
         *              pb = pb.GetOptimizedParticle (false);
         *              if (pb == XmlSchemaParticle.Empty)
         *                      continue;
         *              XmlSchemaParticle pd = null;
         *              while (this.CompiledItems.Count > index) {
         *                      pd = (XmlSchemaParticle) this.CompiledItems [index];
         *                      pd = pd.GetOptimizedParticle (false);
         *                      index++;
         *                      if (pd != XmlSchemaParticle.Empty)
         *                              break;
         *              }
         *              if (!ValidateParticleSection (ref index, pd, pb, h, schema, raiseError))
         *                      continue;
         *      }
         *      if (this.CompiledItems.Count > 0 && index != this.CompiledItems.Count) {
         *              if (raiseError)
         *                      error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");
         *              return false;
         *      }
         *      return true;
         * }
         */

        private bool ValidateParticleSection(ref int index, XmlSchemaParticle pd, XmlSchemaParticle pb, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            if (pd == pb)             // they are same particle
            {
                return(true);
            }

            if (pd != null)
            {
//				XmlSchemaElement el = pd as XmlSchemaElement;
                XmlSchemaParticle pdx = pd;
//				if (el != null && el.SubstitutingElements.Count > 0)
//					pdx = el.SubstitutingChoice;

                if (!pdx.ValidateDerivationByRestriction(pb, h, schema, false))
                {
                    if (!pb.ValidateIsEmptiable())
                    {
                        if (raiseError)
                        {
                            error(h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.");
                        }
                        return(false);
                    }
                    else
                    {
                        index--;                         // try the same derived particle and next base particle.
                        return(false);
                    }
                }
            }
            else if (!pb.ValidateIsEmptiable())
            {
                if (raiseError)
                {
                    error(h, "Invalid particle derivation by restriction was found. Base schema particle has non-emptiable sub particle that is not mapped to the derived particle.");
                }
                return(false);
            }

            return(true);
        }
Beispiel #17
0
        public static IEnumerable<XmlSchemaElement> GetAlternativesFromParticle(XmlSchemaParticle particle)
        {
            if (particle is XmlSchemaElement)
            {
                yield return particle as XmlSchemaElement;
                yield break;
            }

            XmlSchemaParticle result;

            XmlSchemaSequence seq = particle as XmlSchemaSequence;
            if (seq != null)
            {
                foreach (XmlSchemaObject o in seq.Items)
                {
                    result = o as XmlSchemaParticle;
                    if (result != null)
                    {
                        foreach (XmlSchemaElement el in GetAlternativesFromParticle(result))
                        {
                            yield return el;
                        }
                    }
                }
            }

            XmlSchemaChoice ch = particle as XmlSchemaChoice;
            if (ch != null)
            {
                foreach (XmlSchemaObject a in ch.Items)
                {
                    result = a as XmlSchemaParticle;
                    if (result != null)
                    {
                        foreach (XmlSchemaElement el2 in GetAlternativesFromParticle(result))
                        {
                            yield return el2;
                        }
                    }
                }
            }
        }
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;

            if (xmlSchemaAny != null)
            {
                return(base.ValidateNSRecurseCheckCardinality(xmlSchemaAny, h, schema, raiseError));
            }
            XmlSchemaChoice xmlSchemaChoice = baseParticle as XmlSchemaChoice;

            if (xmlSchemaChoice != null)
            {
                return(this.ValidateOccurenceRangeOK(xmlSchemaChoice, h, schema, raiseError) && ((xmlSchemaChoice.ValidatedMinOccurs == 0m && xmlSchemaChoice.ValidatedMaxOccurs == 0m && base.ValidatedMinOccurs == 0m && base.ValidatedMaxOccurs == 0m) || base.ValidateSeqRecurseMapSumCommon(xmlSchemaChoice, h, schema, true, false, raiseError)));
            }
            if (raiseError)
            {
                base.error(h, "Invalid choice derivation by restriction was found.");
            }
            return(false);
        }
Beispiel #19
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle,
                                                               ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny baseAny = baseParticle as XmlSchemaAny;

            if (baseAny == null)
            {
                if (raiseError)
                {
                    error(h, "Invalid particle derivation by restriction was found.");
                }
                return(false);
            }
            // 3.9.6 Particle Derivation OK (Any:Any - NSSubset)
            if (!ValidateOccurenceRangeOK(baseParticle, h, schema, raiseError))
            {
                return(false);
            }
            return(wildcard.ValidateWildcardSubset(baseAny.wildcard, h, schema, raiseError));
        }
Beispiel #20
0
        internal static bool HasParticleRef(XmlSchemaParticle?particle, XmlSchema?parentSchema)
        {
            XmlSchemaGroupBase?groupBase = particle as XmlSchemaGroupBase;

            if (groupBase != null)
            {
                bool foundRef = false;
                int  i        = 0;
                while (i < groupBase.Items.Count && !foundRef)
                {
                    XmlSchemaParticle p = (XmlSchemaParticle)groupBase.Items[i++];
                    if (p is XmlSchemaGroupRef)
                    {
                        foundRef = true;
                    }
                    else
                    {
                        XmlSchemaElement?elem = p as XmlSchemaElement;
                        // This is the same condition as in the CloneParticle method
                        //   that's on purpose. This method is used to determine if we need to clone the whole particle.
                        //   If we do, then the CloneParticle is called and it will try to clone only
                        //   those elements which need cloning - and those are the ones matching this condition.
                        if (elem != null && (!elem.RefName.IsEmpty || !elem.SchemaTypeName.IsEmpty ||
                                             GetResolvedElementForm(parentSchema, elem) == XmlSchemaForm.Qualified))
                        {
                            foundRef = true;
                        }
                        else
                        {
                            foundRef = HasParticleRef(p, parentSchema);
                        }
                    }
                }
                return(foundRef);
            }
            else if (particle is XmlSchemaGroupRef)
            {
                return(true);
            }
            return(false);
        }
Beispiel #21
0
        internal override bool ParticleEquals(XmlSchemaParticle other)
        {
            XmlSchemaAny xmlSchemaAny = other as XmlSchemaAny;

            if (xmlSchemaAny == null)
            {
                return(false);
            }
            if (this.HasValueAny != xmlSchemaAny.HasValueAny || this.HasValueLocal != xmlSchemaAny.HasValueLocal || this.HasValueOther != xmlSchemaAny.HasValueOther || this.HasValueTargetNamespace != xmlSchemaAny.HasValueTargetNamespace || this.ResolvedProcessContents != xmlSchemaAny.ResolvedProcessContents || base.ValidatedMaxOccurs != xmlSchemaAny.ValidatedMaxOccurs || base.ValidatedMinOccurs != xmlSchemaAny.ValidatedMinOccurs || this.ResolvedNamespaces.Count != xmlSchemaAny.ResolvedNamespaces.Count)
            {
                return(false);
            }
            for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
            {
                if (this.ResolvedNamespaces[i] != xmlSchemaAny.ResolvedNamespaces[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #22
0
		internal override bool ParticleEquals (XmlSchemaParticle other)
		{
			XmlSchemaGroupBase gb = other as XmlSchemaGroupBase;
			if (gb == null)
				return false;
			if (this.GetType () != gb.GetType ())
				return false;

			if (this.ValidatedMaxOccurs != gb.ValidatedMaxOccurs ||
				this.ValidatedMinOccurs != gb.ValidatedMinOccurs)
				return false;
			if (this.CompiledItems.Count != gb.CompiledItems.Count)
				return false;
			for (int i = 0; i < CompiledItems.Count; i++) {
				XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle;
				XmlSchemaParticle p2 = gb.CompiledItems [i] as XmlSchemaParticle;
				if (!p1.ParticleEquals (p2))
					return false;
			}
			return true;
		}
        public override ArrayList ExpectedParticles(ValidationState context, bool isRequiredOnly, XmlSchemaSet schemaSet)
        {
            ArrayList particles = new ArrayList();

            int[] numArray = this.transitionTable[context.CurrentState.State];
            if (numArray != null)
            {
                for (int i = 0; i < (numArray.Length - 1); i++)
                {
                    if (numArray[i] != -1)
                    {
                        XmlSchemaParticle p = (XmlSchemaParticle)this.symbols.GetParticle(i);
                        if (p != null)
                        {
                            ContentValidator.AddParticleToExpected(p, schemaSet, particles);
                        }
                    }
                }
            }
            return(particles);
        }
Beispiel #24
0
        private void ValidateUPAOnItems(XmlSchemaObjectTable qnames, ArrayList nsNames, ValidationEventHandler h, XmlSchema schema)
        {
            XmlSchemaObjectTable xmlSchemaObjectTable  = new XmlSchemaObjectTable();
            ArrayList            arrayList             = new ArrayList();
            XmlSchemaObjectTable xmlSchemaObjectTable2 = new XmlSchemaObjectTable();
            ArrayList            arrayList2            = new ArrayList();

            for (int i = 0; i < this.Items.Count; i++)
            {
                XmlSchemaParticle xmlSchemaParticle = this.Items[i] as XmlSchemaParticle;
                xmlSchemaParticle.ValidateUniqueParticleAttribution(xmlSchemaObjectTable, arrayList, h, schema);
                if (xmlSchemaParticle.ValidatedMinOccurs == xmlSchemaParticle.ValidatedMaxOccurs)
                {
                    xmlSchemaObjectTable.Clear();
                    arrayList.Clear();
                }
                else
                {
                    if (xmlSchemaParticle.ValidatedMinOccurs != 0m)
                    {
                        foreach (object obj in xmlSchemaObjectTable2.Names)
                        {
                            XmlQualifiedName name = (XmlQualifiedName)obj;
                            xmlSchemaObjectTable.Set(name, null);
                        }
                        foreach (object obj2 in arrayList2)
                        {
                            arrayList.Remove(obj2);
                        }
                    }
                    foreach (object obj3 in xmlSchemaObjectTable.Names)
                    {
                        XmlQualifiedName name2 = (XmlQualifiedName)obj3;
                        xmlSchemaObjectTable2.Set(name2, xmlSchemaObjectTable[name2]);
                    }
                    arrayList2.Clear();
                    arrayList2.AddRange(arrayList);
                }
            }
        }
Beispiel #25
0
        private Parameter[] GetParameters(string messagePartName)
        {
            List <Parameter> parameters = new List <Parameter>();

            //Types types = serviceDescription.Types;
            //System.Xml.Schema.XmlSchema xmlSchema = types.Schemas[0];

            foreach (XmlSchemaElement schemaElement in e.GlobalElements.Values)
            {
                //}
                //foreach (object item in xmlSchema.Items)
                //{
                //    System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement;
                if (schemaElement != null)
                {
                    if (schemaElement.Name == messagePartName)
                    {
                        System.Xml.Schema.XmlSchemaType        schemaType  = schemaElement.SchemaType;
                        System.Xml.Schema.XmlSchemaComplexType complexType =
                            schemaType as System.Xml.Schema.XmlSchemaComplexType;
                        if (complexType != null)
                        {
                            System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle;
                            System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence;
                            if (sequence != null)
                            {
                                foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items)
                                {
                                    string parameterName = childElement.Name;
                                    string parameterType = childElement.SchemaTypeName.Name;
                                    parameters.Add(new Parameter(parameterName, parameterType, null, null));
                                }
                            }
                        }
                        break;
                    }
                }
            }
            return(parameters.ToArray());
        }
Beispiel #26
0
        void ValidateUPAOnItems(XmlSchemaObjectTable qnames, ArrayList nsNames,
                                ValidationEventHandler h, XmlSchema schema)
        {
            // non-optional components
            XmlSchemaObjectTable elems        = new XmlSchemaObjectTable();
            ArrayList            wildcards    = new ArrayList();
            XmlSchemaObjectTable tmpElems     = new XmlSchemaObjectTable();
            ArrayList            tmpWildcards = new ArrayList();

            for (int i = 0; i < Items.Count; i++)
            {
                XmlSchemaParticle p1 = Items [i] as XmlSchemaParticle;
                p1.ValidateUniqueParticleAttribution(elems, wildcards, h, schema);
                if (p1.ValidatedMinOccurs == p1.ValidatedMaxOccurs)
                {
                    elems.Clear();
                    wildcards.Clear();
                }
                else
                {
                    if (p1.ValidatedMinOccurs != 0)
                    {
                        foreach (XmlQualifiedName n in tmpElems.Names)
                        {
                            elems.Set(n, null);                              // remove
                        }
                        foreach (object o in tmpWildcards)
                        {
                            wildcards.Remove(o);
                        }
                    }
                    foreach (XmlQualifiedName n in elems.Names)
                    {
                        tmpElems.Set(n, elems [n]);
                    }
                    tmpWildcards.Clear();
                    tmpWildcards.AddRange(wildcards);
                }
            }
        }
Beispiel #27
0
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (this.OptimizedParticle != null)
            {
                return(this.OptimizedParticle);
            }
            if (this.Items.Count == 0 || base.ValidatedMaxOccurs == 0m)
            {
                this.OptimizedParticle = XmlSchemaParticle.Empty;
                return(this.OptimizedParticle);
            }
            if (this.Items.Count == 1 && base.ValidatedMinOccurs == 1m && base.ValidatedMaxOccurs == 1m)
            {
                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
                this.CopyInfo(xmlSchemaSequence);
                XmlSchemaParticle xmlSchemaParticle = (XmlSchemaParticle)this.Items[0];
                xmlSchemaParticle = xmlSchemaParticle.GetOptimizedParticle(false);
                if (xmlSchemaParticle == XmlSchemaParticle.Empty)
                {
                    this.OptimizedParticle = xmlSchemaParticle;
                }
                else
                {
                    xmlSchemaSequence.Items.Add(xmlSchemaParticle);
                    xmlSchemaSequence.CompiledItems.Add(xmlSchemaParticle);
                    xmlSchemaSequence.Compile(null, this.schema);
                    this.OptimizedParticle = xmlSchemaSequence;
                }
                return(this.OptimizedParticle);
            }
            XmlSchemaAll xmlSchemaAll = new XmlSchemaAll();

            this.CopyInfo(xmlSchemaAll);
            base.CopyOptimizedItems(xmlSchemaAll);
            this.OptimizedParticle = xmlSchemaAll;
            xmlSchemaAll.ComputeEmptiable();
            return(this.OptimizedParticle);
        }
 public static void AddParticleToExpected(XmlSchemaParticle p, XmlSchemaSet schemaSet, ArrayList particles, bool global)
 {
     if (!particles.Contains(p))
     {
         particles.Add(p);
     }
     XmlSchemaElement element = p as XmlSchemaElement;
     if ((element != null) && (global || !element.RefName.IsEmpty))
     {
         XmlSchemaSubstitutionGroup group = (XmlSchemaSubstitutionGroup) schemaSet.SubstitutionGroups[element.QualifiedName];
         if (group != null)
         {
             for (int i = 0; i < group.Members.Count; i++)
             {
                 XmlSchemaElement item = (XmlSchemaElement) group.Members[i];
                 if (!element.QualifiedName.Equals(item.QualifiedName) && !particles.Contains(item))
                 {
                     particles.Add(item);
                 }
             }
         }
     }
 }
        public override ArrayList ExpectedElements(ValidationState context, bool isRequiredOnly)
        {
            ArrayList list = null;

            int[] numArray = this.transitionTable[context.CurrentState.State];
            if (numArray != null)
            {
                for (int i = 0; i < (numArray.Length - 1); i++)
                {
                    if (numArray[i] != -1)
                    {
                        if (list == null)
                        {
                            list = new ArrayList();
                        }
                        XmlSchemaParticle particle = (XmlSchemaParticle)this.symbols.GetParticle(i);
                        if (particle == null)
                        {
                            string str = this.symbols.NameOf(i);
                            if (str.Length != 0)
                            {
                                list.Add(str);
                            }
                        }
                        else
                        {
                            string nameString = particle.NameString;
                            if (!list.Contains(nameString))
                            {
                                list.Add(nameString);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Beispiel #30
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle,
                                                               ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny any = baseParticle as XmlSchemaAny;

            if (any != null)
            {
                // NSRecurseCheckCardinality
                return(ValidateNSRecurseCheckCardinality(any, h, schema, raiseError));
            }

            XmlSchemaChoice choice = baseParticle as XmlSchemaChoice;

            if (choice != null)
            {
                // RecurseLax
                if (!ValidateOccurenceRangeOK(choice, h, schema, raiseError))
                {
                    return(false);
                }

                // If it is totally optional, then ignore their contents.
                if (choice.ValidatedMinOccurs == 0 && choice.ValidatedMaxOccurs == 0 &&
                    this.ValidatedMinOccurs == 0 && this.ValidatedMaxOccurs == 0)
                {
                    return(true);
                }
//				return ValidateRecurseLax (choice, h, schema, raiseError);
                return(this.ValidateSeqRecurseMapSumCommon(choice, h, schema, true, false, raiseError));
            }

            if (raiseError)
            {
                error(h, "Invalid choice derivation by restriction was found.");
            }
            return(false);
        }
 internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema)
 {
     XmlSchemaGroupBase base2 = particle as XmlSchemaGroupBase;
     if (base2 != null)
     {
         XmlSchemaGroupBase base3 = base2;
         XmlSchemaObjectCollection newItems = CloneGroupBaseParticles(base2.Items, parentSchema);
         base3 = (XmlSchemaGroupBase) base2.Clone();
         base3.SetItems(newItems);
         return base3;
     }
     if (particle is XmlSchemaGroupRef)
     {
         XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef) particle.Clone();
         ref2.RefName = ref2.RefName.Clone();
         return ref2;
     }
     XmlSchemaElement element = particle as XmlSchemaElement;
     if ((element == null) || ((element.RefName.IsEmpty && element.SchemaTypeName.IsEmpty) && (GetResolvedElementForm(parentSchema, element) != XmlSchemaForm.Qualified)))
     {
         return particle;
     }
     return (XmlSchemaElement) element.Clone(parentSchema);
 }
        internal static bool HasParticleRef(XmlSchemaParticle particle)
        {
            XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase;

            if (groupBase != null && !(groupBase is XmlSchemaAll))
            {
                bool foundRef = false;
                int  i        = 0;
                while (i < groupBase.Items.Count && !foundRef)
                {
                    XmlSchemaParticle p = (XmlSchemaParticle)groupBase.Items[i++];
                    if (p is XmlSchemaGroupRef)
                    {
                        foundRef = true;
                    }
                    else
                    {
                        XmlSchemaElement elem = p as XmlSchemaElement;
                        if (elem != null && (!elem.RefName.IsEmpty || !elem.SchemaTypeName.IsEmpty))
                        {
                            foundRef = true;
                        }
                        else
                        {
                            foundRef = HasParticleRef(p);
                        }
                    }
                }
                return(foundRef);
            }
            else if (particle is XmlSchemaGroupRef)
            {
                return(true);
            }
            return(false);
        }
Beispiel #33
0
        internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema)
        {
            XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase;

            if (groupBase != null)   //Choice or sequence
            {
                XmlSchemaGroupBase newGroupBase = groupBase;

                XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items, parentSchema);
                newGroupBase = (XmlSchemaGroupBase)groupBase.Clone();
                newGroupBase.SetItems(newGroupbaseParticles);
                return(newGroupBase);
            }
            else if (particle is XmlSchemaGroupRef)   // group ref
            {
                XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone();
                newGroupRef.RefName = newGroupRef.RefName.Clone();
                return(newGroupRef);
            }
            else
            {
                XmlSchemaElement oldElem = particle as XmlSchemaElement;
                // If the particle is an element and one of the following is true:
                //   - it references another element by name
                //   - it references its type by name
                //   - it's form (effective) is qualified (meaning it will inherint namespace from chameleon includes if that happens)
                // then the element itself needs to be cloned.
                if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty ||
                                        GetResolvedElementForm(parentSchema, oldElem) == XmlSchemaForm.Qualified))
                {
                    XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone(parentSchema);
                    return(newElem);
                }
            }
            return(particle);
        }
        public static void AddParticleToExpected(XmlSchemaParticle p, XmlSchemaSet schemaSet, ArrayList particles, bool global)
        {
            if (!particles.Contains(p))
            {
                particles.Add(p);
            }
            XmlSchemaElement element = p as XmlSchemaElement;

            if ((element != null) && (global || !element.RefName.IsEmpty))
            {
                XmlSchemaSubstitutionGroup group = (XmlSchemaSubstitutionGroup)schemaSet.SubstitutionGroups[element.QualifiedName];
                if (group != null)
                {
                    for (int i = 0; i < group.Members.Count; i++)
                    {
                        XmlSchemaElement item = (XmlSchemaElement)group.Members[i];
                        if (!element.QualifiedName.Equals(item.QualifiedName) && !particles.Contains(item))
                        {
                            particles.Add(item);
                        }
                    }
                }
            }
        }
 private bool IsParticleEmptiable(XmlSchemaParticle particle)
 {
     decimal num;
     decimal num2;
     this.CalculateEffectiveTotalRange(particle, out num, out num2);
     return (num == 0M);
 }
Beispiel #36
0
 internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle,
                                                        ValidationEventHandler h, XmlSchema schema, bool raiseError)
 {
     return(true);
 }
 private XmlSchemaContentType GetSchemaContentType(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaParticle particle)
 {
     if (((complexContent != null) && complexContent.IsMixed) || ((complexContent == null) && complexType.IsMixed))
     {
         return XmlSchemaContentType.Mixed;
     }
     if ((particle != null) && !particle.IsEmpty)
     {
         return XmlSchemaContentType.ElementOnly;
     }
     return XmlSchemaContentType.Empty;
 }
Beispiel #38
0
        /// <summary>
        /// Finds the element specified in the given stack, starting from the given XML particle.
        /// </summary>
        /// <param name="p_xspParticle">The particle at which to being the search.</param>
        /// <param name="p_stkCode">A stack describing a path to an XML element.</param>
        /// <returns>The element specified by the given stack, or <lang cref="null"/> if no such
        /// element could be found.</returns>
        private XmlSchemaElement findElement(XmlSchemaParticle p_xspParticle, Stack<string> p_stkCode)
        {
            if (p_xspParticle is XmlSchemaElement)
            {
                XmlSchemaElement xseElement = (XmlSchemaElement)p_xspParticle;
                if (p_stkCode.Peek().Equals(xseElement.Name))
                {
                    p_stkCode.Pop();
                    if (p_stkCode.Count == 0)
                        return xseElement;

                    if (xseElement.ElementSchemaType is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType xctElement = (XmlSchemaComplexType)xseElement.ElementSchemaType;
                        if (xctElement.ContentTypeParticle != null)
                            return findElement(xctElement.ContentTypeParticle, p_stkCode);
                    }
                    //if this isn't a complex type, then this element has no children,
                    // so if this isn't the element we are looking for, we are looking
                    // in the wrong part of the schema tree.
                }
            }
            else if (p_xspParticle is XmlSchemaGroupBase)
            {
                //this handle sequences, choices, and all
                XmlSchemaGroupBase xbsGroup = (XmlSchemaGroupBase)p_xspParticle;
                XmlSchemaElement xseElement = null;
                foreach (XmlSchemaParticle xspParticle in xbsGroup.Items)
                {
                    xseElement = findElement(xspParticle, p_stkCode);
                    if (xseElement != null)
                        return xseElement;
                }
            }

            return null;
        }
Beispiel #39
0
		// This method is used only by particles
		internal virtual void CopyInfo (XmlSchemaParticle obj)
		{
			obj.LineNumber = LineNumber;
			obj.LinePosition = LinePosition;
			obj.SourceUri = SourceUri;
			obj.errorCount = errorCount;
			// Other fields and properties may be useless for Particle.
		}
 private XmlSchemaParticle CannonicalizeParticle(XmlSchemaParticle particle, bool root, bool substitution)
 {
     if ((particle == null) || particle.IsEmpty)
     {
         return XmlSchemaParticle.Empty;
     }
     if (particle is XmlSchemaElement)
     {
         return this.CannonicalizeElement((XmlSchemaElement) particle, substitution);
     }
     if (particle is XmlSchemaGroupRef)
     {
         return this.CannonicalizeGroupRef((XmlSchemaGroupRef) particle, root, substitution);
     }
     if (particle is XmlSchemaAll)
     {
         return this.CannonicalizeAll((XmlSchemaAll) particle, root, substitution);
     }
     if (particle is XmlSchemaChoice)
     {
         return this.CannonicalizeChoice((XmlSchemaChoice) particle, root, substitution);
     }
     if (particle is XmlSchemaSequence)
     {
         return this.CannonicalizeSequence((XmlSchemaSequence) particle, root, substitution);
     }
     return particle;
 }
 private void CalculateEffectiveTotalRange(XmlSchemaParticle particle, out decimal minOccurs, out decimal maxOccurs)
 {
     if ((particle is XmlSchemaElement) || (particle is XmlSchemaAny))
     {
         minOccurs = particle.MinOccurs;
         maxOccurs = particle.MaxOccurs;
     }
     else if (particle is XmlSchemaChoice)
     {
         if (((XmlSchemaChoice) particle).Items.Count == 0)
         {
             minOccurs = maxOccurs = 0M;
         }
         else
         {
             minOccurs = 79228162514264337593543950335M;
             maxOccurs = 0M;
             XmlSchemaChoice choice = (XmlSchemaChoice) particle;
             for (int i = 0; i < choice.Items.Count; i++)
             {
                 decimal num2;
                 decimal num3;
                 this.CalculateEffectiveTotalRange((XmlSchemaParticle) choice.Items[i], out num2, out num3);
                 if (num2 < minOccurs)
                 {
                     minOccurs = num2;
                 }
                 if (num3 > maxOccurs)
                 {
                     maxOccurs = num3;
                 }
             }
             minOccurs *= particle.MinOccurs;
             if (maxOccurs != 79228162514264337593543950335M)
             {
                 if (particle.MaxOccurs == 79228162514264337593543950335M)
                 {
                     maxOccurs = 79228162514264337593543950335M;
                 }
                 else
                 {
                     maxOccurs *= particle.MaxOccurs;
                 }
             }
         }
     }
     else
     {
         XmlSchemaObjectCollection items = ((XmlSchemaGroupBase) particle).Items;
         if (items.Count == 0)
         {
             minOccurs = maxOccurs = 0M;
         }
         else
         {
             minOccurs = 0M;
             maxOccurs = 0M;
             for (int j = 0; j < items.Count; j++)
             {
                 decimal num5;
                 decimal num6;
                 this.CalculateEffectiveTotalRange((XmlSchemaParticle) items[j], out num5, out num6);
                 minOccurs += num5;
                 if (maxOccurs != 79228162514264337593543950335M)
                 {
                     if (num6 == 79228162514264337593543950335M)
                     {
                         maxOccurs = 79228162514264337593543950335M;
                     }
                     else
                     {
                         maxOccurs += num6;
                     }
                 }
             }
             minOccurs *= particle.MinOccurs;
             if (maxOccurs != 79228162514264337593543950335M)
             {
                 if (particle.MaxOccurs == 79228162514264337593543950335M)
                 {
                     maxOccurs = 79228162514264337593543950335M;
                 }
                 else
                 {
                     maxOccurs *= particle.MaxOccurs;
                 }
             }
         }
     }
 }
Beispiel #42
0
 internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
 {
     return(this.TargetGroup != null && this.TargetGroup.Particle.ValidateDerivationByRestriction(baseParticle, h, schema, raiseError));
 }
		internal override bool ParticleEquals (XmlSchemaParticle other)
		{
			return this.GetOptimizedParticle (true).ParticleEquals (other);
		}
Beispiel #44
0
		void ImportParticleContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaParticle particle, CodeIdentifiers classIds, bool multiValue, ref bool isMixed)
		{
			if (particle == null) return;
			
			if (particle is XmlSchemaGroupRef)
				particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);

			if (particle.MaxOccurs > 1) multiValue = true;
			
			if (particle is XmlSchemaSequence) {
				ImportSequenceContent (typeQName, cmap, ((XmlSchemaSequence)particle).Items, classIds, multiValue, ref isMixed);
			}
			else if (particle is XmlSchemaChoice) {
				if (((XmlSchemaChoice)particle).Items.Count == 1)
					ImportSequenceContent (typeQName, cmap, ((XmlSchemaChoice)particle).Items, classIds, multiValue, ref isMixed);
				else
					ImportChoiceContent (typeQName, cmap, (XmlSchemaChoice)particle, classIds, multiValue);
			}
			else if (particle is XmlSchemaAll) {
				ImportSequenceContent (typeQName, cmap, ((XmlSchemaAll)particle).Items, classIds, multiValue, ref isMixed);
			}
		}
Beispiel #45
0
 internal override bool ParticleEquals(XmlSchemaParticle other)
 {
     return(this.GetOptimizedParticle(true).ParticleEquals(other));
 }
Beispiel #46
0
		void ImportParticleComplexContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaParticle particle, CodeIdentifiers classIds, bool isMixed)
		{
			ImportParticleContent (typeQName, cmap, particle, classIds, false, ref isMixed);
			if (isMixed) AddTextMember (typeQName, cmap, classIds);
		}
Beispiel #47
0
		bool CheckChoiceType (XmlQualifiedName typeQName, XmlSchemaParticle particle, ArrayList types, ref bool multiValue)
		{
			XmlQualifiedName type = null;

			multiValue = multiValue || particle.MaxOccurs > 1;

			if (particle is XmlSchemaGroupRef)
				return CheckChoiceType (typeQName, GetRefGroupParticle ((XmlSchemaGroupRef)particle), types, ref multiValue);

			if (particle is XmlSchemaElement) {
				string ns;
				XmlSchemaElement elem = (XmlSchemaElement)particle;
				XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
				if (refElem.SchemaType != null) return true;
				type = refElem.SchemaTypeName;
			}
			else if (particle is XmlSchemaAny) {
				type = anyType;
			}
			else if (particle is XmlSchemaSequence)
			{
				XmlSchemaSequence seq = particle as XmlSchemaSequence;
				foreach (XmlSchemaParticle par in seq.Items)
					if (!CheckChoiceType (typeQName, par, types, ref multiValue)) return false;
				return true;
			}
			else if (particle is XmlSchemaChoice)
			{
				foreach (XmlSchemaParticle choice in ((XmlSchemaChoice)particle).Items)
					if (!CheckChoiceType (typeQName, choice, types, ref multiValue)) return false;
				return true;
			}

			if (typeQName.Equals (type)) return false;

			// For primitive types, compare using CLR types, since several
			// xml types can be mapped to a single CLR type

			string t;
			if (IsPrimitiveTypeNamespace (type.Namespace))
				t = TypeTranslator.GetPrimitiveTypeData (type.Name).FullTypeName + ":" + type.Namespace;

			else
				t = type.Name + ":" + type.Namespace;

			if (types.Contains (t)) return false;
			types.Add (t);
			return true;
		}
Beispiel #48
0
		bool CanBeArray (XmlQualifiedName typeQName, XmlSchemaParticle particle, bool multiValue)
		{
			// To be an array, there can't be a direct child of type typeQName

			if (particle == null) return false;

			multiValue = multiValue || particle.MaxOccurs > 1;

			if (particle is XmlSchemaGroupRef)
				return CanBeArray (typeQName, GetRefGroupParticle ((XmlSchemaGroupRef)particle), multiValue);

			if (particle is XmlSchemaElement)
			{
				XmlSchemaElement elem = (XmlSchemaElement)particle;
				if (!elem.RefName.IsEmpty)
					return CanBeArray (typeQName, FindRefElement (elem), multiValue);
				else
					return multiValue && !typeQName.Equals (((XmlSchemaElement)particle).SchemaTypeName);
			}

			if (particle is XmlSchemaAny)
				return multiValue;

			if (particle is XmlSchemaSequence)
			{
				XmlSchemaSequence seq = particle as XmlSchemaSequence;
				if (seq.Items.Count != 1) return false;
				return CanBeArray (typeQName, (XmlSchemaParticle)seq.Items[0], multiValue);
			}

			if (particle is XmlSchemaChoice)
			{
				// Can be array if all choices have different types
				ArrayList types = new ArrayList ();
				if(!CheckChoiceType (typeQName, particle, types, ref multiValue)) return false;
				return multiValue;
			}

			return false;
		}
 private bool IsValidOccurrenceRangeRestriction(XmlSchemaParticle derivedParticle, XmlSchemaParticle baseParticle)
 {
     return this.IsValidOccurrenceRangeRestriction(derivedParticle.MinOccurs, derivedParticle.MaxOccurs, baseParticle.MinOccurs, baseParticle.MaxOccurs);
 }
		internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
			ValidationEventHandler h, XmlSchema schema, bool raiseError)
		{
			if (TargetGroup != null)
				return TargetGroup.Particle.ValidateDerivationByRestriction (baseParticle, h, schema, raiseError);
			else
				return false; // should not occur
		}
 private bool IsValidRestriction(XmlSchemaParticle derivedParticle, XmlSchemaParticle baseParticle)
 {
     if (derivedParticle == baseParticle)
     {
         return true;
     }
     if ((derivedParticle == null) || (derivedParticle == XmlSchemaParticle.Empty))
     {
         return this.IsParticleEmptiable(baseParticle);
     }
     if ((baseParticle != null) && (baseParticle != XmlSchemaParticle.Empty))
     {
         if (baseParticle is XmlSchemaElement)
         {
             return ((derivedParticle is XmlSchemaElement) && this.IsElementFromElement((XmlSchemaElement) derivedParticle, (XmlSchemaElement) baseParticle));
         }
         if (baseParticle is XmlSchemaAny)
         {
             if (derivedParticle is XmlSchemaElement)
             {
                 return this.IsElementFromAny((XmlSchemaElement) derivedParticle, (XmlSchemaAny) baseParticle);
             }
             if (derivedParticle is XmlSchemaAny)
             {
                 return this.IsAnyFromAny((XmlSchemaAny) derivedParticle, (XmlSchemaAny) baseParticle);
             }
             return this.IsGroupBaseFromAny((XmlSchemaGroupBase) derivedParticle, (XmlSchemaAny) baseParticle);
         }
         if (baseParticle is XmlSchemaAll)
         {
             if (derivedParticle is XmlSchemaElement)
             {
                 return this.IsElementFromGroupBase((XmlSchemaElement) derivedParticle, (XmlSchemaGroupBase) baseParticle, true);
             }
             if (derivedParticle is XmlSchemaAll)
             {
                 return this.IsGroupBaseFromGroupBase((XmlSchemaGroupBase) derivedParticle, (XmlSchemaGroupBase) baseParticle, true);
             }
             if (derivedParticle is XmlSchemaSequence)
             {
                 return this.IsSequenceFromAll((XmlSchemaSequence) derivedParticle, (XmlSchemaAll) baseParticle);
             }
         }
         else if (baseParticle is XmlSchemaChoice)
         {
             if (derivedParticle is XmlSchemaElement)
             {
                 return this.IsElementFromGroupBase((XmlSchemaElement) derivedParticle, (XmlSchemaGroupBase) baseParticle, false);
             }
             if (derivedParticle is XmlSchemaChoice)
             {
                 return this.IsGroupBaseFromGroupBase((XmlSchemaGroupBase) derivedParticle, (XmlSchemaGroupBase) baseParticle, false);
             }
             if (derivedParticle is XmlSchemaSequence)
             {
                 return this.IsSequenceFromChoice((XmlSchemaSequence) derivedParticle, (XmlSchemaChoice) baseParticle);
             }
         }
         else if (baseParticle is XmlSchemaSequence)
         {
             if (derivedParticle is XmlSchemaElement)
             {
                 return this.IsElementFromGroupBase((XmlSchemaElement) derivedParticle, (XmlSchemaGroupBase) baseParticle, true);
             }
             if (derivedParticle is XmlSchemaSequence)
             {
                 return this.IsGroupBaseFromGroupBase((XmlSchemaGroupBase) derivedParticle, (XmlSchemaGroupBase) baseParticle, true);
             }
         }
     }
     return false;
 }
 public Particle(XmlSchemaParticle particle)
 {
     XmlParticle = particle;
     MinOccurs = particle.MinOccurs;
     MaxOccurs = particle.MaxOccurs;
 }
 private static void CleanupParticle(XmlSchemaParticle particle)
 {
     if (particle is XmlSchemaElement)
     {
         CleanupElement((XmlSchemaElement) particle);
     }
     else if (particle is XmlSchemaGroupBase)
     {
         XmlSchemaObjectCollection items = ((XmlSchemaGroupBase) particle).Items;
         for (int i = 0; i < items.Count; i++)
         {
             CleanupParticle((XmlSchemaParticle) items[i]);
         }
     }
 }
 private XmlSchemaParticle CompileContentTypeParticle(XmlSchemaParticle particle, bool substitution)
 {
     XmlSchemaParticle particle2 = this.CannonicalizeParticle(particle, true, substitution);
     XmlSchemaChoice source = particle2 as XmlSchemaChoice;
     if ((source == null) || (source.Items.Count != 0))
     {
         return particle2;
     }
     if (source.MinOccurs != 0M)
     {
         base.SendValidationEvent("Sch_EmptyChoice", source, XmlSeverityType.Warning);
     }
     return XmlSchemaParticle.Empty;
 }
Beispiel #55
0
        /// <summary>
        /// Determines if the given XML particle contains the given sibling elements, and populates
        /// the list of elements that are eligible to be the next element in the XML document.
        /// </summary>
        /// <remarks>
        /// A particle contains the siblings if the siblings are children of the given particle.
        /// </remarks>
        /// <param name="p_xspParticle">That XML particle for which it is to be determined if it
        /// contains the given sibling element.</param>
        /// <param name="p_lstChoices">The list of elements that are eligible to be the next element in the XML document.</param>
        /// <param name="p_lstSiblings">A list of sibling elements.</param>
        /// <returns><lang cref="true"/> if the given siblings are contained by the given particle.</returns>
        private bool ContainsSiblings(XmlSchemaParticle p_xspParticle, ref List<KeyValuePair<string, string>> p_lstChoices, List<string> p_lstSiblings)
        {
            if (p_xspParticle is XmlSchemaElement)
            {
                XmlSchemaElement xseElement = (XmlSchemaElement)p_xspParticle;
                string strLastSibling = null;
                if (p_lstSiblings.Count > 0)
                    strLastSibling = p_lstSiblings[p_lstSiblings.Count - 1];
                return xseElement.Name.Equals(strLastSibling);
            }
            else if (p_xspParticle is XmlSchemaSequence)
            {
                XmlSchemaSequence xssSequence = (XmlSchemaSequence)p_xspParticle;
                bool booFound = false;
                Int32 i = 0;
                XmlSchemaParticle xspParticle = null;
                for (i = 0; i < xssSequence.Items.Count; i++)
                {
                    xspParticle = (XmlSchemaParticle)xssSequence.Items[i];
                    if (ContainsSiblings(xspParticle, ref p_lstChoices, p_lstSiblings))
                    {
                        booFound = true;
                        break;
                    }
                }
                if (booFound)
                {
                    if (p_lstChoices == null)
                    {
                        Int32 intLastSiblingCount = 1;
                        for (intLastSiblingCount = p_lstSiblings.Count - 1; (intLastSiblingCount > -1) && p_lstSiblings[intLastSiblingCount].Equals(p_lstSiblings[p_lstSiblings.Count - 1]); intLastSiblingCount--) ;
                        intLastSiblingCount = p_lstSiblings.Count - intLastSiblingCount - 1;

                        List<KeyValuePair<string, string>> lstChoices = new List<KeyValuePair<string, string>>();
                        if (intLastSiblingCount < xspParticle.MaxOccurs)
                            lstChoices.AddRange(GetChildrenElements(xspParticle));
                        for (i++; i < xssSequence.Items.Count; i++)
                        {
                            xspParticle = (XmlSchemaParticle)xssSequence.Items[i];
                            lstChoices.AddRange(GetChildrenElements(xspParticle));
                            if (xspParticle.MinOccurs > 0)
                                break;
                        }
                        if (lstChoices.Count > 0)
                            p_lstChoices = lstChoices;
                    }
                    return true;
                }
            }
            else if (p_xspParticle is XmlSchemaChoice)
            {
                XmlSchemaChoice xscChoice = (XmlSchemaChoice)p_xspParticle;
                foreach (XmlSchemaParticle xspParticle in xscChoice.Items)
                    if (ContainsSiblings(xspParticle, ref p_lstChoices, p_lstSiblings))
                        return true;
            }
            else if (p_xspParticle is XmlSchemaAll)
            {
                XmlSchemaAll xsaAll = (XmlSchemaAll)p_xspParticle;
                bool booFound = false;
                foreach (XmlSchemaParticle xspParticle in xsaAll.Items)
                {
                    if (ContainsSiblings(xspParticle, ref p_lstChoices, p_lstSiblings))
                    {
                        booFound = true;
                        break;
                    }
                }
                if (booFound)
                {
                    if (p_lstChoices == null)
                    {
                        List<KeyValuePair<string, string>> lstChoices = new List<KeyValuePair<string, string>>();
                        List<string> lstSibling = new List<string>();
                        Int32 intFoundCount = 0;
                        foreach (XmlSchemaParticle xspParticle in xsaAll.Items)
                        {
                            booFound = false;
                            foreach (string strSibling in p_lstSiblings)
                            {
                                lstSibling.Clear();
                                lstSibling.Add(strSibling);
                                if (ContainsSiblings(xspParticle, ref lstChoices, lstSibling))
                                {
                                    intFoundCount++;
                                    booFound = true;
                                    break;
                                }
                            }
                            if (!booFound)
                                lstChoices.AddRange(GetChildrenElements(xspParticle));
                        }
                        if (intFoundCount < xsaAll.Items.Count)
                            p_lstChoices = lstChoices;
                    }
                    return true;
                }
            }
            return false;
        }
 private void CompileParticleElements(XmlSchemaComplexType complexType, XmlSchemaParticle particle)
 {
     if (particle is XmlSchemaElement)
     {
         XmlSchemaElement xe = (XmlSchemaElement) particle;
         this.CompileElement(xe);
         if (complexType.LocalElements[xe.QualifiedName] == null)
         {
             complexType.LocalElements.Add(xe.QualifiedName, xe);
         }
         else
         {
             XmlSchemaElement element2 = (XmlSchemaElement) complexType.LocalElements[xe.QualifiedName];
             if (element2.ElementSchemaType != xe.ElementSchemaType)
             {
                 base.SendValidationEvent("Sch_ElementTypeCollision", particle);
             }
         }
     }
     else if (particle is XmlSchemaGroupBase)
     {
         XmlSchemaObjectCollection items = ((XmlSchemaGroupBase) particle).Items;
         for (int i = 0; i < items.Count; i++)
         {
             this.CompileParticleElements(complexType, (XmlSchemaParticle) items[i]);
         }
     }
 }
Beispiel #57
0
 /// <summary>
 /// Gets the child elements of the given XML particle that are eligible to
 /// be the next element in the XML document.
 /// </summary>
 /// <param name="p_xspParticle">The particle whoe children are to be retrieved.</param>
 /// <returns>A list of the child elements of the given XML particle that are eligible to
 /// be the next element in the XML document.</returns>
 private List<KeyValuePair<string, string>> GetChildrenElements(XmlSchemaParticle p_xspParticle)
 {
     if (p_xspParticle is XmlSchemaElement)
     {
         XmlSchemaElement xseElement = (XmlSchemaElement)p_xspParticle;
         return new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(xseElement.Name, GetDocumentation(xseElement)) };
     }
     else if (p_xspParticle is XmlSchemaSequence)
     {
         XmlSchemaSequence xssSequence = (XmlSchemaSequence)p_xspParticle;
         List<KeyValuePair<string, string>> lstChoices = new List<KeyValuePair<string, string>>();
         foreach (XmlSchemaParticle xspParticle in xssSequence.Items)
         {
             lstChoices.AddRange(GetChildrenElements(xspParticle));
             if (xspParticle.MinOccurs > 0)
                 break;
         }
         return lstChoices;
     }
     else if (p_xspParticle is XmlSchemaChoice)
     {
         XmlSchemaChoice xscChoice = (XmlSchemaChoice)p_xspParticle;
         List<KeyValuePair<string, string>> lstChoices = new List<KeyValuePair<string, string>>();
         foreach (XmlSchemaParticle xspParticle in xscChoice.Items)
             lstChoices.AddRange(GetChildrenElements(xspParticle));
         return lstChoices;
     }
     else if (p_xspParticle is XmlSchemaAll)
     {
         XmlSchemaAll xsaAll = (XmlSchemaAll)p_xspParticle;
         List<KeyValuePair<string, string>> lstChoices = new List<KeyValuePair<string, string>>();
         foreach (XmlSchemaParticle xspParticle in xsaAll.Items)
             lstChoices.AddRange(GetChildrenElements(xspParticle));
         return lstChoices;
     }
     return null;
 }
 private int GetMappingParticle(XmlSchemaParticle particle, XmlSchemaObjectCollection collection)
 {
     for (int i = 0; i < collection.Count; i++)
     {
         if (this.IsValidRestriction(particle, (XmlSchemaParticle) collection[i]))
         {
             return i;
         }
     }
     return -1;
 }
 private void PreprocessParticle(XmlSchemaParticle particle)
 {
     XmlSchemaObjectCollection items;
     if (particle is XmlSchemaAll)
     {
         if ((particle.MinOccurs != 0M) && (particle.MinOccurs != 1M))
         {
             particle.MinOccurs = 1M;
             base.SendValidationEvent("Sch_InvalidAllMin", particle);
         }
         if (particle.MaxOccurs != 1M)
         {
             particle.MaxOccurs = 1M;
             base.SendValidationEvent("Sch_InvalidAllMax", particle);
         }
         items = ((XmlSchemaAll) particle).Items;
         for (int i = 0; i < items.Count; i++)
         {
             XmlSchemaElement source = (XmlSchemaElement) items[i];
             if ((source.MaxOccurs != 0M) && (source.MaxOccurs != 1M))
             {
                 source.MaxOccurs = 1M;
                 base.SendValidationEvent("Sch_InvalidAllElementMax", source);
             }
             this.SetParent(source, particle);
             this.PreprocessLocalElement(source);
         }
     }
     else
     {
         if (particle.MinOccurs > particle.MaxOccurs)
         {
             particle.MinOccurs = particle.MaxOccurs;
             base.SendValidationEvent("Sch_MinGtMax", particle);
         }
         if (particle is XmlSchemaChoice)
         {
             items = ((XmlSchemaChoice) particle).Items;
             for (int j = 0; j < items.Count; j++)
             {
                 this.SetParent(items[j], particle);
                 XmlSchemaElement element = items[j] as XmlSchemaElement;
                 if (element != null)
                 {
                     this.PreprocessLocalElement(element);
                 }
                 else
                 {
                     this.PreprocessParticle((XmlSchemaParticle) items[j]);
                 }
             }
         }
         else if (particle is XmlSchemaSequence)
         {
             items = ((XmlSchemaSequence) particle).Items;
             for (int k = 0; k < items.Count; k++)
             {
                 this.SetParent(items[k], particle);
                 XmlSchemaElement element3 = items[k] as XmlSchemaElement;
                 if (element3 != null)
                 {
                     this.PreprocessLocalElement(element3);
                 }
                 else
                 {
                     this.PreprocessParticle((XmlSchemaParticle) items[k]);
                 }
             }
         }
         else if (particle is XmlSchemaGroupRef)
         {
             XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef) particle;
             if (ref2.RefName.IsEmpty)
             {
                 base.SendValidationEvent("Sch_MissAttribute", "ref", ref2);
             }
             else
             {
                 this.ValidateQNameAttribute(ref2, "ref", ref2.RefName);
             }
         }
         else if (particle is XmlSchemaAny)
         {
             try
             {
                 ((XmlSchemaAny) particle).BuildNamespaceList(this.targetNamespace);
             }
             catch (FormatException exception)
             {
                 base.SendValidationEvent("Sch_InvalidAnyDetailed", new string[] { exception.Message }, exception, particle);
             }
         }
     }
     this.PreprocessAnnotation(particle);
     this.ValidateIdAttribute(particle);
 }
 void ImportGroupMembers(XmlSchemaParticle particle, CodeIdentifiers members, string ns) {
     XmlQualifiedName parentType = XmlSchemas.GetParentName(particle);
     if (particle is XmlSchemaGroupRef) {
         throw new InvalidOperationException(Res.GetString(Res.XmlSoapUnsupportedGroupRef, parentType.Name, parentType.Namespace));
     }
     else if (particle is XmlSchemaGroupBase) {
         XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle;
         if (group.IsMultipleOccurrence)
             throw new InvalidOperationException(Res.GetString(Res.XmlSoapUnsupportedGroupRepeat, parentType.Name, parentType.Namespace));
         for (int i = 0; i < group.Items.Count; i++) {
             object item = group.Items[i];
             if (item is XmlSchemaGroupBase || item is XmlSchemaGroupRef)
                 throw new InvalidOperationException(Res.GetString(Res.XmlSoapUnsupportedGroupNested, parentType.Name, parentType.Namespace));
             else if (item is XmlSchemaElement)
                 ImportElementMember((XmlSchemaElement)item, members, ns);
             else if (item is XmlSchemaAny) 
                 throw new InvalidOperationException(Res.GetString(Res.XmlSoapUnsupportedGroupAny, parentType.Name, parentType.Namespace));
         }
     }
 }