Summary description for XmlSchemaFacet.
Inheritance: XmlSchemaAnnotated
コード例 #1
0
 private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode)
 {
     if ((this.derivedRestriction.Flags & flag) != 0)
     {
         throw new XmlSchemaException(errorCode, facet);
     }
 }
コード例 #2
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 internal void CompileLengthFacet(XmlSchemaFacet facet) {
     CheckProhibitedFlag(facet, RestrictionFlags.Length, Res.Sch_LengthFacetProhibited);
     CheckDupFlag(facet, RestrictionFlags.Length, Res.Sch_DupLengthFacet);
     derivedRestriction.Length = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(nonNegativeInt, facet, Res.Sch_LengthFacetInvalid, null, null));
     
     if ((baseFixedFlags & RestrictionFlags.Length) != 0) {
         if (!datatype.IsEqual(datatype.Restriction.Length, derivedRestriction.Length)) {
             throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
         }
     }
     if ((baseFlags & RestrictionFlags.Length) != 0) {
         if (datatype.Restriction.Length < derivedRestriction.Length) {
             throw new XmlSchemaException(Res.Sch_LengthGtBaseLength, facet);
         }
     }
     // If the base has the MinLength facet, check that our derived length is not violating it
     if ((baseFlags & RestrictionFlags.MinLength) != 0) {
         if (datatype.Restriction.MinLength > derivedRestriction.Length) {
             throw new XmlSchemaException(Res.Sch_MaxMinLengthBaseLength, facet);
         }
     }
     // If the base has the MaxLength facet, check that our derived length is not violating it
     if ((baseFlags & RestrictionFlags.MaxLength) != 0) {
         if (datatype.Restriction.MaxLength < derivedRestriction.Length) {
             throw new XmlSchemaException(Res.Sch_MaxMinLengthBaseLength, facet);
         }
     }
     SetFlag(facet, RestrictionFlags.Length);
 }
コード例 #3
0
 private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode)
 {
     if ((this.validRestrictionFlags & flag) == 0)
     {
         throw new XmlSchemaException(errorCode, this.datatype.TypeCodeString, facet);
     }
 }
コード例 #4
0
 private void SetFlag(XmlSchemaFacet facet, RestrictionFlags flag)
 {
     this.derivedRestriction.Flags |= flag;
     if (facet.IsFixed)
     {
         this.derivedRestriction.FixedFlags |= flag;
     }
 }
コード例 #5
0
 internal void CompileEnumerationFacet(XmlSchemaFacet facet, IXmlNamespaceResolver nsmgr, XmlNameTable nameTable)
 {
     this.CheckProhibitedFlag(facet, RestrictionFlags.Enumeration, "Sch_EnumerationFacetProhibited");
     if (this.derivedRestriction.Enumeration == null)
     {
         this.derivedRestriction.Enumeration = new ArrayList();
     }
     this.derivedRestriction.Enumeration.Add(this.ParseFacetValue(this.datatype, facet, "Sch_EnumerationFacetInvalid", nsmgr, nameTable));
     this.SetFlag(facet, RestrictionFlags.Enumeration);
 }
コード例 #6
0
            private object ParseFacetValue(XmlSchemaDatatype datatype, XmlSchemaFacet facet, string code, IXmlNamespaceResolver nsmgr, XmlNameTable nameTable)
            {
                object    obj2;
                Exception innerException = datatype.TryParseValue(facet.Value, nameTable, nsmgr, out obj2);

                if (innerException != null)
                {
                    throw new XmlSchemaException(code, new string[] { innerException.Message }, innerException, facet.SourceUri, facet.LineNumber, facet.LinePosition, facet);
                }
                return(obj2);
            }
コード例 #7
0
 internal void CompileMinExclusiveFacet(XmlSchemaFacet facet)
 {
     this.CheckProhibitedFlag(facet, RestrictionFlags.MinExclusive, "Sch_MinExclusiveFacetProhibited");
     this.CheckDupFlag(facet, RestrictionFlags.MinExclusive, "Sch_DupMinExclusiveFacet");
     this.derivedRestriction.MinExclusive = this.ParseFacetValue(this.builtInType, facet, "Sch_MinExclusiveFacetInvalid", null, null);
     if (((this.baseFixedFlags & RestrictionFlags.MinExclusive) != 0) && !this.datatype.IsEqual(this.datatype.Restriction.MinExclusive, this.derivedRestriction.MinExclusive))
     {
         throw new XmlSchemaException("Sch_FacetBaseFixed", facet);
     }
     this.CheckValue(this.derivedRestriction.MinExclusive, facet);
     this.SetFlag(facet, RestrictionFlags.MinExclusive);
 }
