Inheritance: XmlNamespaceManager
Exemple #1
0
        //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;
        }
 private void CompileIdentityConstraint(XmlSchemaIdentityConstraint xi)
 {
     if (xi.IsProcessing)
     {
         xi.CompiledConstraint = CompiledIdentityConstraint.Empty;
         base.SendValidationEvent("Sch_IdentityConstraintCircularRef", xi);
     }
     else if (xi.CompiledConstraint == null)
     {
         xi.IsProcessing = true;
         CompiledIdentityConstraint constraint = null;
         try
         {
             SchemaNamespaceManager nsmgr = new SchemaNamespaceManager(xi);
             constraint = new CompiledIdentityConstraint(xi, nsmgr);
             if (xi is XmlSchemaKeyref)
             {
                 XmlSchemaIdentityConstraint constraint2 = (XmlSchemaIdentityConstraint) this.schema.IdentityConstraints[((XmlSchemaKeyref) xi).Refer];
                 if (constraint2 == null)
                 {
                     throw new XmlSchemaException("Sch_UndeclaredIdentityConstraint", ((XmlSchemaKeyref) xi).Refer.ToString(), xi);
                 }
                 this.CompileIdentityConstraint(constraint2);
                 if (constraint2.CompiledConstraint == null)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidIdentityConstraint", ((XmlSchemaKeyref) xi).Refer.ToString(), xi);
                 }
                 if (constraint2.Fields.Count != xi.Fields.Count)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidCardin", xi.QualifiedName.ToString(), xi);
                 }
                 if (constraint2.CompiledConstraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref)
                 {
                     throw new XmlSchemaException("Sch_ReftoKeyref", xi.QualifiedName.ToString(), xi);
                 }
             }
             xi.CompiledConstraint = constraint;
         }
         catch (XmlSchemaException exception)
         {
             if (exception.SourceSchemaObject == null)
             {
                 exception.SetSource(xi);
             }
             base.SendValidationEvent(exception);
             xi.CompiledConstraint = CompiledIdentityConstraint.Empty;
         }
         finally
         {
             xi.IsProcessing = false;
         }
     }
 }
        private void CompileIdentityConstraint (XmlSchemaIdentityConstraint xi) { 
            if (xi.IsProcessing) {
                xi.CompiledConstraint = CompiledIdentityConstraint.Empty;       
                SendValidationEvent(Res.Sch_IdentityConstraintCircularRef, xi);
                return;
            }

            if (xi.CompiledConstraint != null) {
                return;
            }
            
            xi.IsProcessing = true;
            CompiledIdentityConstraint compic = null;
            try {
                SchemaNamespaceManager xnmgr = new SchemaNamespaceManager(xi);
                compic = new CompiledIdentityConstraint(xi, xnmgr);
                if (xi is XmlSchemaKeyref) {
                    XmlSchemaIdentityConstraint ic = (XmlSchemaIdentityConstraint)this.identityConstraints[((XmlSchemaKeyref)xi).Refer];
                    if (ic == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredIdentityConstraint, ((XmlSchemaKeyref)xi).Refer.ToString(), xi);
                    }     
                    CompileIdentityConstraint(ic);
                    if (ic.CompiledConstraint == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidIdentityConstraint, ((XmlSchemaKeyref)xi).Refer.ToString(), xi);
                    }
                    // keyref has the different cardinality with the key it referred
                    if (ic.Fields.Count != xi.Fields.Count) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidCardin, xi.QualifiedName.ToString(), xi);
                    }
                    // keyref can only refer to key/unique
                    if (ic.CompiledConstraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref) {
                        throw new XmlSchemaException(Res.Sch_ReftoKeyref, xi.QualifiedName.ToString(), xi);
                    }
                }
                xi.CompiledConstraint = compic;
            }
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xi);
                }
                SendValidationEvent(e);
                xi.CompiledConstraint = CompiledIdentityConstraint.Empty;       
                // empty is better than null here, stop quickly when circle referencing
            } 
            finally {
                xi.IsProcessing = false;
            }

        }
        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;
        }
        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;
        }
Exemple #6
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);
        }