internal NfaContentValidator(BitSet firstpos, BitSet[] followpos, SymbolsDictionary symbols, Positions positions, int endMarkerPos, XmlSchemaContentType contentType, bool isOpen, bool isEmptiable) : base(contentType, isOpen, isEmptiable)
 {
     this.firstpos = firstpos;
     this.followpos = followpos;
     this.symbols = symbols;
     this.positions = positions;
     this.endMarkerPos = endMarkerPos;
 }
 internal void Clear()
 {
     this.isNil = false;
     this.isDefault = false;
     this.schemaType = null;
     this.schemaElement = null;
     this.schemaAttribute = null;
     this.memberType = null;
     this.validity = XmlSchemaValidity.NotKnown;
     this.contentType = XmlSchemaContentType.Empty;
 }
Пример #3
0
		public static void AssertCompiledComplexType (XmlSchemaComplexType cType,
			XmlQualifiedName name,
			int attributesCount, int attributeUsesCount,
			bool existsAny, Type contentModelType,
			bool hasContentTypeParticle,
			XmlSchemaContentType contentType)
		{
			Assert.IsNotNull (cType);
			Assert.AreEqual (name.Name, cType.Name);
			Assert.AreEqual (name, cType.QualifiedName);
			Assert.AreEqual (attributesCount, cType.Attributes.Count);
			Assert.AreEqual (attributeUsesCount, cType.AttributeUses.Count);
			Assert.IsTrue (existsAny == (cType.AttributeWildcard != null));
			if (contentModelType == null)
				Assert.IsNull (cType.ContentModel);
			else
				Assert.AreEqual (contentModelType, cType.ContentModel.GetType ());
			Assert.AreEqual (hasContentTypeParticle, cType.ContentTypeParticle != null);
			Assert.AreEqual (contentType, cType.ContentType);
		}
Пример #4
0
		private void CollectContentTypeFromComplexRestriction ()
		{
			XmlSchemaComplexContentRestriction ccr = (XmlSchemaComplexContentRestriction) ContentModel.Content;
			// 3.4.2 complex content schema component {content type}
			// - 1.1.1
			bool isEmptyParticle = false;
			if (ccr.Particle == null) 
				isEmptyParticle = true;
			else {
				XmlSchemaGroupBase gb = ccr.Particle as XmlSchemaGroupBase;
				if (gb != null) {
					// - 1.1.2
					if (!(gb is XmlSchemaChoice) && gb.Items.Count == 0)
						isEmptyParticle = true;
					// - 1.1.3
					else if (gb is XmlSchemaChoice && gb.Items.Count == 0 && gb.ValidatedMinOccurs == 0)
						isEmptyParticle = true;
				}
			}
			if (isEmptyParticle) {
				resolvedContentType = XmlSchemaContentType.Empty;
				validatableParticle = XmlSchemaParticle.Empty;
			} else {
				// - 1.2.1
				resolvedContentType = GetComplexContentType (contentModel);
				// - 1.2.2
				validatableParticle = ccr.Particle;
			}
		}
 protected ContentValidator(XmlSchemaContentType contentType, bool isOpen, bool isEmptiable)
 {
     this.contentType = contentType;
     this.isOpen      = isOpen;
     this.isEmptiable = isEmptiable;
 }