コード例 #8
0
 internal void CompileFractionDigitsFacet(XmlSchemaFacet facet)
 {
     this.CheckProhibitedFlag(facet, RestrictionFlags.FractionDigits, "Sch_FractionDigitsFacetProhibited");
     this.CheckDupFlag(facet, RestrictionFlags.FractionDigits, "Sch_DupFractionDigitsFacet");
     this.derivedRestriction.FractionDigits = XmlBaseConverter.DecimalToInt32((decimal)this.ParseFacetValue(this.nonNegativeInt, facet, "Sch_FractionDigitsFacetInvalid", null, null));
     if ((this.derivedRestriction.FractionDigits != 0) && (this.datatype.TypeCode != XmlTypeCode.Decimal))
     {
         throw new XmlSchemaException("Sch_FractionDigitsFacetInvalid", Res.GetString("Sch_FractionDigitsNotOnDecimal"), facet);
     }
     if (((this.baseFlags & RestrictionFlags.FractionDigits) != 0) && (this.derivedRestriction.FractionDigits > this.datatype.Restriction.FractionDigits))
     {
         throw new XmlSchemaException("Sch_TotalDigitsMismatch", string.Empty);
     }
     this.SetFlag(facet, RestrictionFlags.FractionDigits);
 }
コード例 #9
0
        internal void ValidateDerivationValid(object baseType, XmlSchemaObjectCollection facets, ValidationEventHandler h, XmlSchema schema)
        {
            XmlSchemaSimpleType       xmlSchemaSimpleType       = baseType as XmlSchemaSimpleType;
            XmlSchemaDerivationMethod xmlSchemaDerivationMethod = this.Variety;

            if (xmlSchemaDerivationMethod != XmlSchemaDerivationMethod.Restriction)
            {
                if (xmlSchemaDerivationMethod != XmlSchemaDerivationMethod.List)
                {
                    if (xmlSchemaDerivationMethod == XmlSchemaDerivationMethod.Union)
                    {
                        if (facets != null)
                        {
                            foreach (XmlSchemaObject xmlSchemaObject in facets)
                            {
                                XmlSchemaFacet xmlSchemaFacet = (XmlSchemaFacet)xmlSchemaObject;
                                if (!(xmlSchemaFacet is XmlSchemaEnumerationFacet) && !(xmlSchemaFacet is XmlSchemaPatternFacet))
                                {
                                    base.error(h, "Not allowed facet was found on this simple type which derives list type.");
                                }
                            }
                        }
                    }
                }
                else if (facets != null)
                {
                    foreach (XmlSchemaObject xmlSchemaObject2 in facets)
                    {
                        XmlSchemaFacet xmlSchemaFacet2 = (XmlSchemaFacet)xmlSchemaObject2;
                        if (!(xmlSchemaFacet2 is XmlSchemaLengthFacet) && !(xmlSchemaFacet2 is XmlSchemaMaxLengthFacet) && !(xmlSchemaFacet2 is XmlSchemaMinLengthFacet) && !(xmlSchemaFacet2 is XmlSchemaEnumerationFacet) && !(xmlSchemaFacet2 is XmlSchemaPatternFacet))
                        {
                            base.error(h, "Not allowed facet was found on this simple type which derives list type.");
                        }
                    }
                }
            }
            else
            {
                if (xmlSchemaSimpleType != null && xmlSchemaSimpleType.resolvedDerivedBy != XmlSchemaDerivationMethod.Restriction)
                {
                    base.error(h, "Base schema type is not either atomic type or primitive type.");
                }
                if (xmlSchemaSimpleType != null && (xmlSchemaSimpleType.FinalResolved & XmlSchemaDerivationMethod.Restriction) != XmlSchemaDerivationMethod.Empty)
                {
                    base.error(h, "Derivation by restriction is prohibited by the base simple type.");
                }
            }
        }
 private void Write_XmlSchemaFacet(string name, XmlSchemaFacet o)
 {
     if (o != null)
     {
         this.WriteStartElement(name);
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttribute("value", "", o.Value);
         if (o.IsFixed)
         {
             this.WriteAttribute("fixed", "", XmlConvert.ToString(o.IsFixed));
         }
         this.WriteAttributes(o.UnhandledAttributes, o);
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.WriteEndElement();
     }
 }
コード例 #11
0
            internal void CompileTotalDigitsFacet(XmlSchemaFacet facet)
            {
                this.CheckProhibitedFlag(facet, RestrictionFlags.TotalDigits, "Sch_TotalDigitsFacetProhibited");
                this.CheckDupFlag(facet, RestrictionFlags.TotalDigits, "Sch_DupTotalDigitsFacet");
                XmlSchemaDatatype datatype = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.PositiveInteger).Datatype;

                this.derivedRestriction.TotalDigits = XmlBaseConverter.DecimalToInt32((decimal)this.ParseFacetValue(datatype, facet, "Sch_TotalDigitsFacetInvalid", null, null));
                if (((this.baseFixedFlags & RestrictionFlags.TotalDigits) != 0) && !this.datatype.IsEqual(this.datatype.Restriction.TotalDigits, this.derivedRestriction.TotalDigits))
                {
                    throw new XmlSchemaException("Sch_FacetBaseFixed", facet);
                }
                if (((this.baseFlags & RestrictionFlags.TotalDigits) != 0) && (this.derivedRestriction.TotalDigits > this.datatype.Restriction.TotalDigits))
                {
                    throw new XmlSchemaException("Sch_TotalDigitsMismatch", string.Empty);
                }
                this.SetFlag(facet, RestrictionFlags.TotalDigits);
            }
