コード例 #1
0
        internal void CheckWhitespaceFacets(ref string s, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;

            switch (datatype.Variety)
            {
            case XmlSchemaDatatypeVariety.Atomic:
                if (datatype.BuiltInWhitespaceFacet != XmlSchemaWhiteSpace.Collapse)
                {
                    if (datatype.BuiltInWhitespaceFacet == XmlSchemaWhiteSpace.Replace)
                    {
                        s = XmlComplianceUtil.CDataNormalize(s);
                    }
                    else if ((restriction != null) && ((restriction.Flags & RestrictionFlags.WhiteSpace) != 0))
                    {
                        if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace)
                        {
                            s = XmlComplianceUtil.CDataNormalize(s);
                            return;
                        }
                        if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse)
                        {
                            s = XmlComplianceUtil.NonCDataNormalize(s);
                        }
                    }
                    return;
                }
                s = XmlComplianceUtil.NonCDataNormalize(s);
                return;

            case XmlSchemaDatatypeVariety.List:
                s = s.Trim();
                return;
            }
        }
コード例 #2
0
        internal override Exception CheckValueFacets(XmlQualifiedName value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if (flags != 0)
            {
                int length = value.ToString().Length;
                if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
                {
                    return(new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
                {
                    return(new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
                {
                    return(new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration))
                {
                    return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
                }
            }
            return(null);
        }
コード例 #3
0
        internal Exception CheckValueFacets(string value, XmlSchemaDatatype datatype, bool verifyUri)
        {
            int length = value.Length;
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            Exception         exception   = this.CheckBuiltInFacets(value, datatype.TypeCode, verifyUri);

            if (exception != null)
            {
                return(exception);
            }
            if (flags != 0)
            {
                if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
                {
                    return(new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
                {
                    return(new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
                {
                    return(new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
                {
                    return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
                }
            }
            return(null);
        }
コード例 #4
0
        internal override Exception CheckValueFacets(TimeSpan value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MaxInclusive) > 0))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MaxExclusive) >= 0))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MinInclusive) < 0))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (TimeSpan.Compare(value, (TimeSpan)restriction.MinExclusive) <= 0))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
コード例 #5
0
        internal override Exception CheckValueFacets(double value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDouble(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDouble(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDouble(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDouble(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
コード例 #6
0
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            Array             array       = value as Array;
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if ((flags & (RestrictionFlags.MaxLength | RestrictionFlags.MinLength | RestrictionFlags.Length)) != 0)
            {
                int length = array.Length;
                if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
                {
                    return(new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
                {
                    return(new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty));
                }
                if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
                {
                    return(new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty));
                }
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
コード例 #7
0
        internal override Exception CheckValueFacets(object value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction = datatype.Restriction;
            RestrictionFlags  flags       = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);

            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, datatype))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(null);
        }
コード例 #8
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction) {
     firstPattern = true;
     regStr = null;
     pattern_facet = null;
     datatype = baseDatatype;
     derivedRestriction = restriction;
     baseFlags = datatype.Restriction != null ? datatype.Restriction.Flags : 0;
     baseFixedFlags = datatype.Restriction != null ? datatype.Restriction.FixedFlags : 0;
     validRestrictionFlags = datatype.ValidRestrictionFlags;
     nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     builtInEnum = !(datatype is Datatype_union || datatype is Datatype_List) ? datatype.TypeCode : 0;
     builtInType = (int)builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(builtInEnum).Datatype : datatype;
 }
コード例 #9
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern          = true;
     this.regStr                = null;
     this.pattern_facet         = null;
     this.datatype              = baseDatatype;
     this.derivedRestriction    = restriction;
     this.baseFlags             = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags)0);
     this.baseFixedFlags        = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags)0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt        = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum           = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType           = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
コード例 #10
0
ファイル: FacetChecker.cs プロジェクト: geoffkizer/corefx
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     _firstPattern = true;
     _regStr = null;
     _pattern_facet = null;
     _datatype = baseDatatype;
     _derivedRestriction = restriction;
     _baseFlags = _datatype.Restriction != null ? _datatype.Restriction.Flags : 0;
     _baseFixedFlags = _datatype.Restriction != null ? _datatype.Restriction.FixedFlags : 0;
     _validRestrictionFlags = _datatype.ValidRestrictionFlags;
     _nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     _builtInEnum = !(_datatype is Datatype_union || _datatype is Datatype_List) ? _datatype.TypeCode : 0;
     _builtInType = (int)_builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(_builtInEnum).Datatype : _datatype;
 }