Пример #6
0
		private void CollectContentTypeFromComplexExtension (ValidationEventHandler h, XmlSchema schema)
		{
			XmlSchemaComplexContentExtension cce = (XmlSchemaComplexContentExtension) ContentModel.Content;
			XmlSchemaComplexType baseComplexType = this.BaseXmlSchemaType as XmlSchemaComplexType;
			if (baseComplexType != null)
				baseComplexType.CollectSchemaComponent (h ,schema);

			// It must exist, but consider validation error case.
			if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)
				baseComplexType = XmlSchemaComplexType.AnyType;

			// On error case, it simple reject any contents
			if (baseComplexType == null) {
				validatableParticle = XmlSchemaParticle.Empty;
				resolvedContentType = XmlSchemaContentType.Empty;
				return;
			}

			// 3.4.2 complex content {content type}
			if (cce.Particle == null || cce.Particle == XmlSchemaParticle.Empty) {
				// - 2.1
				if (baseComplexType == null) {
					// Basically it is an error. Considering ValidationEventHandler.
					validatableParticle = XmlSchemaParticle.Empty;
					resolvedContentType = XmlSchemaContentType.Empty;
				} else {
					validatableParticle = baseComplexType.ValidatableParticle;
					resolvedContentType = baseComplexType.resolvedContentType;
					// Bug #501814
					if (resolvedContentType == XmlSchemaContentType.Empty)
						resolvedContentType = GetComplexContentType (contentModel);
				}
			} else if (baseComplexType.validatableParticle == XmlSchemaParticle.Empty
				|| baseComplexType == XmlSchemaComplexType.AnyType) {
				// - 2.2
				validatableParticle = cce.Particle;
				resolvedContentType = GetComplexContentType (contentModel);
			} else {
				// - 2.3 : create a new sequences that merges both contents.
				XmlSchemaSequence seq = new XmlSchemaSequence ();
				this.CopyInfo (seq);
				seq.Items.Add (baseComplexType.validatableParticle);
				seq.Items.Add (cce.Particle);
				seq.Compile (h, schema);
				seq.Validate (h, schema);
				validatableParticle = seq;
				resolvedContentType = GetComplexContentType (contentModel);
			}
			if (validatableParticle == null)
				validatableParticle = XmlSchemaParticle.Empty;
		}
 public ParticleContentValidator(XmlSchemaContentType contentType, bool enableUpaCheck) : base(contentType) {
     this.enableUpaCheck = enableUpaCheck;
 }
Пример #8
0
        public void CallValidateElementAndCHeckXmlSchemaInfoFOr_Simple_Complex_Empty_Mixed_Element_First_Second_Overload(String elemType, XmlSchemaContentType schemaContentType, String overload)
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            string name = elemType;

            schemas.Add("", Path.Combine(TestData, XSDFILE_VALIDATE_TEXT));
            schemas.Compile();
            val = CreateValidator(schemas);

            val.Initialize();
            if (overload == "first")
                val.ValidateElement(name, "", info);
            else
                val.ValidateElement(name, "", info, null, null, null, null);

            Assert.Equal(info.ContentType, schemaContentType);
            Assert.Equal(info.Validity, XmlSchemaValidity.NotKnown);
            Assert.Equal(info.SchemaElement, schemas.GlobalElements[new XmlQualifiedName(name)]);
            Assert.Equal(info.IsNil, false);
            Assert.Equal(info.IsDefault, false);
            if (name == "SimpleElement")
                Assert.True(info.SchemaType is XmlSchemaSimpleType);
            else
                Assert.True(info.SchemaType is XmlSchemaComplexType);

            return;
        }
 internal void Clear() {
     isNil = false;
     isDefault = false;
     schemaType = null;
     schemaElement = null;
     schemaAttribute = null;
     memberType = null;
     validity = XmlSchemaValidity.NotKnown;
     contentType = XmlSchemaContentType.Empty;
 }
Пример #10
0
 internal NfaContentValidator(BitSet firstpos, BitSet[] followpos, SymbolsDictionary symbols, Positions positions, int endMarkerPos, XmlSchemaContentType contentType, bool isOpen, bool isEmptiable) : base(contentType, isOpen, isEmptiable)
 {
     this.firstpos     = firstpos;
     this.followpos    = followpos;
     this.symbols      = symbols;
     this.positions    = positions;
     this.endMarkerPos = endMarkerPos;
 }
Пример #11
0
 protected ContentValidator(XmlSchemaContentType contentType, bool anyElement) {
   this.contentType = contentType;
   this.anyElement = anyElement;
 }
 /// <summary>
 /// Algorithm 3.5 Construction of a DFA from a regular expression
 /// </summary>
 internal DfaContentValidator(
     int[][] transitionTable, SymbolsDictionary symbols,
     XmlSchemaContentType contentType, bool isOpen, bool isEmptiable)  : base(contentType, isOpen, isEmptiable) {
     this.transitionTable = transitionTable;
     this.symbols = symbols;
 }