コード例 #12
0
            internal void CompileWhitespaceFacet(XmlSchemaFacet facet)
            {
                XmlSchemaWhiteSpace whiteSpace;

                this.CheckProhibitedFlag(facet, RestrictionFlags.WhiteSpace, "Sch_WhiteSpaceFacetProhibited");
                this.CheckDupFlag(facet, RestrictionFlags.WhiteSpace, "Sch_DupWhiteSpaceFacet");
                if (facet.Value == "preserve")
                {
                    this.derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Preserve;
                }
                else if (facet.Value == "replace")
                {
                    this.derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Replace;
                }
                else
                {
                    if (facet.Value != "collapse")
                    {
                        throw new XmlSchemaException("Sch_InvalidWhiteSpace", facet.Value, facet);
                    }
                    this.derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Collapse;
                }
                if (((this.baseFixedFlags & RestrictionFlags.WhiteSpace) != 0) && !this.datatype.IsEqual(this.datatype.Restriction.WhiteSpace, this.derivedRestriction.WhiteSpace))
                {
                    throw new XmlSchemaException("Sch_FacetBaseFixed", facet);
                }
                if ((this.baseFlags & RestrictionFlags.WhiteSpace) != 0)
                {
                    whiteSpace = this.datatype.Restriction.WhiteSpace;
                }
                else
                {
                    whiteSpace = this.datatype.BuiltInWhitespaceFacet;
                }
                if ((whiteSpace == XmlSchemaWhiteSpace.Collapse) && ((this.derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Replace) || (this.derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve)))
                {
                    throw new XmlSchemaException("Sch_WhiteSpaceRestriction1", facet);
                }
                if ((whiteSpace == XmlSchemaWhiteSpace.Replace) && (this.derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve))
                {
                    throw new XmlSchemaException("Sch_WhiteSpaceRestriction2", facet);
                }
                this.SetFlag(facet, RestrictionFlags.WhiteSpace);
            }
コード例 #13
0
 internal void CompileMaxLengthFacet(XmlSchemaFacet facet)
 {
     this.CheckProhibitedFlag(facet, RestrictionFlags.MaxLength, "Sch_MaxLengthFacetProhibited");
     this.CheckDupFlag(facet, RestrictionFlags.MaxLength, "Sch_DupMaxLengthFacet");
     this.derivedRestriction.MaxLength = XmlBaseConverter.DecimalToInt32((decimal)this.ParseFacetValue(this.nonNegativeInt, facet, "Sch_MaxLengthFacetInvalid", null, null));
     if (((this.baseFixedFlags & RestrictionFlags.MaxLength) != 0) && !this.datatype.IsEqual(this.datatype.Restriction.MaxLength, this.derivedRestriction.MaxLength))
     {
         throw new XmlSchemaException("Sch_FacetBaseFixed", facet);
     }
     if (((this.baseFlags & RestrictionFlags.MaxLength) != 0) && (this.datatype.Restriction.MaxLength < this.derivedRestriction.MaxLength))
     {
         throw new XmlSchemaException("Sch_MaxLengthGtBaseMaxLength", facet);
     }
     if (((this.baseFlags & RestrictionFlags.Length) != 0) && (this.datatype.Restriction.Length > this.derivedRestriction.MaxLength))
     {
         throw new XmlSchemaException("Sch_MaxMinLengthBaseLength", facet);
     }
     this.SetFlag(facet, RestrictionFlags.MaxLength);
 }
コード例 #14
0
        /// <summary>
        /// Loads a facet for this property.
        /// </summary>
        /// <param name="facet">The facet to load for this property.</param>
        protected override void OnLoadFacet(XmlSchemaFacet facet)
        {
            base.OnLoadFacet(facet);

            var maxLengthFacet = facet as XmlSchemaMaxLengthFacet;

            if (maxLengthFacet != null)
            {
                int.TryParse(maxLengthFacet.Value, out _iMaxLength);
            }
            else
            {
                var lengthFacet = facet as XmlSchemaLengthFacet;

                if (lengthFacet != null)
                {
                    int.TryParse(lengthFacet.Value, out _iMaxLength);
                }
            }
        }
コード例 #15
0
 private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
 {
     XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
         Name = dataTypeName
     };
     XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
         BaseTypeName = baseTypeName
     };
     foreach (XmlSchemaFacet facet in facets)
     {
         restriction.Facets.Add(facet);
     }
     dataType.Content = restriction;
     TypeDesc desc = new TypeDesc(type, false, dataType, formatterName, flags);
     if (primitiveTypes[type] == null)
     {
         primitiveTypes.Add(type, desc);
     }
     primitiveDataTypes.Add(dataType, desc);
     primitiveNames.Add(dataTypeName, ns, desc);
 }
コード例 #16
0
        /// <summary>
        /// Loads a facet for this property.
        /// </summary>
        /// <param name="facet">The facet to load for this property.</param>
        protected virtual void OnLoadFacet(XmlSchemaFacet facet)
        {
            var patternFacet = facet as XmlSchemaPatternFacet;

            if (patternFacet != null)
                _strPattern = patternFacet.Value;
        }
コード例 #17
0
 /// <summary>
 /// Loads a facet for this property.
 /// </summary>
 /// <param name="facet">The facet to load for this property.</param>
 public void LoadFacet(XmlSchemaFacet facet)
 {
     OnLoadFacet(facet);
 }
コード例 #18
0
ファイル: BuiltInDatatype.cs プロジェクト: nobled/mono
			// Can you even use XsdAnySimpleType in a schema?
			// -> Yes. See E1-22 of http://www.w3.org/2001/05/xmlschema-errata#Errata1 (somewhat paranoid ;-)
		
		internal bool AllowsFacet(XmlSchemaFacet xsf) {
			return (AllowedFacets & xsf.ThisFacet)!=0;
		}