コード例 #11
0
 internal Exception CheckPatternFacets(RestrictionFacets restriction, string value)
 {
     if ((restriction != null) && ((restriction.Flags & RestrictionFlags.Pattern) != 0))
     {
         for (int i = 0; i < restriction.Patterns.Count; i++)
         {
             Regex regex = (Regex)restriction.Patterns[i];
             if (!regex.IsMatch(value))
             {
                 return(new XmlSchemaException("Sch_PatternConstraintFailed", string.Empty));
             }
         }
     }
     return(null);
 }
コード例 #12
0
 internal Exception CheckPatternFacets(RestrictionFacets restriction, string value)
 {
     if ((restriction != null) && ((restriction.Flags & RestrictionFlags.Pattern) != 0))
     {
         for (int i = 0; i < restriction.Patterns.Count; i++)
         {
             Regex regex = (Regex) restriction.Patterns[i];
             if (!regex.IsMatch(value))
             {
                 return new XmlSchemaException("Sch_PatternConstraintFailed", string.Empty);
             }
         }
     }
     return null;
 }
コード例 #13
0
            internal void CompileFacetCombinations()
            {
                RestrictionFacets restriction = this.datatype.Restriction;

                if (((this.derivedRestriction.Flags & RestrictionFlags.MaxInclusive) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MaxExclusive) != 0))
                {
                    throw new XmlSchemaException("Sch_MaxInclusiveExclusive", string.Empty);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MinInclusive) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MinExclusive) != 0))
                {
                    throw new XmlSchemaException("Sch_MinInclusiveExclusive", string.Empty);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.Length) != 0) && ((this.derivedRestriction.Flags & (RestrictionFlags.MaxLength | RestrictionFlags.MinLength)) != 0))
                {
                    throw new XmlSchemaException("Sch_LengthAndMinMax", string.Empty);
                }
                this.CopyFacetsFromBaseType();
                if ((((this.derivedRestriction.Flags & RestrictionFlags.MinLength) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MaxLength) != 0)) && (this.derivedRestriction.MinLength > this.derivedRestriction.MaxLength))
                {
                    throw new XmlSchemaException("Sch_MinLengthGtMaxLength", string.Empty);
                }
                if ((((this.derivedRestriction.Flags & RestrictionFlags.MinInclusive) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MaxInclusive) != 0)) && (this.datatype.Compare(this.derivedRestriction.MinInclusive, this.derivedRestriction.MaxInclusive) > 0))
                {
                    throw new XmlSchemaException("Sch_MinInclusiveGtMaxInclusive", string.Empty);
                }
                if ((((this.derivedRestriction.Flags & RestrictionFlags.MinInclusive) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MaxExclusive) != 0)) && (this.datatype.Compare(this.derivedRestriction.MinInclusive, this.derivedRestriction.MaxExclusive) > 0))
                {
                    throw new XmlSchemaException("Sch_MinInclusiveGtMaxExclusive", string.Empty);
                }
                if ((((this.derivedRestriction.Flags & RestrictionFlags.MinExclusive) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MaxExclusive) != 0)) && (this.datatype.Compare(this.derivedRestriction.MinExclusive, this.derivedRestriction.MaxExclusive) > 0))
                {
                    throw new XmlSchemaException("Sch_MinExclusiveGtMaxExclusive", string.Empty);
                }
                if ((((this.derivedRestriction.Flags & RestrictionFlags.MinExclusive) != 0) && ((this.derivedRestriction.Flags & RestrictionFlags.MaxInclusive) != 0)) && (this.datatype.Compare(this.derivedRestriction.MinExclusive, this.derivedRestriction.MaxInclusive) > 0))
                {
                    throw new XmlSchemaException("Sch_MinExclusiveGtMaxInclusive", string.Empty);
                }
                if (((this.derivedRestriction.Flags & (RestrictionFlags.FractionDigits | RestrictionFlags.TotalDigits)) == (RestrictionFlags.FractionDigits | RestrictionFlags.TotalDigits)) && (this.derivedRestriction.FractionDigits > this.derivedRestriction.TotalDigits))
                {
                    throw new XmlSchemaException("Sch_FractionDigitsGtTotalDigits", string.Empty);
                }
            }