Пример #13
0
        public void CallValidateElementAndCHeckXmlSchemaInfoFOr_Simple_Complex_Empty_Mixed_Element_First_Second_Overload(String elemType, XmlSchemaContentType schemaContentType, String overload)
        {
            XmlSchemaValidator val;
            XmlSchemaSet       schemas = new XmlSchemaSet();
            XmlSchemaInfo      info    = new XmlSchemaInfo();
            string             name    = elemType;

            schemas.Add("", Path.Combine(TestData, XSDFILE_VALIDATE_TEXT));
            schemas.Compile();
            val = CreateValidator(schemas);

            val.Initialize();
            if (overload == "first")
            {
                val.ValidateElement(name, "", info);
            }
            else
            {
                val.ValidateElement(name, "", info, null, null, null, null);
            }

            Assert.Equal(info.ContentType, schemaContentType);
            Assert.Equal(info.Validity, XmlSchemaValidity.NotKnown);
            Assert.Equal(info.SchemaElement, schemas.GlobalElements[new XmlQualifiedName(name)]);
            Assert.Equal(info.IsNil, false);
            Assert.Equal(info.IsDefault, false);
            if (name == "SimpleElement")
            {
                Assert.True(info.SchemaType is XmlSchemaSimpleType);
            }
            else
            {
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }

            return;
        }
Пример #14
0
 public ContentValidator(XmlSchemaContentType contentType, Member mixed) {
   this.contentType = contentType;
   this.mixed = mixed;
 }
Пример #15
0
 internal void SetContentType(XmlSchemaContentType value)
 {
     _contentType = value;
 }
Пример #16
0
 public ParticleContentValidator(XmlSchemaContentType contentType, bool enableUpaCheck) : base(contentType)
 {
     this.enableUpaCheck = enableUpaCheck;
 }
Пример #17
0
 public ParticleContentValidator(XmlSchemaContentType contentType) : this(contentType, true)
 {
 }