コード例 #19
0
 private void CheckValue(object value, XmlSchemaFacet facet, RestrictionFlags thisFlags) {
     if ((thisFlags & RestrictionFlags.MaxInclusive) != 0) {
         if (Compare(value, this.restriction.MaxInclusive) > 0) {
             throw new XmlSchemaException(Res.Sch_MaxInclusiveMismatch);
         }
     }
     if ((thisFlags & RestrictionFlags.MaxExclusive) != 0) {
         if (Compare(value, this.restriction.MaxExclusive) >= 0) {
             throw new XmlSchemaException(Res.Sch_MaxExclusiveMismatch);
         }
     }
     if ((thisFlags & RestrictionFlags.MinInclusive) != 0) {
         if (Compare(value, this.restriction.MinInclusive) < 0) {
             throw new XmlSchemaException(Res.Sch_MinInclusiveMismatch);
         }
     }
     if ((thisFlags & RestrictionFlags.MinExclusive) != 0) {
         if (Compare(value, this.restriction.MinExclusive) <= 0) {
             throw new XmlSchemaException(Res.Sch_MinExclusiveMismatch);
         }
     }
 }
コード例 #20
0
 private void SetFlag(RestrictionFacets restriction, XmlSchemaFacet facet, RestrictionFlags flag) {
     restriction.Flags |= flag;
     if (facet.IsFixed) {
         restriction.FixedFlags |= flag;
     }
 }
コード例 #21
0
 private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags validRestrictionFlags, RestrictionFlags flag, string errorCode) {
     if ((validRestrictionFlags & flag) == 0) {
         if(!valueType.Name.Equals("String[]"))
             throw new XmlSchemaException(errorCode, valueType.Name, facet);
         else
             throw new XmlSchemaException(errorCode, "IDREFS, NMTOKENS, ENTITIES", facet);
     }
 }
コード例 #22
0
 void Write_XmlSchemaFacet(string name, XmlSchemaFacet o) {
     if ((object)o == null) return;
     WriteStartElement(name);
     
     WriteAttribute("id", "", o.Id);
     WriteAttribute("value", "", o.Value);
     if (o.IsFixed) {
         WriteAttribute(@"fixed", @"", XmlConvert.ToString(o.IsFixed));
     }
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     WriteEndElement();
 }
コード例 #23
0
        internal virtual RestrictionFacets ConstructRestriction(DatatypeImplementation datatype, XmlSchemaObjectCollection facets, XmlNameTable nameTable)
        {
            RestrictionFacets restriction = new RestrictionFacets();
            FacetsCompiler    compiler    = new FacetsCompiler(datatype, restriction);

            for (int i = 0; i < facets.Count; i++)
            {
                XmlSchemaFacet source = (XmlSchemaFacet)facets[i];
                if (source.Value == null)
                {
                    throw new XmlSchemaException("Sch_InvalidFacet", source);
                }
                IXmlNamespaceResolver nsmgr = new SchemaNamespaceManager(source);
                switch (source.FacetType)
                {
                case FacetType.Length:
                    compiler.CompileLengthFacet(source);
                    break;

                case FacetType.MinLength:
                    compiler.CompileMinLengthFacet(source);
                    break;

                case FacetType.MaxLength:
                    compiler.CompileMaxLengthFacet(source);
                    break;

                case FacetType.Pattern:
                    compiler.CompilePatternFacet(source as XmlSchemaPatternFacet);
                    break;

                case FacetType.Whitespace:
                    compiler.CompileWhitespaceFacet(source);
                    break;

                case FacetType.Enumeration:
                    compiler.CompileEnumerationFacet(source, nsmgr, nameTable);
                    break;

                case FacetType.MinExclusive:
                    compiler.CompileMinExclusiveFacet(source);
                    break;

                case FacetType.MinInclusive:
                    compiler.CompileMinInclusiveFacet(source);
                    break;

                case FacetType.MaxExclusive:
                    compiler.CompileMaxExclusiveFacet(source);
                    break;

                case FacetType.MaxInclusive:
                    compiler.CompileMaxInclusiveFacet(source);
                    break;

                case FacetType.TotalDigits:
                    compiler.CompileTotalDigitsFacet(source);
                    break;

                case FacetType.FractionDigits:
                    compiler.CompileFractionDigitsFacet(source);
                    break;

                default:
                    throw new XmlSchemaException("Sch_UnknownFacet", source);
                }
            }
            compiler.FinishFacetCompile();
            compiler.CompileFacetCombinations();
            return(restriction);
        }
コード例 #24
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) {
     if ((derivedRestriction.Flags & flag) != 0) {
         throw new XmlSchemaException(errorCode, facet);
     }
 }