コード例 #14
0
        internal override Exception CheckValueFacets(decimal value, XmlSchemaDatatype datatype)
        {
            RestrictionFacets restriction    = datatype.Restriction;
            RestrictionFlags  flags          = (restriction != null) ? restriction.Flags : ((RestrictionFlags)0);
            XmlValueConverter valueConverter = datatype.ValueConverter;

            if ((value > this.maxValue) || (value < this.minValue))
            {
                return(new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { value.ToString(CultureInfo.InvariantCulture), datatype.TypeCodeString })));
            }
            if (flags == 0)
            {
                return(null);
            }
            if (((flags & RestrictionFlags.MaxInclusive) != 0) && (value > valueConverter.ToDecimal(restriction.MaxInclusive)))
            {
                return(new XmlSchemaException("Sch_MaxInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MaxExclusive) != 0) && (value >= valueConverter.ToDecimal(restriction.MaxExclusive)))
            {
                return(new XmlSchemaException("Sch_MaxExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinInclusive) != 0) && (value < valueConverter.ToDecimal(restriction.MinInclusive)))
            {
                return(new XmlSchemaException("Sch_MinInclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.MinExclusive) != 0) && (value <= valueConverter.ToDecimal(restriction.MinExclusive)))
            {
                return(new XmlSchemaException("Sch_MinExclusiveConstraintFailed", string.Empty));
            }
            if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration, valueConverter))
            {
                return(new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty));
            }
            return(this.CheckTotalAndFractionDigits(value, restriction.TotalDigits, restriction.FractionDigits, (flags & RestrictionFlags.TotalDigits) != 0, (flags & RestrictionFlags.FractionDigits) != 0));
        }
コード例 #15
0
 internal Exception CheckPatternFacets(RestrictionFacets restriction, string value) {
     if (restriction != null && (restriction.Flags & RestrictionFlags.Pattern) != 0) {
         foreach(Regex regex in restriction.Patterns) {
             if (!regex.IsMatch(value)) {
                 return new XmlSchemaException(Res.Sch_PatternConstraintFailed, string.Empty);
             }
         }
     }
     return null;
 }
コード例 #16
0
        private void ConstrainAtomicValue(RestrictionFacets restriction, object value) {
            RestrictionFlags flags = restriction.Flags;
            if ((flags & (RestrictionFlags.Length|RestrictionFlags.MinLength|RestrictionFlags.MaxLength)) != 0) {
                int length = LengthOf(value);
                if ((flags & RestrictionFlags.Length) != 0) {
                    if (restriction.Length != length) {
                        throw new XmlSchemaException(Res.Sch_LengthConstraintFailed);
                    }
                }

                if ((flags & RestrictionFlags.MinLength) != 0) {
                    if (length < restriction.MinLength) {
                        throw new XmlSchemaException(Res.Sch_MinLengthConstraintFailed);
                    }
                }

                if ((flags & RestrictionFlags.MaxLength) != 0) {
                    if (restriction.MaxLength < length) {
                        throw new XmlSchemaException(Res.Sch_MaxLengthConstraintFailed);
                    }
                }
            }

            if ((flags & RestrictionFlags.MaxInclusive) != 0) {
                if (Compare(value, restriction.MaxInclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MaxInclusiveConstraintFailed);
                }
            }

            if ((flags & RestrictionFlags.MaxExclusive) != 0) {
                if (Compare(value, restriction.MaxExclusive) >= 0) {
                    throw new XmlSchemaException(Res.Sch_MaxExclusiveConstraintFailed);
                }
            }

            if ((flags & RestrictionFlags.MinInclusive) != 0) {
                if (Compare(value, restriction.MinInclusive) < 0) {
                    throw new XmlSchemaException(Res.Sch_MinInclusiveConstraintFailed);
                }
            }

            if ((flags & RestrictionFlags.MinExclusive) != 0) {
                if (Compare(value, restriction.MinExclusive) <= 0) {
                    throw new XmlSchemaException(Res.Sch_MinExclusiveConstraintFailed);
                }
            }

            if ((flags & RestrictionFlags.MinExclusive) != 0) {
                if (Compare(value, restriction.MinExclusive) <= 0) {
                    throw new XmlSchemaException(Res.Sch_MinExclusiveConstraintFailed);
                }
            }

            if ((flags & RestrictionFlags.Enumeration) != 0) {
                if(!MatchEnumeration(value, restriction.Enumeration)) {
                    throw new XmlSchemaException(Res.Sch_EnumerationConstraintFailed);
                }
            }
        }
コード例 #17
0
 private void SetFlag(RestrictionFacets restriction, RestrictionFlags fixedFlags, RestrictionFlags flag) {
     restriction.Flags |= flag;
     if ((fixedFlags & flag) != 0) {
         restriction.FixedFlags |= flag;
     }
 }
コード例 #18
0
 private void SetFlag(RestrictionFacets restriction, XmlSchemaFacet facet, RestrictionFlags flag) {
     restriction.Flags |= flag;
     if (facet.IsFixed) {
         restriction.FixedFlags |= flag;
     }
 }
コード例 #19
0
 private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFacets restriction, RestrictionFlags flag, string errorCode) {
     if ((restriction.Flags & flag) != 0) {
         throw new XmlSchemaException(errorCode, facet);
     }
 }
コード例 #20
0
        private RestrictionFacets ConstructRestriction(XmlSchemaObjectCollection facets, XmlNameTable nameTable) {
            RestrictionFacets restriction = new RestrictionFacets();
            RestrictionFlags thisFlags = this.restriction != null ? this.restriction.Flags : 0;
            RestrictionFlags fixedFlags = this.restriction != null ? this.restriction.FixedFlags : 0;
            RestrictionFlags validRestrictionFlags = ValidRestrictionFlags;
            if (variety == XmlSchemaDatatypeVariety.List) {
                validRestrictionFlags = RestrictionFlags.Length|RestrictionFlags.MinLength|RestrictionFlags.MaxLength|RestrictionFlags.Enumeration|RestrictionFlags.WhiteSpace;
                if (minListSize == 0) {
                    validRestrictionFlags |= RestrictionFlags.Pattern;
                }
            }
            StringBuilder regStr = new StringBuilder();
            XmlSchemaFacet pattern_facet = null;
            bool firstP = true;

            foreach (XmlSchemaFacet facet in facets) {
                if (facet.Value == null) {
                    throw new XmlSchemaException(Res.Sch_InvalidFacet, facet);
                }
                XmlNamespaceManager nsmgr = new SchemaNamespaceManager(facet);
                if (facet is XmlSchemaLengthFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.Length);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.Length, Res.Sch_LengthFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.Length, Res.Sch_DupLengthFacet);
                    try {
                        restriction.Length = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_LengthFacetInvalid, e.Message, facet);
                    }
                    if ((thisFlags & RestrictionFlags.Length) != 0) {
                        if (this.restriction.Length < restriction.Length) {
                            throw new XmlSchemaException(Res.Sch_LengthGtBaseLength, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.Length);
                }
                else if (facet is XmlSchemaMinLengthFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MinLength);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MinLength, Res.Sch_MinLengthFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MinLength, Res.Sch_DupMinLengthFacet);
                    try {
                        restriction.MinLength = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MinLengthFacetInvalid, e.Message, facet);
                    }
                    if ((thisFlags & RestrictionFlags.MinLength) != 0) {
                        if (this.restriction.MinLength > restriction.MinLength) {
                            throw new XmlSchemaException(Res.Sch_MinLengthGtBaseMinLength, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.MinLength);
                }
                else if (facet is XmlSchemaMaxLengthFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MaxLength);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MaxLength, Res.Sch_MaxLengthFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MaxLength, Res.Sch_DupMaxLengthFacet);
                    try {
                        restriction.MaxLength = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MaxLengthFacetInvalid, e.Message, facet);
                    }
                    if ((thisFlags & RestrictionFlags.MaxLength) != 0) {
                        if (this.restriction.MaxLength < restriction.MaxLength) {
                            throw new XmlSchemaException(Res.Sch_MaxLengthGtBaseMaxLength, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.MaxLength);
                }
                else if (facet is XmlSchemaPatternFacet) {
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.Pattern, Res.Sch_PatternFacetProhibited);
                    if(firstP == true) {
                        regStr.Append("(");
                        regStr.Append(facet.Value);
                        pattern_facet = new XmlSchemaPatternFacet();
                        pattern_facet = facet;
                        firstP = false;
                    }
                    else {
                        regStr.Append(")|(");
                        regStr.Append(facet.Value);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.Pattern);
                }
                else if (facet is XmlSchemaEnumerationFacet) {
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.Enumeration, Res.Sch_EnumerationFacetProhibited);
                    if (restriction.Enumeration == null) {
                        restriction.Enumeration = new ArrayList();
                    }
                    try {
                        //restriction.Enumeration.Add(ParseAtomicValue(facet.Value, nameTable, nsmgr));
                        restriction.Enumeration.Add(ParseValue(facet.Value, nameTable, nsmgr));
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_EnumerationFacetInvalid, e.Message, facet);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.Enumeration);
                }
                else if (facet is XmlSchemaWhiteSpaceFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.WhiteSpace);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.WhiteSpace, Res.Sch_WhiteSpaceFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.WhiteSpace, Res.Sch_DupWhiteSpaceFacet);
                    if (facet.Value == "preserve") {
                        restriction.WhiteSpace = XmlSchemaWhiteSpace.Preserve;
                    }
                    else if (facet.Value == "replace") {
                        restriction.WhiteSpace = XmlSchemaWhiteSpace.Replace;
                    }
                    else if (facet.Value == "collapse") {
                        restriction.WhiteSpace = XmlSchemaWhiteSpace.Collapse;
                    }
                    else {
                        throw new XmlSchemaException(Res.Sch_InvalidWhiteSpace, facet.Value, facet);
                    }
                    if (IsWhitespaceCollapseFixed && (restriction.WhiteSpace != XmlSchemaWhiteSpace.Collapse)) {
                        throw new XmlSchemaException(Res.Sch_InvalidWhiteSpace, facet.Value, facet);
                    }
                    if ((thisFlags & RestrictionFlags.WhiteSpace) != 0) {
                        if (
                            this.restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse &&
                            (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace || restriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve)
                        ) {
                            throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction1, facet);
                        }
                        if (
                            this.restriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve &&
                            restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace
                        ) {
                            throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction2, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.WhiteSpace);
                }
                else if (facet is XmlSchemaMaxInclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.Length);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MaxInclusive, Res.Sch_MaxInclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MaxInclusive, Res.Sch_DupMaxInclusiveFacet);
                    try {
                        restriction.MaxInclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MaxInclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MaxInclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MaxInclusive);
                }
                else if (facet is XmlSchemaMaxExclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MaxExclusive);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MaxExclusive, Res.Sch_MaxExclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MaxExclusive, Res.Sch_DupMaxExclusiveFacet);
                    try {
                        restriction.MaxExclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MaxExclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MaxExclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MaxExclusive);
                }
                else if (facet is XmlSchemaMinInclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MinInclusive);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MinInclusive, Res.Sch_MinInclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MinInclusive, Res.Sch_DupMinInclusiveFacet);
                    try {
                        restriction.MinInclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MinInclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MinInclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MinInclusive);
                }
                else if (facet is XmlSchemaMinExclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MinExclusive);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MinExclusive, Res.Sch_MinExclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MinExclusive, Res.Sch_DupMinExclusiveFacet);
                    try {
                        restriction.MinExclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MinExclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MinExclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MinExclusive);
                }
                else if (facet is XmlSchemaTotalDigitsFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.TotalDigits);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.TotalDigits, Res.Sch_TotalDigitsFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.TotalDigits, Res.Sch_DupTotalDigitsFacet);
                    try {
                        restriction.TotalDigits = (int)(decimal)c_positiveInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_TotalDigitsFacetInvalid, e.Message, facet);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.TotalDigits);
                }
                else if (facet is XmlSchemaFractionDigitsFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.FractionDigits);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.FractionDigits, Res.Sch_FractionDigitsFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.FractionDigits, Res.Sch_DupFractionDigitsFacet);
                    try {
                        restriction.FractionDigits = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                        if ((restriction.FractionDigits != 0) && (this.GetType() != typeof(Datatype_decimal))) {
                            throw new XmlSchemaException(Res.Sch_FractionDigitsNotOnDecimal, facet);
                        }
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_FractionDigitsFacetInvalid, e.Message, facet);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.FractionDigits);
                }
                else {
                    throw new XmlSchemaException(Res.Sch_UnknownFacet, facet);
                }

            }

            //If facet is XMLSchemaPattern, then the String built inside the loop
            //needs to be converted to a RegEx

            if(firstP == false) {
                if (restriction.Patterns == null) {
                    restriction.Patterns = new ArrayList();
                }
                try {
                    regStr.Append(")");
                    string tempStr = regStr.ToString();
                    if(tempStr.IndexOf("|") != -1) {
                        regStr.Insert(0,"(");
                        regStr.Append(")");
                    }
                   restriction.Patterns.Add(new Regex(Preprocess(regStr.ToString()), RegexOptions.None));

                }catch (Exception e) {
                    throw new XmlSchemaException(Res.Sch_PatternFacetInvalid, e.Message, pattern_facet);
                }
            }

            // Copy from the base
            if (
                (restriction.Flags & RestrictionFlags.Length) == 0 &&
                (thisFlags & RestrictionFlags.Length) != 0
            ) {
                restriction.Length = this.restriction.Length;
                SetFlag(restriction, fixedFlags, RestrictionFlags.Length);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinLength) == 0 &&
                (thisFlags & RestrictionFlags.MinLength) != 0
            ) {
                restriction.MinLength = this.restriction.MinLength;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MinLength);
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxLength) == 0 &&
                (thisFlags & RestrictionFlags.MaxLength) != 0
            ) {
                restriction.MaxLength = this.restriction.MaxLength;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MaxLength);
            }
            if ((thisFlags & RestrictionFlags.Pattern) != 0) {
                if (restriction.Patterns == null) {
                    restriction.Patterns = this.restriction.Patterns;
                }
                else {
                    restriction.Patterns.AddRange(this.restriction.Patterns);
                }
                SetFlag(restriction, fixedFlags, RestrictionFlags.Pattern);
            }


            if ((thisFlags & RestrictionFlags.Enumeration) != 0) {
                if (restriction.Enumeration == null) {
                    restriction.Enumeration = this.restriction.Enumeration;
                }
                SetFlag(restriction, fixedFlags, RestrictionFlags.Enumeration);
            }

            if (
                (restriction.Flags & RestrictionFlags.WhiteSpace) == 0 &&
                (thisFlags & RestrictionFlags.WhiteSpace) != 0
            ) {
                restriction.WhiteSpace = this.restriction.WhiteSpace;
                SetFlag(restriction, fixedFlags, RestrictionFlags.WhiteSpace);
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxInclusive) == 0 &&
                (thisFlags & RestrictionFlags.MaxInclusive) != 0
            ) {
                restriction.MaxInclusive = this.restriction.MaxInclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MaxInclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxExclusive) == 0 &&
                (thisFlags & RestrictionFlags.MaxExclusive) != 0
            ) {
                restriction.MaxExclusive = this.restriction.MaxExclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MaxExclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) == 0 &&
                (thisFlags & RestrictionFlags.MinInclusive) != 0
            ) {
                restriction.MinInclusive = this.restriction.MinInclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MinInclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinExclusive) == 0 &&
                (thisFlags & RestrictionFlags.MinExclusive) != 0
            ) {
                restriction.MinExclusive = this.restriction.MinExclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MinExclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.TotalDigits) == 0 &&
                (thisFlags & RestrictionFlags.TotalDigits) != 0
            ) {
                restriction.MinExclusive = this.restriction.TotalDigits;
                SetFlag(restriction, fixedFlags, RestrictionFlags.TotalDigits);
            }
            if (
                (restriction.Flags & RestrictionFlags.FractionDigits) == 0 &&
                (thisFlags & RestrictionFlags.FractionDigits) != 0
            ) {
                restriction.FractionDigits = this.restriction.FractionDigits;
                SetFlag(restriction, fixedFlags, RestrictionFlags.FractionDigits);
            }

            // Check combinations
            if (
                (restriction.Flags & RestrictionFlags.Length) != 0 &&
                (restriction.Flags & (RestrictionFlags.MinLength|RestrictionFlags.MaxLength)) != 0
            ) {
                throw new XmlSchemaException(Res.Sch_LengthAndMinMax);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinLength) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxLength) != 0
            ) {
                if (restriction.MinLength > restriction.MaxLength) {
                    throw new XmlSchemaException(Res.Sch_MinLengthGtMaxLength);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxExclusive) != 0
            ) {
                throw new XmlSchemaException(Res.Sch_MaxInclusiveExclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MinExclusive) != 0
            ) {
                throw new XmlSchemaException(Res.Sch_MinInclusiveExclusive);
            }

            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxInclusive) != 0
            ) {
                if (Compare(restriction.MinInclusive, restriction.MaxInclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinInclusiveGtMaxInclusive);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxExclusive) != 0
            ) {
                if (Compare(restriction.MinInclusive, restriction.MaxExclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinInclusiveGtMaxExclusive);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MinExclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxExclusive) != 0
            ) {
                if (Compare(restriction.MinExclusive, restriction.MaxExclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinExclusiveGtMaxExclusive);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MinExclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxInclusive) != 0
            ) {
                if (Compare(restriction.MinExclusive, restriction.MaxInclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinExclusiveGtMaxInclusive);
                }
            }
            if ((restriction.Flags & (RestrictionFlags.TotalDigits|RestrictionFlags.FractionDigits)) == (RestrictionFlags.TotalDigits|RestrictionFlags.FractionDigits)) {
                if (restriction.FractionDigits > restriction.TotalDigits) {
                    throw new XmlSchemaException(Res.Sch_FractionDigitsGtTotalDigits);
                }
            }
            return restriction;
        }