Пример #18
0
		private void ValidateContentModel (ValidationEventHandler h, XmlSchema schema)
		{
			XmlSchemaType baseType = BaseXmlSchemaTypeInternal;

			// Here we check 3.4.6 Properties Correct :: 2. and 3.
			XmlSchemaComplexContentExtension cce = contentModel.Content as XmlSchemaComplexContentExtension;
			XmlSchemaComplexContentRestriction ccr = contentModel.Content as XmlSchemaComplexContentRestriction;
			XmlSchemaSimpleContentExtension sce = contentModel.Content as XmlSchemaSimpleContentExtension;
			XmlSchemaSimpleContentRestriction scr = contentModel.Content as XmlSchemaSimpleContentRestriction;

			XmlSchemaAnyAttribute localAnyAttribute = null;
			XmlSchemaAnyAttribute baseAnyAttribute = null;

			// 3.4.6 Properties Correct :: 3. Circular definition prohibited.
			if (ValidateRecursionCheck ())
				error (h, "Circular definition of schema types was found.");
			if (baseType != null) {
				// Fill "Datatype" property.
				this.DatatypeInternal = baseType.Datatype;
			} else if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)
				DatatypeInternal = XmlSchemaSimpleType.AnySimpleType;
			else if (XmlSchemaUtil.IsBuiltInDatatypeName (BaseSchemaTypeName)) {
				DatatypeInternal = XmlSchemaDatatype.FromName (BaseSchemaTypeName);
			}

			XmlSchemaComplexType baseComplexType = baseType as XmlSchemaComplexType;
			XmlSchemaSimpleType baseSimpleType = baseType as XmlSchemaSimpleType;

			// 3.4.6 Derivation Valid (common to Extension and Restriction, Complex) :: 1.
			if (baseType != null && (baseType.FinalResolved & resolvedDerivedBy) != 0)
					error (h, "Specified derivation is specified as final by derived schema type.");

			// 3.4.6 Properties Correct :: 2.
			// Simple {base type definition} and restriction {derivation method} not allowed.
			if (baseSimpleType != null && resolvedDerivedBy == XmlSchemaDerivationMethod.Restriction)
				error (h, "If the base schema type is a simple type, then this type must be extension.");

			// Common to complexContent
			if (cce != null || ccr != null) {
				// 3.4.3 Complex Type Definition Representation OK :: 1.
				// base
				if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)
					baseComplexType = XmlSchemaComplexType.AnyType;
				else if (XmlSchemaUtil.IsBuiltInDatatypeName (BaseSchemaTypeName))
					error (h, "Referenced base schema type is XML Schema datatype.");
				else if (baseComplexType == null && !schema.IsNamespaceAbsent (BaseSchemaTypeName.Namespace))
					error (h, "Referenced base schema type " + BaseSchemaTypeName + " was not complex type or not found in the corresponding schema.");
			}
			// Common to simpleContent 
			else {
				// ContentType of {content type}
				resolvedContentType = XmlSchemaContentType.TextOnly;

				// 3.4.3 Complex Type Definition Representation OK :: 1.
				// base
				if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)
					baseComplexType = XmlSchemaComplexType.AnyType;

				if (baseComplexType != null && baseComplexType.ContentType != XmlSchemaContentType.TextOnly) {
					error (h, "Base schema complex type of a simple content must be simple content type. Base type is " + BaseSchemaTypeName);
				} else if (sce == null && (baseSimpleType != null && BaseSchemaTypeName.Namespace != XmlSchema.Namespace)) {
					error (h, "If a simple content is not an extension, base schema type must be complex type. Base type is " + BaseSchemaTypeName);
				} else if (XmlSchemaUtil.IsBuiltInDatatypeName (BaseSchemaTypeName)) {
					// do nothing for particle.
				}
				// otherwise, it might be missing sub components.
				else if (baseType == null && !schema.IsNamespaceAbsent (BaseSchemaTypeName.Namespace))
					error (h, "Referenced base schema type " + BaseSchemaTypeName + " was not found in the corresponding schema.");

				// 3.4.3 Complex Type Definition Representation OK :: 2.
				// Note that baseSimpleType is also allowed as to Errata E1-27 (http://www.w3.org/2001/05/xmlschema-errata)
				if (baseComplexType != null) {
					if (baseComplexType.ContentType == XmlSchemaContentType.TextOnly) {
						// 2.1.1
					// Here "baseComplexType.Particle != null" is required for error-ignorant case
					} else if (scr != null && baseComplexType.ContentType == XmlSchemaContentType.Mixed && baseComplexType.Particle != null && baseComplexType.Particle.ValidateIsEmptiable () && scr.BaseType != null) {
						// 2.1.2 && 2.2: OK
					}
					else
						error (h, "Base complex type of a simple content restriction must be text only.");
				} else {
					if (sce != null && baseComplexType == null) {
						// 2.1.3 : OK
					}
					else
						error (h, "Not allowed base type of a simple content restriction.");
				}
			}

			// complexType/complexContent/extension
			if (cce != null) {
				// I don't think 3.4.6 Derivation Valid (Extension) :: 1.2
				// is constraining anything here, since 3.4.2 {attribute uses}
				// defines as to include base type's attribute uses.
				localAnyAttribute = cce.AnyAttribute;
				if (baseComplexType != null) {
					foreach (DictionaryEntry entry in baseComplexType.AttributeUses) {
						XmlSchemaAttribute attr = (XmlSchemaAttribute) entry.Value;
						XmlSchemaUtil.AddToTable (attributeUses, attr, attr.QualifiedName, h);
					}
					baseAnyAttribute = baseComplexType.AttributeWildcard;
				}
				// attributes
				errorCount += XmlSchemaUtil.ValidateAttributesResolved (
					this.attributeUses, h, schema, cce.Attributes, 
					cce.AnyAttribute , ref attributeWildcard, null, true);

				// After adding them, test extension validity.
				if (baseComplexType != null)
					this.ValidateComplexBaseDerivationValidExtension (baseComplexType, h, schema);
				else if (baseSimpleType != null)
					this.ValidateSimpleBaseDerivationValidExtension (baseSimpleType, h, schema);
			}
			// complexType/complexContent/restriction
			if (ccr != null) {
				// For ValidationEventHandler.
				if (baseComplexType == null)
					baseComplexType = XmlSchemaComplexType.AnyType;

				// attributes
				localAnyAttribute = ccr.AnyAttribute;
				this.attributeWildcard = localAnyAttribute;
				if (baseComplexType != null)
					baseAnyAttribute = baseComplexType.AttributeWildcard;
				if (baseAnyAttribute != null && localAnyAttribute != null)
					// 1.3 attribute wildcard subset. (=> 3.10.6)
					localAnyAttribute.ValidateWildcardSubset (baseAnyAttribute, h, schema);

				// 3.4.2 Complex Type Definition with complex content Schema Component
				// and its {attribute uses} and {attribute wildcard} are done here (descendantly)
				errorCount += XmlSchemaUtil.ValidateAttributesResolved (
					this.attributeUses, h, schema, ccr.Attributes, 
					ccr.AnyAttribute, ref attributeWildcard, null, false);
				foreach (DictionaryEntry entry in baseComplexType.AttributeUses) {
					XmlSchemaAttribute attr = (XmlSchemaAttribute) entry.Value;
					if (attributeUses [attr.QualifiedName] == null)
						XmlSchemaUtil.AddToTable (attributeUses, attr, attr.QualifiedName, h);
				}

				// Derivation Valid (Restriction, Complex) :: 5.
				// Also see E1-15 of http://www.w3.org/2001/05/xmlschema-errata#Errata1
				// 5.1 shouled be in scr (XmlSchemaSimpleContentRestriction)
				this.ValidateDerivationValidRestriction (baseComplexType, h, schema);
			}
			// complexType/simpleContent/extension
			if (sce != null) {
				errorCount += XmlSchemaUtil.ValidateAttributesResolved (
					this.attributeUses, h, schema, sce.Attributes, 
					sce.AnyAttribute, ref attributeWildcard, null, true);

				// Attributes
				// I don't think 3.4.6 Derivation Valid (Extension) :: 1.2
				// is constraining anything here, since 3.4.2 {attribute uses}
				// defines as to include base type's attribute uses.
				localAnyAttribute = sce.AnyAttribute;

				if (baseComplexType != null) {
					baseAnyAttribute = baseComplexType.AttributeWildcard;

					foreach (DictionaryEntry entry in baseComplexType.AttributeUses) {
						XmlSchemaAttribute attr = (XmlSchemaAttribute) entry.Value;
#if BUGGY_MS_COMPLIANT
						if (attr.Use != XmlSchemaUse.Prohibited)
							XmlSchemaUtil.AddToTable (attributeUses, attr, attr.QualifiedName, h);
#endif
						XmlSchemaUtil.AddToTable (attributeUses, attr, attr.QualifiedName, h);
					}
				}
				if (baseAnyAttribute != null && localAnyAttribute != null)
					// 1.3 attribute wildcard subset. (=> 3.10.6)
					localAnyAttribute.ValidateWildcardSubset (baseAnyAttribute, h, schema);
			}
			// complexType/simpleContent/restriction
			if (scr != null) {
				// Attributes
				baseAnyAttribute = baseComplexType != null ? baseComplexType.AttributeWildcard : null;

				localAnyAttribute = scr.AnyAttribute;
				if (localAnyAttribute != null && baseAnyAttribute != null)
					// 1.3 attribute wildcard subset. (=> 3.10.6)
					localAnyAttribute.ValidateWildcardSubset (baseAnyAttribute, h, schema);
				// 3.4.6 :: 5.1. Beware that There is an errata for 5.1!!
				// http://www.w3.org/2001/05/xmlschema-errata#Errata1

				// 3.4.2 Complex Type Definition with simple content Schema Component
				// and its {attribute uses} and {attribute wildcard} are done here (descendantly)
				errorCount += XmlSchemaUtil.ValidateAttributesResolved (
					this.attributeUses, h, schema, scr.Attributes, 
					scr.AnyAttribute, ref attributeWildcard, null, false);
			}

			// Common process of AttributeWildcard.
			if (localAnyAttribute != null) {
				this.attributeWildcard = localAnyAttribute;
			}
			else
				this.attributeWildcard = baseAnyAttribute;
		}
 public AllElementsContentValidator(XmlSchemaContentType contentType, int size, bool isEmptiable) : base(contentType, false, isEmptiable) {
     elements = new Hashtable(size);
     particles = new object[size];
     isRequired = new BitSet(size);
 }
        public Shape GenerateFromSchema(XmlSchemaElement xse)
        {
            XmlQualifiedName     xseName     = xse.QualifiedName;
            XmlSchemaType        schemaType  = xse.ElementSchemaType;
            XmlSchemaComplexType complexType = schemaType as XmlSchemaComplexType;

            if (null != complexType)
            {
                XmlSchemaParticle particle  = null;
                Shape             rootShape = null;

                XmlSchemaContentType contentType = complexType.ElementDecl.ContentValidator.ContentType;
                switch (contentType)
                {
                case XmlSchemaContentType.Mixed:
                case XmlSchemaContentType.TextOnly:
                    rootShape = new Shape(GenName(xseName) + "_Text", BindingType.Text);
                    rootShape.AddParticle(xse);
                    break;

                case XmlSchemaContentType.Empty:
                    rootShape = new Shape(null, BindingType.Sequence);
                    break;

                case XmlSchemaContentType.ElementOnly:
                    particle  = complexType.ContentTypeParticle;
                    rootShape = ProcessParticle(particle, null);
                    break;
                }

                Debug.Assert(rootShape != null);
                if (complexType.AttributeUses.Values.Count > 0)
                {
                    if (rootShape.BindingType != BindingType.Sequence)
                    {
                        Shape s = new Shape(null, BindingType.Sequence);
                        s.AddSubShape(rootShape);
                        rootShape = s;
                    }
                    int      pos   = 0;
                    string[] names = rootShape.SubShapeNames();

                    ICollection          attributes = complexType.AttributeUses.Values;
                    XmlSchemaAttribute[] xsaArray   = new XmlSchemaAttribute[attributes.Count];
                    attributes.CopyTo(xsaArray, 0);
                    Array.Sort(xsaArray, new XmlSchemaAttributeComparer());
                    foreach (XmlSchemaAttribute xsa in xsaArray)
                    {
                        string name      = GenAttrName(xsa.QualifiedName, names);
                        Shape  attrShape = new Shape(name, BindingType.Attribute);
                        attrShape.AddParticle(xsa);
                        rootShape.AddAttrShapeAt(attrShape, pos++);
                    }
                }

                if (rootShape.BindingType != BindingType.Text)
                {
                    rootShape.Name          = GenName(xseName);
                    rootShape.ContainerDecl = xse;
                }
                return(rootShape);
            }
            else   // simple type
            {
                Shape s = new Shape(GenName(xseName), BindingType.Text);
                s.AddParticle(xse);
                return(s);
            }
        }
 protected ContentValidator(XmlSchemaContentType contentType, bool isOpen, bool isEmptiable) {
     this.contentType = contentType;
     this.isOpen = isOpen;
     this.isEmptiable = isEmptiable;
 }