コード例 #25
0
            private void CheckValue(object value, XmlSchemaFacet facet)
            {
                RestrictionFacets restriction = this.datatype.Restriction;

                switch (facet.FacetType)
                {
                case FacetType.MinExclusive:
                    if (((this.baseFlags & RestrictionFlags.MinExclusive) != 0) && (this.datatype.Compare(value, restriction.MinExclusive) < 0))
                    {
                        throw new XmlSchemaException("Sch_MinExclusiveMismatch", string.Empty);
                    }
                    if (((this.baseFlags & RestrictionFlags.MinInclusive) != 0) && (this.datatype.Compare(value, restriction.MinInclusive) < 0))
                    {
                        throw new XmlSchemaException("Sch_MinExlIncMismatch", string.Empty);
                    }
                    if (((this.baseFlags & RestrictionFlags.MaxExclusive) != 0) && (this.datatype.Compare(value, restriction.MaxExclusive) >= 0))
                    {
                        throw new XmlSchemaException("Sch_MinExlMaxExlMismatch", string.Empty);
                    }
                    break;

                case FacetType.MinInclusive:
                    if (((this.baseFlags & RestrictionFlags.MinInclusive) != 0) && (this.datatype.Compare(value, restriction.MinInclusive) < 0))
                    {
                        throw new XmlSchemaException("Sch_MinInclusiveMismatch", string.Empty);
                    }
                    if (((this.baseFlags & RestrictionFlags.MinExclusive) != 0) && (this.datatype.Compare(value, restriction.MinExclusive) < 0))
                    {
                        throw new XmlSchemaException("Sch_MinIncExlMismatch", string.Empty);
                    }
                    if (((this.baseFlags & RestrictionFlags.MaxExclusive) == 0) || (this.datatype.Compare(value, restriction.MaxExclusive) < 0))
                    {
                        break;
                    }
                    throw new XmlSchemaException("Sch_MinIncMaxExlMismatch", string.Empty);

                case FacetType.MaxExclusive:
                    if (((this.baseFlags & RestrictionFlags.MaxExclusive) != 0) && (this.datatype.Compare(value, restriction.MaxExclusive) > 0))
                    {
                        throw new XmlSchemaException("Sch_MaxExclusiveMismatch", string.Empty);
                    }
                    if (((this.baseFlags & RestrictionFlags.MaxInclusive) == 0) || (this.datatype.Compare(value, restriction.MaxInclusive) <= 0))
                    {
                        break;
                    }
                    throw new XmlSchemaException("Sch_MaxExlIncMismatch", string.Empty);

                case FacetType.MaxInclusive:
                    if (((this.baseFlags & RestrictionFlags.MaxInclusive) != 0) && (this.datatype.Compare(value, restriction.MaxInclusive) > 0))
                    {
                        throw new XmlSchemaException("Sch_MaxInclusiveMismatch", string.Empty);
                    }
                    if (((this.baseFlags & RestrictionFlags.MaxExclusive) == 0) || (this.datatype.Compare(value, restriction.MaxExclusive) < 0))
                    {
                        break;
                    }
                    throw new XmlSchemaException("Sch_MaxIncExlMismatch", string.Empty);

                default:
                    return;
                }
            }
コード例 #26
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
        private void CheckValue(object value, XmlSchemaFacet facet) {
            RestrictionFacets restriction = datatype.Restriction;
            switch (facet.FacetType) {
                case FacetType.MaxInclusive:
                    if ((baseFlags & RestrictionFlags.MaxInclusive) != 0) { //Base facet has maxInclusive
                        if (datatype.Compare(value, restriction.MaxInclusive) > 0) {
                            throw new XmlSchemaException(Res.Sch_MaxInclusiveMismatch, string.Empty);
                        }
                    }
                    if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
                        if (datatype.Compare(value, restriction.MaxExclusive) >= 0) {
                            throw new XmlSchemaException(Res.Sch_MaxIncExlMismatch, string.Empty);
                        }
                    }
                break;

                case FacetType.MaxExclusive:
                    if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
                        if (datatype.Compare(value, restriction.MaxExclusive) > 0) {
                            throw new XmlSchemaException(Res.Sch_MaxExclusiveMismatch, string.Empty);
                        }
                    }
                    if ((baseFlags & RestrictionFlags.MaxInclusive) != 0) { //Base facet has maxInclusive
                        if (datatype.Compare(value, restriction.MaxInclusive) > 0) {
                            throw new XmlSchemaException(Res.Sch_MaxExlIncMismatch, string.Empty);
                        }
                    }
                break;

                case FacetType.MinInclusive:
                    if ((baseFlags & RestrictionFlags.MinInclusive) != 0) { //Base facet has minInclusive
                        if (datatype.Compare(value, restriction.MinInclusive) < 0) {
                            throw new XmlSchemaException(Res.Sch_MinInclusiveMismatch, string.Empty);
                        }
                    }
                    if ((baseFlags & RestrictionFlags.MinExclusive) != 0) { //Base facet has minExclusive
                        if (datatype.Compare(value, restriction.MinExclusive) < 0) {
                            throw new XmlSchemaException(Res.Sch_MinIncExlMismatch, string.Empty);
                        }
                    }
                    if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
                        if (datatype.Compare(value, restriction.MaxExclusive) >= 0) {
                            throw new XmlSchemaException(Res.Sch_MinIncMaxExlMismatch, string.Empty);
                        }
                    }
                break;

                case FacetType.MinExclusive:
                    if ((baseFlags & RestrictionFlags.MinExclusive) != 0) { //Base facet has minExclusive
                        if (datatype.Compare(value, restriction.MinExclusive) < 0) {
                            throw new XmlSchemaException(Res.Sch_MinExclusiveMismatch, string.Empty);
                        }
                    }
                    if ((baseFlags & RestrictionFlags.MinInclusive) != 0) { //Base facet has minInclusive
                        if (datatype.Compare(value, restriction.MinInclusive) < 0) {
                            throw new XmlSchemaException(Res.Sch_MinExlIncMismatch, string.Empty);
                        }
                    }
                    if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
                        if (datatype.Compare(value, restriction.MaxExclusive) >= 0) {
                            throw new XmlSchemaException(Res.Sch_MinExlMaxExlMismatch, string.Empty);
                        }
                    }
                break;

                default:
                    Debug.Assert(false);
                break;
            }
        }