コード例 #21
0
        private void ConstrainList(RestrictionFacets restriction, ArrayList values) {
            RestrictionFlags flags = restriction.Flags;
            if ((flags & (RestrictionFlags.Length|RestrictionFlags.MinLength|RestrictionFlags.MaxLength)) != 0) {
                int length = values.Count;
                if ((flags & RestrictionFlags.Length) != 0) {
                    if (restriction.Length != length) {
                        throw new XmlSchemaException(Res.Sch_LengthConstraintFailed);
                    }
                }

                if ((flags & RestrictionFlags.MinLength) != 0) {
                    if (length < restriction.MinLength) {
                        throw new XmlSchemaException(Res.Sch_MinLengthConstraintFailed);
                    }
                }

                if ((flags & RestrictionFlags.MaxLength) != 0) {
                    if (restriction.MaxLength < length) {
                        throw new XmlSchemaException(Res.Sch_MaxLengthConstraintFailed);
                    }
                }
            }
            if ((flags & RestrictionFlags.Enumeration) != 0) {
                bool valid = false;
                foreach(Array correctArray in restriction.Enumeration) {
                      if(MatchEnumerationList(values, correctArray)) {
                           valid = true;
                           break;
                        }
                }
                if(!valid) {
                     throw new XmlSchemaException(Res.Sch_EnumerationConstraintFailed);
                }
            }
        }