Пример #22
0
 public ParticleContentValidator(XmlSchemaContentType contentType, NamedNode[] namedTerminals, Hashtable symbols, InternalNode contentRoot, NamedNode endMarker, int symbolCount, Member mixed) : base(contentType, mixed) {
   this.namedTerminals = namedTerminals;
   this.symbols = symbols;
   this.contentRoot = contentRoot;
   this.endMarker = endMarker;
   this.symbolCount = symbolCount;
 }
 internal DfaContentValidator(int[][] transitionTable, SymbolsDictionary symbols, XmlSchemaContentType contentType, bool isOpen, bool isEmptiable) : base(contentType, isOpen, isEmptiable)
 {
     this.transitionTable = transitionTable;
     this.symbols         = symbols;
 }
 internal RangeContentValidator(
     BitSet firstpos, BitSet[] followpos, SymbolsDictionary symbols, Positions positions, int endMarkerPos, XmlSchemaContentType contentType, bool isEmptiable, BitSet positionsWithRangeTerminals, int minmaxNodesCount)  : base(contentType, false, isEmptiable) {
     this.firstpos = firstpos;
     this.followpos = followpos;
     this.symbols = symbols;
     this.positions = positions;
     this.positionsWithRangeTerminals = positionsWithRangeTerminals;
     this.minMaxNodesCount = minmaxNodesCount;
     this.endMarkerPos = endMarkerPos;
 }