コード例 #27
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 internal void CompileTotalDigitsFacet(XmlSchemaFacet facet) {
     CheckProhibitedFlag(facet, RestrictionFlags.TotalDigits, Res.Sch_TotalDigitsFacetProhibited);
     CheckDupFlag(facet, RestrictionFlags.TotalDigits, Res.Sch_DupTotalDigitsFacet);
     XmlSchemaDatatype positiveInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.PositiveInteger).Datatype;                        
     derivedRestriction.TotalDigits = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(positiveInt, facet, Res.Sch_TotalDigitsFacetInvalid, null, null));
     
     if ((baseFixedFlags & RestrictionFlags.TotalDigits) != 0) {
         if (!datatype.IsEqual(datatype.Restriction.TotalDigits, derivedRestriction.TotalDigits)) {
             throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
         }
     }
     if ((baseFlags & RestrictionFlags.TotalDigits) != 0) {
         if(derivedRestriction.TotalDigits > datatype.Restriction.TotalDigits) {
             throw new XmlSchemaException(Res.Sch_TotalDigitsMismatch, string.Empty);
         }
     }
     SetFlag(facet, RestrictionFlags.TotalDigits);
 }
コード例 #28
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 internal void CompileWhitespaceFacet(XmlSchemaFacet facet) {
     CheckProhibitedFlag(facet, RestrictionFlags.WhiteSpace, Res.Sch_WhiteSpaceFacetProhibited);
     CheckDupFlag(facet, RestrictionFlags.WhiteSpace, Res.Sch_DupWhiteSpaceFacet);
     if (facet.Value == "preserve") {
         derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Preserve;
     }
     else if (facet.Value == "replace") {
         derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Replace;
     }
     else if (facet.Value == "collapse") {
         derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Collapse;
     }
     else {
         throw new XmlSchemaException(Res.Sch_InvalidWhiteSpace, facet.Value, facet);
     }
     if ((baseFixedFlags & RestrictionFlags.WhiteSpace) != 0) {
         if (!datatype.IsEqual(datatype.Restriction.WhiteSpace, derivedRestriction.WhiteSpace)) {
             throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
         }
     }
     //Check base and derived whitespace facets
     XmlSchemaWhiteSpace baseWhitespace;
     if ((baseFlags & RestrictionFlags.WhiteSpace) != 0) {
         baseWhitespace = datatype.Restriction.WhiteSpace;
     }
     else {
         baseWhitespace = datatype.BuiltInWhitespaceFacet;
     }
     if ( baseWhitespace == XmlSchemaWhiteSpace.Collapse &&
         (derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Replace || derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve)
     ) {
         throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction1, facet);
     }
     if (baseWhitespace == XmlSchemaWhiteSpace.Replace &&
         derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve
     ) {
         throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction2, facet);
     }
     SetFlag(facet, RestrictionFlags.WhiteSpace);
 }
コード例 #29
0
        /// <summary>
        /// Loads a facet for this property.
        /// </summary>
        /// <param name="facet">The facet to load for this property.</param>
        protected override void OnLoadFacet(XmlSchemaFacet facet)
        {
            base.OnLoadFacet(facet);

            var minFacet = facet as XmlSchemaMinInclusiveFacet;

            if (minFacet != null)
            {
                ushort.TryParse(minFacet.Value, out _usMin);
            }
            else
            {
                var maxFacet = facet as XmlSchemaMaxInclusiveFacet;

                if (maxFacet != null)
                {
                    ushort.TryParse(maxFacet.Value, out _usMax);
                }
                else
                {
                    var totalDigitsFacet = facet as XmlSchemaTotalDigitsFacet;

                    if (totalDigitsFacet != null)
                        int.TryParse(totalDigitsFacet.Value, out _iLength);
                }
            }
        }
コード例 #30
0
ファイル: XsdBuilder.cs プロジェクト: uQr/referencesource
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
コード例 #31
0
 private void CheckFixedFlag(XmlSchemaFacet facet, RestrictionFlags fixedFlags, RestrictionFlags flag) {
     if ((fixedFlags & flag) != 0) {
         throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
     }
 }
コード例 #32
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 internal void CompileEnumerationFacet(XmlSchemaFacet facet, IXmlNamespaceResolver nsmgr, XmlNameTable nameTable) {
     CheckProhibitedFlag(facet, RestrictionFlags.Enumeration, Res.Sch_EnumerationFacetProhibited);
     if (derivedRestriction.Enumeration == null) {
         derivedRestriction.Enumeration = new ArrayList();
     }
     derivedRestriction.Enumeration.Add(ParseFacetValue(datatype, facet, Res.Sch_EnumerationFacetInvalid, nsmgr, nameTable));
     SetFlag(facet, RestrictionFlags.Enumeration);
 }