コード例 #22
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;
                }
            }
コード例 #23
0
            private void CopyFacetsFromBaseType()
            {
                RestrictionFacets restriction = this.datatype.Restriction;

                if (((this.derivedRestriction.Flags & RestrictionFlags.Length) == 0) && ((this.baseFlags & RestrictionFlags.Length) != 0))
                {
                    this.derivedRestriction.Length = restriction.Length;
                    this.SetFlag(RestrictionFlags.Length);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MinLength) == 0) && ((this.baseFlags & RestrictionFlags.MinLength) != 0))
                {
                    this.derivedRestriction.MinLength = restriction.MinLength;
                    this.SetFlag(RestrictionFlags.MinLength);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MaxLength) == 0) && ((this.baseFlags & RestrictionFlags.MaxLength) != 0))
                {
                    this.derivedRestriction.MaxLength = restriction.MaxLength;
                    this.SetFlag(RestrictionFlags.MaxLength);
                }
                if ((this.baseFlags & RestrictionFlags.Pattern) != 0)
                {
                    if (this.derivedRestriction.Patterns == null)
                    {
                        this.derivedRestriction.Patterns = restriction.Patterns;
                    }
                    else
                    {
                        this.derivedRestriction.Patterns.AddRange(restriction.Patterns);
                    }
                    this.SetFlag(RestrictionFlags.Pattern);
                }
                if ((this.baseFlags & RestrictionFlags.Enumeration) != 0)
                {
                    if (this.derivedRestriction.Enumeration == null)
                    {
                        this.derivedRestriction.Enumeration = restriction.Enumeration;
                    }
                    this.SetFlag(RestrictionFlags.Enumeration);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.WhiteSpace) == 0) && ((this.baseFlags & RestrictionFlags.WhiteSpace) != 0))
                {
                    this.derivedRestriction.WhiteSpace = restriction.WhiteSpace;
                    this.SetFlag(RestrictionFlags.WhiteSpace);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MaxInclusive) == 0) && ((this.baseFlags & RestrictionFlags.MaxInclusive) != 0))
                {
                    this.derivedRestriction.MaxInclusive = restriction.MaxInclusive;
                    this.SetFlag(RestrictionFlags.MaxInclusive);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MaxExclusive) == 0) && ((this.baseFlags & RestrictionFlags.MaxExclusive) != 0))
                {
                    this.derivedRestriction.MaxExclusive = restriction.MaxExclusive;
                    this.SetFlag(RestrictionFlags.MaxExclusive);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MinInclusive) == 0) && ((this.baseFlags & RestrictionFlags.MinInclusive) != 0))
                {
                    this.derivedRestriction.MinInclusive = restriction.MinInclusive;
                    this.SetFlag(RestrictionFlags.MinInclusive);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.MinExclusive) == 0) && ((this.baseFlags & RestrictionFlags.MinExclusive) != 0))
                {
                    this.derivedRestriction.MinExclusive = restriction.MinExclusive;
                    this.SetFlag(RestrictionFlags.MinExclusive);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.TotalDigits) == 0) && ((this.baseFlags & RestrictionFlags.TotalDigits) != 0))
                {
                    this.derivedRestriction.TotalDigits = restriction.TotalDigits;
                    this.SetFlag(RestrictionFlags.TotalDigits);
                }
                if (((this.derivedRestriction.Flags & RestrictionFlags.FractionDigits) == 0) && ((this.baseFlags & RestrictionFlags.FractionDigits) != 0))
                {
                    this.derivedRestriction.FractionDigits = restriction.FractionDigits;
                    this.SetFlag(RestrictionFlags.FractionDigits);
                }
            }