Пример #25
0
    internal CompiledParticleContentValidator(ValidationState context, InternalNode contentRoot, NamedNode[] namedTerminals, Hashtable symbols, int symCount, bool isOpen, XmlSchemaContentType contentType, Member mixed, NamedNode endMarker)  
      : base(contentType, namedTerminals, symbols, contentRoot, endMarker, symCount, mixed) {
      // keep these
      this.isOpen = isOpen;
      this.isEmptiable = contentRoot.LeftChild.IsNullable;

      int terminalsCount = namedTerminals.Length;
      int endMarkerPos = terminalsCount - 1; 

      // calculate followpos
      BitSet[] followpos = new BitSet[terminalsCount];
      for (int i = 0; i < terminalsCount; i++) {
        followpos[i] = new BitSet(terminalsCount);
      }
      contentRoot.CalcFollowpos(followpos);

      // transition table
      ArrayList transitionTable = new ArrayList();
            
      // state lookup table
      Hashtable stateTable = new Hashtable();

      // lists unmarked states
      ArrayList unmarked = new ArrayList();

      stateTable.Add(new BitSet(terminalsCount), -1); // add empty

      // start with firstpos at the root
      BitSet firstpos = contentRoot.Firstpos;
      stateTable.Add(firstpos, 0);
      unmarked.Add(firstpos);

      int[] a = new int[symbolCount + 1];
      transitionTable.Add(a);
      if (firstpos[endMarkerPos]) {
        a[symbolCount] = 1;   // accepting
      }

      // current state processed
      int state = 0;

      // check all unmarked states
      while (unmarked.Count > 0) {
        int[] t = (int[])transitionTable[state];

        firstpos = (BitSet)unmarked[0];
        if (!isNonDeterministic && !CheckDeterministic(firstpos, namedTerminals, context)) {
          isNonDeterministic = true;
        }
        unmarked.RemoveAt(0);

        // check all input symbols
        foreach (NamedNodeList list in symbols.Values){
          foreach (NamedNode node in list) {
            BitSet newset = new BitSet(terminalsCount);

            // if symbol is in the set add followpos to new set
            for (int i = 0; i < terminalsCount; i++) {
              if (firstpos[i] && node == namedTerminals[i]) {
                newset.Or(followpos[i]);
              }
            }

            object lookup = stateTable[newset];
            // this state will transition to
            int transitionTo;
            // if new set is not in states add it
            if (lookup == null) {
              transitionTo = stateTable.Count - 1;
              stateTable.Add(newset, transitionTo);
              unmarked.Add(newset);
              a = new int[symbolCount + 1];
              transitionTable.Add(a);
              if (newset[endMarkerPos]) {
                a[symbolCount] = 1;   // accepting
              }
            }
            else {
              transitionTo = (int)lookup;
            }
            // set the transition for the symbol
            t[node.Symbol] = transitionTo;
          }
        }
        state++;
      }
      // now convert transition table to array
      this.transitionTable = (int[][])transitionTable.ToArray(typeof(int[]));
    }
 public ContentValidator(XmlSchemaContentType contentType) {
     this.contentType = contentType;
     this.isEmptiable = true;
 }