コード例 #33
0
		private void checkMinMaxFacet(XmlSchemaFacet facet, 
																		ref object baseFacet,
																		ValidationEventHandler h) { 
// Is it a valid instance of the base type.
		 object newValue = ValidateValueWithDatatype(facet.Value);
		 if (newValue != null) {
// Is the base fixed - if so is it the same
			 if (((fixedFacets & facet.ThisFacet) != 0)  && (baseFacet != null)){
				 XsdAnySimpleType dt = getDatatype();
				 if (dt.Compare (newValue, baseFacet) != XsdOrdering.Equal) {
					 facet.error (h, 
							 String.Format(CultureInfo.InvariantCulture, "{0} is not the same as fixed parent {1} facet.", 
										 facet.Value, facet.ThisFacet));
				 }
			 }
			 baseFacet = newValue;
		 }
		 else {
			 facet.error(h, 
					 String.Format("The value '{0}' is not valid against the base type.", facet.Value));
		 }
		}
コード例 #34
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
        internal void CompileMinExclusiveFacet(XmlSchemaFacet facet) {
            CheckProhibitedFlag(facet, RestrictionFlags.MinExclusive, Res.Sch_MinExclusiveFacetProhibited);
            CheckDupFlag(facet, RestrictionFlags.MinExclusive, Res.Sch_DupMinExclusiveFacet);
            derivedRestriction.MinExclusive = ParseFacetValue(builtInType, facet, Res.Sch_MinExclusiveFacetInvalid, null, null);

            if ((baseFixedFlags & RestrictionFlags.MinExclusive) != 0) {
                if (!datatype.IsEqual(datatype.Restriction.MinExclusive, derivedRestriction.MinExclusive)) {
                    throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
                }
            }
            CheckValue(derivedRestriction.MinExclusive, facet);
            SetFlag(facet, RestrictionFlags.MinExclusive);
        }
コード例 #35
0
		private void checkLengthFacet(XmlSchemaLengthFacet lf,	
																	XmlSchemaFacet.Facet facetsDefined, 
																	ValidationEventHandler h) {
				if (lf != null) {
					try {
					if ((facetsDefined & (XmlSchemaFacet.Facet.minLength | XmlSchemaFacet.Facet.maxLength)) != 0)  
							lf.error(h, "It is an error for both length and minLength or maxLength to be present.");
						else {
							lengthFacet = decimal.Parse (lf.Value.Trim (), lengthStyle, CultureInfo.InvariantCulture);
						/* TODO: Check that it is between inherited max/min lengths */
							if (lengthFacet < 0) 
								lf.error(h, "The value '" + lengthFacet + "' is an invalid length");
						}
				} catch (FormatException) { // FIXME: better catch ;-(
						lf.error (h, "The value '" + lf.Value + "' is an invalid length facet specification");
					}
				}
		}
コード例 #36
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
        internal void CompileFractionDigitsFacet(XmlSchemaFacet facet) {
            CheckProhibitedFlag(facet, RestrictionFlags.FractionDigits, Res.Sch_FractionDigitsFacetProhibited);
            CheckDupFlag(facet, RestrictionFlags.FractionDigits, Res.Sch_DupFractionDigitsFacet);
            derivedRestriction.FractionDigits = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(nonNegativeInt, facet, Res.Sch_FractionDigitsFacetInvalid, null, null));

            if ((derivedRestriction.FractionDigits != 0) && (datatype.TypeCode != XmlTypeCode.Decimal)) {
                throw new XmlSchemaException(Res.Sch_FractionDigitsFacetInvalid, Res.GetString(Res.Sch_FractionDigitsNotOnDecimal), facet);
            }
            if ((baseFlags & RestrictionFlags.FractionDigits) != 0) {
                if (derivedRestriction.FractionDigits > datatype.Restriction.FractionDigits) {
                    throw new XmlSchemaException(Res.Sch_TotalDigitsMismatch, string.Empty);
                }
            }
            SetFlag(facet, RestrictionFlags.FractionDigits);
        }
コード例 #37
0
		private void checkMinLengthFacet(XmlSchemaMinLengthFacet minlf, 
																		 XmlSchemaFacet.Facet facetsDefined,
																		 ValidationEventHandler h) {
				if (minlf != null) {
					try {
						if (lengthFacet >=0) 
							minlf.error(h, "It is an error for both length and minLength or maxLength to be present.");
						else {
						decimal newMinLengthFacet = decimal.Parse (minlf.Value.Trim (), lengthStyle, CultureInfo.InvariantCulture);
						
						if (((fixedFacets & XmlSchemaFacet.Facet.minLength)!=0) && (newMinLengthFacet != minLengthFacet)) 
							minlf.error(h, String.Format(CultureInfo.InvariantCulture, "The value '{0}' is not the same as the fixed value '{1}' on the base type", minlf.Value.Trim (), minLengthFacet));
						if (newMinLengthFacet < minLengthFacet) 
							minlf.error(h, String.Format(CultureInfo.InvariantCulture, "The value '{0}' is not a valid restriction of the value '{1}' on the base minLength facet", minlf.Value.Trim (), minLengthFacet));
						else
							minLengthFacet = newMinLengthFacet;
							if (minLengthFacet < 0) 
								minlf.error(h, "The value '" + minLengthFacet + "' is an invalid minLength");
							if (maxLengthFacet >=0 && minLengthFacet > maxLengthFacet)
								minlf.error(h, "minLength is greater than maxLength.");
						}
				} catch (FormatException) {
						minlf.error (h, "The value '" + minlf.Value + "' is an invalid minLength facet specification");
					}
				}
			}
