| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- //
- // System.Xml.Schema.XmlSchemaSequence.cs
- //
- // Author:
- // Dwivedi, Ajay kumar [email protected]
- // Atsushi Enomoto [email protected]
- //
- using System;
- using System.Collections;
- using System.Xml.Serialization;
- using System.Xml;
- namespace System.Xml.Schema
- {
- /// <summary>
- /// Summary description for XmlSchemaSequence.
- /// </summary>
- public class XmlSchemaSequence : XmlSchemaGroupBase
- {
- private XmlSchemaObjectCollection items;
- private XmlSchemaObjectCollection compiledItems;
- private static string xmlname = "sequence";
- public XmlSchemaSequence()
- {
- items = new XmlSchemaObjectCollection();
- }
- [XmlElement("element",typeof(XmlSchemaElement),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("any",typeof(XmlSchemaAny),Namespace="http://www.w3.org/2001/XMLSchema")]
- public override XmlSchemaObjectCollection Items
- {
- get{ return items; }
- }
- internal XmlSchemaObjectCollection CompiledItems
- {
- get{ return compiledItems; }
- }
- [MonoTODO]
- internal override int Compile(ValidationEventHandler h, XmlSchema schema)
- {
- // If this is already compiled this time, simply skip.
- if (this.IsComplied (schema.CompilationId))
- return 0;
- XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
- CompileOccurence (h, schema);
- foreach(XmlSchemaObject obj in Items)
- {
- if(obj is XmlSchemaElement ||
- obj is XmlSchemaGroupRef ||
- obj is XmlSchemaChoice ||
- obj is XmlSchemaSequence ||
- obj is XmlSchemaAny)
- {
- errorCount += obj.Compile(h,schema);
- }
- else
- error(h, "Invalid schema object was specified in the particles of the sequence model group.");
- }
- this.CompilationId = schema.CompilationId;
- return errorCount;
- }
-
- [MonoTODO]
- internal override int Validate(ValidationEventHandler h, XmlSchema schema)
- {
- if (IsValidated (schema.CompilationId))
- return errorCount;
- compiledItems = new XmlSchemaObjectCollection ();
- foreach (XmlSchemaObject obj in Items) {
- errorCount += obj.Validate (h, schema);
- compiledItems.Add (obj);
- }
- ValidationId = schema.ValidationId;
- return errorCount;
- }
- internal override void ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
- ValidationEventHandler h, XmlSchema schema)
- {
- XmlSchemaElement el = baseParticle as XmlSchemaElement;
- if (el != null) {
- // Forbidden
- error (h, "Invalid sequence paricle derivation.");
- return;
- }
- XmlSchemaSequence seq = baseParticle as XmlSchemaSequence;
- if (seq != null) {
- // Recurse
- ValidateOccurenceRangeOK (seq, h, schema);
- // FIXME: What is the correct "order preserving" mapping?
- int baseIndex = 0;
- for (int i = 0; i < this.Items.Count; i++) {
- XmlSchemaParticle pd = Items [i] as XmlSchemaParticle;
- if (seq.Items.Count > baseIndex) {
- XmlSchemaParticle pb = seq.Items [baseIndex] as XmlSchemaParticle;
- pd.ActualParticle.ValidateDerivationByRestriction (pb.ActualParticle, h, schema);
- baseIndex++;
- }
- else
- error (h, "Invalid choice derivation by extension was found.");
- }
- return;
- }
- XmlSchemaAll all = baseParticle as XmlSchemaAll;
- XmlSchemaAny any = baseParticle as XmlSchemaAny;
- XmlSchemaChoice choice = baseParticle as XmlSchemaChoice;
- if (all != null) {
- // RecurseUnordered
- XmlSchemaObjectCollection already = new XmlSchemaObjectCollection ();
- for (int i = 0; i < this.Items.Count; i++) {
- XmlSchemaElement de = this.Items [i] as XmlSchemaElement;
- if (de == null) {
- error (h, "Invalid sequence particle derivation by restriction from all.");
- continue;
- }
- foreach (XmlSchemaElement e in all.Items) {
- if (e.QualifiedName == de.QualifiedName) {
- if (already.Contains (e))
- error (h, "Base element particle is mapped to the derived element particle in a sequence two or more times.");
- else {
- already.Add (e);
- de.ValidateDerivationByRestriction (e, h, schema);
- }
- }
- }
- }
- foreach (XmlSchemaElement e in all.Items)
- if (!already.Contains (e))
- if (!e.ValidateIsEmptiable ())
- error (h, "In base -all- particle, mapping-skipped base element which is not emptiable was found.");
- } else if (any != null) {
- // NSRecurseCheckCardinality
- ValidateNSRecurseCheckCardinality (any, h, schema);
- return;
- } else if (choice != null) {
- // TODO: MapAndSum
- }
- }
- internal override decimal GetMinEffectiveTotalRange ()
- {
- return GetMinEffectiveTotalRangeAllAndSequence ();
- }
- internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)
- {
- foreach (XmlSchemaParticle p in this.Items)
- p.CheckRecursion (depth, h, schema);
- }
- internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames, ArrayList nsNames,
- ValidationEventHandler h, XmlSchema schema)
- {
- foreach (XmlSchemaParticle p in this.Items) {
- p.ValidateUniqueParticleAttribution (qnames, nsNames, h, schema);
- if (p.ValidatedMinOccurs == p.ValidatedMaxOccurs)
- break;
- }
- XmlSchemaObjectTable tmpTable = new XmlSchemaObjectTable ();
- ArrayList al = new ArrayList ();
- for (int i=0; i<Items.Count; i++) {
- XmlSchemaParticle p1 = Items [i] as XmlSchemaParticle;
- p1.ValidateUniqueParticleAttribution (tmpTable, al, h, schema);
- if (p1.ValidatedMinOccurs == p1.ValidatedMaxOccurs) {
- tmpTable.Clear ();
- al.Clear ();
- }
- }
- }
- internal override void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
- ValidationEventHandler h, XmlSchema schema)
- {
- foreach (XmlSchemaParticle p in this.Items)
- p.ValidateUniqueTypeAttribution (labels, h, schema);
- }
- //<sequence
- // id = ID
- // maxOccurs = (nonNegativeInteger | unbounded) : 1
- // minOccurs = nonNegativeInteger : 1
- // {any attributes with non-schema namespace . . .}>
- // Content: (annotation?, (element | group | choice | sequence | any)*)
- //</sequence>
- internal static XmlSchemaSequence Read(XmlSchemaReader reader, ValidationEventHandler h)
- {
- XmlSchemaSequence sequence = new XmlSchemaSequence();
- reader.MoveToElement();
- if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
- {
- error(h,"Should not happen :1: XmlSchemaSequence.Read, name="+reader.Name,null);
- reader.Skip();
- return null;
- }
- sequence.LineNumber = reader.LineNumber;
- sequence.LinePosition = reader.LinePosition;
- sequence.SourceUri = reader.BaseURI;
- while(reader.MoveToNextAttribute())
- {
- if(reader.Name == "id")
- {
- sequence.Id = reader.Value;
- }
- else if(reader.Name == "maxOccurs")
- {
- try
- {
- sequence.MaxOccursString = reader.Value;
- }
- catch(Exception e)
- {
- error(h,reader.Value + " is an invalid value for maxOccurs",e);
- }
- }
- else if(reader.Name == "minOccurs")
- {
- try
- {
- sequence.MinOccursString = reader.Value;
- }
- catch(Exception e)
- {
- error(h,reader.Value + " is an invalid value for minOccurs",e);
- }
- }
- else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
- {
- error(h,reader.Name + " is not a valid attribute for sequence",null);
- }
- else
- {
- XmlSchemaUtil.ReadUnhandledAttribute(reader,sequence);
- }
- }
-
- reader.MoveToElement();
- if(reader.IsEmptyElement)
- return sequence;
- // Content: (annotation?, (element | group | choice | sequence | any)*)
- int level = 1;
- while(reader.ReadNextElement())
- {
- if(reader.NodeType == XmlNodeType.EndElement)
- {
- if(reader.LocalName != xmlname)
- error(h,"Should not happen :2: XmlSchemaSequence.Read, name="+reader.Name,null);
- break;
- }
- if(level <= 1 && reader.LocalName == "annotation")
- {
- level = 2; //Only one annotation
- XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
- if(annotation != null)
- sequence.Annotation = annotation;
- continue;
- }
- if(level <=2)
- {
- if(reader.LocalName == "element")
- {
- level = 2;
- XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
- if(element != null)
- sequence.items.Add(element);
- continue;
- }
- if(reader.LocalName == "group")
- {
- level = 2;
- XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
- if(group != null)
- sequence.items.Add(group);
- continue;
- }
- if(reader.LocalName == "choice")
- {
- level = 2;
- XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
- if(choice != null)
- sequence.items.Add(choice);
- continue;
- }
- if(reader.LocalName == "sequence")
- {
- level = 2;
- XmlSchemaSequence seq = XmlSchemaSequence.Read(reader,h);
- if(seq != null)
- sequence.items.Add(seq);
- continue;
- }
- if(reader.LocalName == "any")
- {
- level = 2;
- XmlSchemaAny any = XmlSchemaAny.Read(reader,h);
- if(any != null)
- sequence.items.Add(any);
- continue;
- }
- }
- reader.RaiseInvalidElementError();
- }
- return sequence;
- }
- }
- }
|