Пример #27
0
 public ContentModelBuilder(XmlSchemaContentType contentType) {
   this.contentType = contentType;
 }
 public ParticleContentValidator(XmlSchemaContentType contentType) : this(contentType, true) {
 }
Пример #29
0
		void FillContentTypeParticle (ValidationEventHandler h, XmlSchema schema)
		{
			// {content type} => ContentType and ContentTypeParticle (later)
			if (ContentModel != null) {
				CollectContentTypeFromContentModel (h, schema);
			} else
				CollectContentTypeFromImmediateContent ();

			contentTypeParticle = validatableParticle.GetOptimizedParticle (true);
			if (contentTypeParticle == XmlSchemaParticle.Empty && resolvedContentType == XmlSchemaContentType.ElementOnly)
				resolvedContentType = XmlSchemaContentType.Empty;

			CollectProcessId = schema.CompilationId;
		}
Пример #30
0
		private void CollectContentTypeFromImmediateContent ()
		{
			// leave resolvedDerivedBy as Empty
			if (Particle != null)
				validatableParticle = Particle;
			if (this == AnyType) {
				resolvedContentType = XmlSchemaContentType.Mixed;
				return;
			}

			if (validatableParticle == XmlSchemaParticle.Empty) {
				// note that this covers "Particle == null" case
				if (this.IsMixed)
					resolvedContentType = XmlSchemaContentType.TextOnly;
				else
					resolvedContentType = XmlSchemaContentType.Empty;
			} else {
				if (this.IsMixed)
					resolvedContentType = XmlSchemaContentType.Mixed;
				else
					resolvedContentType = XmlSchemaContentType.ElementOnly;
			}
			if (this != AnyType)
				BaseXmlSchemaTypeInternal = XmlSchemaComplexType.AnyType;
		}
Пример #31
0
		private void CollectContentTypeFromContentModel (ValidationEventHandler h, XmlSchema schema)
		{
			if (ContentModel.Content == null) {
				// basically it is error. Recover by specifying empty content.
				validatableParticle = XmlSchemaParticle.Empty;
				resolvedContentType = XmlSchemaContentType.Empty;
				return;
			}

			if (ContentModel.Content is XmlSchemaComplexContentExtension)
				CollectContentTypeFromComplexExtension (h, schema);
			if (ContentModel.Content is XmlSchemaComplexContentRestriction)
				CollectContentTypeFromComplexRestriction ();
		}
Пример #32
0
 internal void SetContentType(XmlSchemaContentType value) { 
     contentType = value; 
 }
 public ContentValidator(XmlSchemaContentType contentType)
 {
     this.contentType = contentType;
     this.isEmptiable = true;
 }