コード例 #38
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 private object ParseFacetValue(XmlSchemaDatatype datatype, XmlSchemaFacet facet, string code, IXmlNamespaceResolver nsmgr, XmlNameTable nameTable) {
     object typedValue;
     Exception ex = datatype.TryParseValue(facet.Value, nameTable, nsmgr, out typedValue);
     if (ex == null) {
         return typedValue;
     }
     else {
         throw new XmlSchemaException(code, new string[] {ex.Message} , ex, facet.SourceUri, facet.LineNumber, facet.LinePosition, facet);
     }
 }
コード例 #39
0
ファイル: FacetChecker.cs プロジェクト: geoffkizer/corefx
            internal void CompileMaxInclusiveFacet(XmlSchemaFacet facet)
            {
                CheckProhibitedFlag(facet, RestrictionFlags.MaxInclusive, SR.Sch_MaxInclusiveFacetProhibited);
                CheckDupFlag(facet, RestrictionFlags.MaxInclusive, SR.Sch_DupMaxInclusiveFacet);
                _derivedRestriction.MaxInclusive = ParseFacetValue(_builtInType, facet, SR.Sch_MaxInclusiveFacetInvalid, null, null);

                if ((_baseFixedFlags & RestrictionFlags.MaxInclusive) != 0)
                {
                    if (!_datatype.IsEqual(_datatype.Restriction.MaxInclusive, _derivedRestriction.MaxInclusive))
                    {
                        throw new XmlSchemaException(SR.Sch_FacetBaseFixed, facet);
                    }
                }
                CheckValue(_derivedRestriction.MaxInclusive, facet);
                SetFlag(facet, RestrictionFlags.MaxInclusive);
            }
コード例 #40
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) {
     if ((validRestrictionFlags & flag) == 0) {
         throw new XmlSchemaException(errorCode, datatype.TypeCodeString, facet);
     }
 }
コード例 #41
0
ファイル: FacetChecker.cs プロジェクト: geoffkizer/corefx
            internal void CompileMinLengthFacet(XmlSchemaFacet facet)
            {
                CheckProhibitedFlag(facet, RestrictionFlags.MinLength, SR.Sch_MinLengthFacetProhibited);
                CheckDupFlag(facet, RestrictionFlags.MinLength, SR.Sch_DupMinLengthFacet);
                _derivedRestriction.MinLength = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(_nonNegativeInt, facet, SR.Sch_MinLengthFacetInvalid, null, null));

                if ((_baseFixedFlags & RestrictionFlags.MinLength) != 0)
                {
                    if (!_datatype.IsEqual(_datatype.Restriction.MinLength, _derivedRestriction.MinLength))
                    {
                        throw new XmlSchemaException(SR.Sch_FacetBaseFixed, facet);
                    }
                }
                if ((_baseFlags & RestrictionFlags.MinLength) != 0)
                {
                    if (_datatype.Restriction.MinLength > _derivedRestriction.MinLength)
                    {
                        throw new XmlSchemaException(SR.Sch_MinLengthGtBaseMinLength, facet);
                    }
                }
                if ((_baseFlags & RestrictionFlags.Length) != 0)
                {
                    if (_datatype.Restriction.Length < _derivedRestriction.MinLength)
                    {
                        throw new XmlSchemaException(SR.Sch_MaxMinLengthBaseLength, facet);
                    }
                }
                SetFlag(facet, RestrictionFlags.MinLength);
            }
コード例 #42
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 private void SetFlag(XmlSchemaFacet facet, RestrictionFlags flag) {
     derivedRestriction.Flags |= flag;
     if (facet.IsFixed) {
         derivedRestriction.FixedFlags |= flag;
     }
 }
コード例 #43
0
        /// <summary>
        /// Loads a facet for this property.
        /// </summary>
        /// <param name="facet">The facet to load for this property.</param>
        protected override void OnLoadFacet(XmlSchemaFacet facet)
        {
            base.OnLoadFacet(facet);

            var minFacet = facet as XmlSchemaMinInclusiveFacet;

            if (minFacet != null)
            {
                decimal.TryParse(minFacet.Value, out _dMin);
            }
            else
            {
                var maxFacet = facet as XmlSchemaMaxInclusiveFacet;

                if (maxFacet != null)
                {
                    decimal.TryParse(maxFacet.Value, out _dMax);
                }
                else
                {
                    var totalDigitsFacet = facet as XmlSchemaTotalDigitsFacet;

                    if (totalDigitsFacet != null)
                    {
                        int.TryParse(totalDigitsFacet.Value, out _iLength);
                    }
                    else
                    {
                        var factionFacet = facet as XmlSchemaFractionDigitsFacet;

                        if (factionFacet != null)
                        {
                            int.TryParse(factionFacet.Value, out _iDecimalPlaces);
                        }
                    }
                }
            }
        }