コード例 #24
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern = true;
     this.regStr = null;
     this.pattern_facet = null;
     this.datatype = baseDatatype;
     this.derivedRestriction = restriction;
     this.baseFlags = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags) 0);
     this.baseFixedFlags = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags) 0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
コード例 #25
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;
        }
コード例 #26
0
ファイル: FacetChecker.cs プロジェクト: uQr/referencesource
        //Compile-time Facet Checking
        internal virtual RestrictionFacets ConstructRestriction(DatatypeImplementation datatype, XmlSchemaObjectCollection facets, XmlNameTable nameTable) {
            //Datatype is the type on which this method is called
            RestrictionFacets derivedRestriction = new RestrictionFacets();
            FacetsCompiler facetCompiler = new FacetsCompiler(datatype, derivedRestriction);

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

                    case FacetType.MinLength:
                        facetCompiler.CompileMinLengthFacet(facet);
                    break;

                    case FacetType.MaxLength:
                        facetCompiler.CompileMaxLengthFacet(facet);
                    break;
    
                    case FacetType.Pattern:
                        facetCompiler.CompilePatternFacet(facet as XmlSchemaPatternFacet);
                    break;

                    case FacetType.Enumeration:
                        facetCompiler.CompileEnumerationFacet(facet, nsmgr, nameTable);                        
                    break;

                    case FacetType.Whitespace:
                        facetCompiler.CompileWhitespaceFacet(facet);
                    break;

                    case FacetType.MinInclusive:
                        facetCompiler.CompileMinInclusiveFacet(facet);
                    break;

                    case FacetType.MinExclusive:
                        facetCompiler.CompileMinExclusiveFacet(facet);
                    break;

                    case FacetType.MaxInclusive:
                        facetCompiler.CompileMaxInclusiveFacet(facet);
                    break;

                    case FacetType.MaxExclusive:
                        facetCompiler.CompileMaxExclusiveFacet(facet);
                    break;

                    case FacetType.TotalDigits:
                        facetCompiler.CompileTotalDigitsFacet(facet);
                    break;

                    case FacetType.FractionDigits:
                        facetCompiler.CompileFractionDigitsFacet(facet);
                    break;

                    default:
                        throw new XmlSchemaException(Res.Sch_UnknownFacet, facet);
                }
            }
            facetCompiler.FinishFacetCompile();
            facetCompiler.CompileFacetCombinations();
            return derivedRestriction;
        }
コード例 #27
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);
        }