internal virtual Exception CheckLexicalFacets(ref string parsedString, object value, NameTable nameTable, XNamespaceResolver resolver, SimpleTypeValidator type) { RestrictionFacets facets = type.RestrictionFacets; if (facets == null || !facets.HasLexicalFacets) { return(null); } RestrictionFlags flags = facets.Flags; XmlSchemaWhiteSpace wsPattern = XmlSchemaWhiteSpace.Collapse; if ((flags & RestrictionFlags.WhiteSpace) != 0) { if (facets.WhiteSpace == XmlSchemaWhiteSpace.Collapse) { wsPattern = XmlSchemaWhiteSpace.Collapse; } else if (facets.WhiteSpace == XmlSchemaWhiteSpace.Preserve) { wsPattern = XmlSchemaWhiteSpace.Preserve; } } return(CheckLexicalFacets(ref parsedString, type, facets.Patterns, wsPattern)); }
internal virtual Exception CheckLexicalFacets(ref string parsedString, SimpleTypeValidator type, ArrayList patterns, XmlSchemaWhiteSpace wsPattern) { CheckWhitespaceFacets(ref parsedString, type, wsPattern); return(CheckPatternFacets(patterns, parsedString)); }
internal void CheckWhitespaceFacets(ref string s, SimpleTypeValidator type, XmlSchemaWhiteSpace wsPattern) { // before parsing, check whitespace facet RestrictionFacets restriction = type.RestrictionFacets; if (type.Variety == XmlSchemaDatatypeVariety.List) { s = s.Trim(); return; } else if (type.Variety == XmlSchemaDatatypeVariety.Atomic) { XmlSchemaDatatype datatype = type.DataType; if (datatype.GetBuiltInWSFacet() == XmlSchemaWhiteSpace.Collapse) { s = XmlComplianceUtil.NonCDataNormalize(s); } else if (datatype.GetBuiltInWSFacet() == XmlSchemaWhiteSpace.Replace) { s = XmlComplianceUtil.CDataNormalize(s); } else if (restriction != null & (restriction.Flags & RestrictionFlags.WhiteSpace) != 0) { //Restriction has whitespace facet specified if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace) { s = XmlComplianceUtil.CDataNormalize(s); } else if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse) { s = XmlComplianceUtil.NonCDataNormalize(s); } } } return; }
public RestrictionFacets(RestrictionFlags flags, object[] enumeration, int fractionDigits, int length, object maxExclusive, object maxInclusive, int maxLength, object minExclusive, object minInclusive, int minLength, string[] patterns, int totalDigits, XmlSchemaWhiteSpace whiteSpace) { hasValueFacets = false; hasLexicalFacets = false; if ((flags & RestrictionFlags.Enumeration) != 0) { this.Enumeration = new ArrayList(); foreach(object o in enumeration) { this.Enumeration.Add(o); } hasValueFacets = true; } if ((flags & RestrictionFlags.FractionDigits) != 0) { this.FractionDigits = fractionDigits; hasValueFacets = true; } if ((flags & RestrictionFlags.Length) != 0) { this.Length = length; hasValueFacets = true; } if ((flags & RestrictionFlags.MaxExclusive) != 0) { this.MaxExclusive = maxExclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MaxInclusive) != 0) { this.MaxInclusive = maxInclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MaxLength) != 0) { this.MaxLength = maxLength; hasValueFacets = true; } if ((flags & RestrictionFlags.MinExclusive) != 0) { this.MinExclusive = minExclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MinInclusive) != 0) { this.MinInclusive = minInclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MinLength) != 0) { this.MinLength = minLength; hasValueFacets = true; } if ((flags & RestrictionFlags.Pattern) != 0) { CompilePatterns(patterns); hasLexicalFacets = true; } if ((flags & RestrictionFlags.TotalDigits) != 0) { this.TotalDigits = totalDigits; hasValueFacets = true; } if ((flags & RestrictionFlags.WhiteSpace) != 0) { hasLexicalFacets = true; this.WhiteSpace = whiteSpace; } this.Flags = flags; }
internal void CheckWhitespaceFacets(ref string s, SimpleTypeValidator type, XmlSchemaWhiteSpace wsPattern) { // before parsing, check whitespace facet RestrictionFacets restriction = type.RestrictionFacets; if (type.Variety == XmlSchemaDatatypeVariety.List) { s = s.Trim(); return; } else if (type.Variety == XmlSchemaDatatypeVariety.Atomic) { XmlSchemaDatatype datatype = type.DataType; if (datatype.GetBuiltInWSFacet() == XmlSchemaWhiteSpace.Collapse) { s = XmlComplianceUtil.NonCDataNormalize(s); } else if (datatype.GetBuiltInWSFacet() == XmlSchemaWhiteSpace.Replace) { s = XmlComplianceUtil.CDataNormalize(s); } else if (restriction != null & (restriction.Flags & RestrictionFlags.WhiteSpace) != 0) { //Restriction has whitespace facet specified if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace) { s = XmlComplianceUtil.CDataNormalize(s); } else if (restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse) { s = XmlComplianceUtil.NonCDataNormalize(s); } } } return; }
internal virtual Exception CheckLexicalFacets(ref string parsedString, SimpleTypeValidator type, ArrayList patterns, XmlSchemaWhiteSpace wsPattern) { CheckWhitespaceFacets(ref parsedString, type, wsPattern); return CheckPatternFacets(patterns, parsedString); }
public static CodeExpression CreateFacets(ClrSimpleTypeInfo type) { CompiledFacets facets = type.RestrictionFacets; CodeObjectCreateExpression createFacets = new CodeObjectCreateExpression(); createFacets.CreateType = new CodeTypeReference(Constants.RestrictionFacets); RestrictionFlags flags = facets.Flags; if (flags == 0) { return(new CodePrimitiveExpression(null)); } else { CodeCastExpression cast = new CodeCastExpression(new CodeTypeReference(Constants.RestrictionFlags), new CodePrimitiveExpression( System.Convert.ToInt32(flags, CultureInfo.InvariantCulture.NumberFormat))); createFacets.Parameters.Add(cast); } if ((flags & RestrictionFlags.Enumeration) != 0) { CodeArrayCreateExpression enums = new CodeArrayCreateExpression(); enums.CreateType = new CodeTypeReference("System.Object"); foreach (object o in facets.Enumeration) { GetCreateValueExpression(o, type, enums.Initializers); } createFacets.Parameters.Add(enums); } else { createFacets.Parameters.Add(new CodePrimitiveExpression(null)); } int fractionDigits = default(int); if ((flags & RestrictionFlags.FractionDigits) != 0) { fractionDigits = facets.FractionDigits; } createFacets.Parameters.Add(new CodePrimitiveExpression(fractionDigits)); int length = default(int); if ((flags & RestrictionFlags.Length) != 0) { length = facets.Length; } createFacets.Parameters.Add(new CodePrimitiveExpression(length)); object maxExclusive = default(object); if ((flags & RestrictionFlags.MaxExclusive) != 0) { maxExclusive = facets.MaxExclusive; } GetCreateValueExpression(maxExclusive, type, createFacets.Parameters); object maxInclusive = default(object); if ((flags & RestrictionFlags.MaxInclusive) != 0) { maxInclusive = facets.MaxInclusive; } GetCreateValueExpression(maxInclusive, type, createFacets.Parameters); int maxLength = default(int); if ((flags & RestrictionFlags.MaxLength) != 0) { maxLength = facets.MaxLength; } createFacets.Parameters.Add(new CodePrimitiveExpression(maxLength)); object minExclusive = default(object); if ((flags & RestrictionFlags.MinExclusive) != 0) { minExclusive = facets.MinExclusive; } GetCreateValueExpression(minExclusive, type, createFacets.Parameters); object minInclusive = default(object); if ((flags & RestrictionFlags.MinInclusive) != 0) { minInclusive = facets.MinInclusive; } GetCreateValueExpression(minInclusive, type, createFacets.Parameters); int minLength = default(int); if ((flags & RestrictionFlags.MinLength) != 0) { minLength = facets.MinLength; } createFacets.Parameters.Add(new CodePrimitiveExpression(minLength)); if ((flags & RestrictionFlags.Pattern) != 0) { CodeArrayCreateExpression patternStrs = new CodeArrayCreateExpression(); patternStrs.CreateType = new CodeTypeReference(XTypedServices.typeOfString); foreach (object o in facets.Patterns) { string str = o.ToString(); patternStrs.Initializers.Add(new CodePrimitiveExpression(str)); } createFacets.Parameters.Add(patternStrs); } else { createFacets.Parameters.Add(new CodePrimitiveExpression(null)); } int totalDigits = default(int); if ((flags & RestrictionFlags.TotalDigits) != 0) { totalDigits = facets.TotalDigits; } createFacets.Parameters.Add(new CodePrimitiveExpression(totalDigits)); XmlSchemaWhiteSpace ws = facets.WhiteSpace; createFacets.Parameters.Add( CodeDomHelper.CreateFieldReference(Constants.XmlSchemaWhiteSpace, ws.ToString())); return(createFacets); }
public void compileFacets(XmlSchemaSimpleType simpleType) { XmlSchemaSimpleType type = simpleType; XmlSchemaSimpleType enumSimpleType = null; //simpletype that has most restricted enums. flags = 0; while (type != null && !String.Equals(type.QualifiedName.Namespace, Constants.XSD, StringComparison.Ordinal)) { XmlSchemaSimpleTypeRestriction simpleTypeRestriction = type.Content as XmlSchemaSimpleTypeRestriction; if (simpleTypeRestriction != null) { foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets) { if (facet is XmlSchemaMinLengthFacet) { if ((flags & RestrictionFlags.MinLength) == 0) { minLength = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.MinLength; } } else if (facet is XmlSchemaMaxLengthFacet) { if ((flags & RestrictionFlags.MaxLength) == 0) { maxLength = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.MaxLength; } } else if (facet is XmlSchemaLengthFacet) { if ((flags & RestrictionFlags.Length) == 0) { length = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.Length; } } else if (facet is XmlSchemaEnumerationFacet) { if (enumSimpleType == null) { enumerations = new ArrayList(); flags |= RestrictionFlags.Enumeration; enumSimpleType = type; } else if (enumSimpleType != type) { continue; } enumerations.Add(type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null)); } else if (facet is XmlSchemaPatternFacet) { if (patterns == null) { patterns = new ArrayList(); flags |= RestrictionFlags.Pattern; } patterns.Add(facet.Value); } else if (facet is XmlSchemaMaxInclusiveFacet) { if ((flags & RestrictionFlags.MaxInclusive) == 0) { maxInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MaxInclusive; } } else if (facet is XmlSchemaMaxExclusiveFacet) { if ((flags & RestrictionFlags.MaxExclusive) == 0) { maxExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MaxExclusive; } } else if (facet is XmlSchemaMinExclusiveFacet) { if ((flags & RestrictionFlags.MinExclusive) == 0) { minExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MinExclusive; } } else if (facet is XmlSchemaMinInclusiveFacet) { if ((flags & RestrictionFlags.MinInclusive) == 0) { minInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MinInclusive; } } else if (facet is XmlSchemaFractionDigitsFacet) { if ((flags & RestrictionFlags.FractionDigits) == 0) { fractionDigits = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.FractionDigits; } } else if (facet is XmlSchemaTotalDigitsFacet) { if ((flags & RestrictionFlags.TotalDigits) == 0) { totalDigits = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.TotalDigits; } } else if (facet is XmlSchemaWhiteSpaceFacet) { if ((flags & RestrictionFlags.WhiteSpace) == 0) { if (facet.Value == "preserve") { whiteSpace = XmlSchemaWhiteSpace.Preserve; } else if (facet.Value == "replace") { whiteSpace = XmlSchemaWhiteSpace.Replace; } else if (facet.Value == "collapse") { whiteSpace = XmlSchemaWhiteSpace.Collapse; } flags |= RestrictionFlags.WhiteSpace; } } else { continue; } } } type = type.BaseXmlSchemaType as XmlSchemaSimpleType; } }
public CompiledFacets(XmlSchemaDatatype dt) { whiteSpace = dt.GetBuiltInWSFacet(); }
public RestrictionFacets(RestrictionFlags flags, object[] enumeration, int fractionDigits, int length, object maxExclusive, object maxInclusive, int maxLength, object minExclusive, object minInclusive, int minLength, string[] patterns, int totalDigits, XmlSchemaWhiteSpace whiteSpace) { this.hasValueFacets = false; this.hasLexicalFacets = false; if ((int)(flags & RestrictionFlags.Enumeration) != 0) { this.Enumeration = new ArrayList(); object[] objArray = enumeration; for (int i = 0; i < (int)objArray.Length; i++) { object o = objArray[i]; this.Enumeration.Add(o); } this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.FractionDigits) != 0) { this.FractionDigits = fractionDigits; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.Length) != 0) { this.Length = length; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.MaxExclusive) != 0) { this.MaxExclusive = maxExclusive; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.MaxInclusive) != 0) { this.MaxInclusive = maxInclusive; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.MaxLength) != 0) { this.MaxLength = maxLength; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.MinExclusive) != 0) { this.MinExclusive = minExclusive; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.MinInclusive) != 0) { this.MinInclusive = minInclusive; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.MinLength) != 0) { this.MinLength = minLength; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.Pattern) != 0) { this.CompilePatterns(patterns); this.hasLexicalFacets = true; } if ((int)(flags & RestrictionFlags.TotalDigits) != 0) { this.TotalDigits = totalDigits; this.hasValueFacets = true; } if ((int)(flags & RestrictionFlags.WhiteSpace) != 0) { this.hasLexicalFacets = true; this.WhiteSpace = whiteSpace; } this.Flags = flags; }
public CompiledFacets(XmlSchemaDatatype dt) { whiteSpace = dt.GetBuiltInWSFacet(); }
public void compileFacets(XmlSchemaSimpleType simpleType) { XmlSchemaSimpleType type = simpleType; XmlSchemaSimpleType enumSimpleType = null; //simpletype that has most restricted enums. flags = 0; while (type != null && !String.Equals(type.QualifiedName.Namespace, Constants.XSD, StringComparison.Ordinal)) { XmlSchemaSimpleTypeRestriction simpleTypeRestriction = type.Content as XmlSchemaSimpleTypeRestriction; if (simpleTypeRestriction != null) { foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets) { if (facet is XmlSchemaMinLengthFacet) { if ((flags & RestrictionFlags.MinLength) == 0) { minLength = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.MinLength; } } else if (facet is XmlSchemaMaxLengthFacet) { if ((flags & RestrictionFlags.MaxLength) == 0) { maxLength = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.MaxLength; } } else if (facet is XmlSchemaLengthFacet) { if ((flags & RestrictionFlags.Length) == 0) { length = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.Length; } } else if (facet is XmlSchemaEnumerationFacet) { if (enumSimpleType == null) { enumerations = new ArrayList(); flags |= RestrictionFlags.Enumeration; enumSimpleType = type; } else if (enumSimpleType != type) { continue; } enumerations.Add(type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null)); } else if (facet is XmlSchemaPatternFacet) { if (patterns == null) { patterns = new ArrayList(); flags |= RestrictionFlags.Pattern; } patterns.Add(facet.Value); } else if (facet is XmlSchemaMaxInclusiveFacet) { if ((flags & RestrictionFlags.MaxInclusive) == 0) { maxInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MaxInclusive; } } else if (facet is XmlSchemaMaxExclusiveFacet) { if ((flags & RestrictionFlags.MaxExclusive) == 0) { maxExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MaxExclusive; } } else if (facet is XmlSchemaMinExclusiveFacet) { if ((flags & RestrictionFlags.MinExclusive) == 0) { minExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MinExclusive; } } else if (facet is XmlSchemaMinInclusiveFacet) { if ((flags & RestrictionFlags.MinInclusive) == 0) { minInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null); flags |= RestrictionFlags.MinInclusive; } } else if (facet is XmlSchemaFractionDigitsFacet) { if ((flags & RestrictionFlags.FractionDigits) == 0) { fractionDigits = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.FractionDigits; } } else if (facet is XmlSchemaTotalDigitsFacet) { if ((flags & RestrictionFlags.TotalDigits) == 0) { totalDigits = XmlConvert.ToInt32(facet.Value); flags |= RestrictionFlags.TotalDigits; } } else if (facet is XmlSchemaWhiteSpaceFacet) { if ((flags & RestrictionFlags.WhiteSpace) == 0) { if (facet.Value == "preserve") { whiteSpace = XmlSchemaWhiteSpace.Preserve; } else if (facet.Value == "replace") { whiteSpace = XmlSchemaWhiteSpace.Replace; } else if (facet.Value == "collapse") { whiteSpace = XmlSchemaWhiteSpace.Collapse; } flags |= RestrictionFlags.WhiteSpace; } } else { continue; } } } type = type.BaseXmlSchemaType as XmlSchemaSimpleType; } }
public RestrictionFacets(RestrictionFlags flags, object[] enumeration, int fractionDigits, int length, object maxExclusive, object maxInclusive, int maxLength, object minExclusive, object minInclusive, int minLength, string[] patterns, int totalDigits, XmlSchemaWhiteSpace whiteSpace) { hasValueFacets = false; hasLexicalFacets = false; if ((flags & RestrictionFlags.Enumeration) != 0) { this.Enumeration = new ArrayList(); foreach (object o in enumeration) { this.Enumeration.Add(o); } hasValueFacets = true; } if ((flags & RestrictionFlags.FractionDigits) != 0) { this.FractionDigits = fractionDigits; hasValueFacets = true; } if ((flags & RestrictionFlags.Length) != 0) { this.Length = length; hasValueFacets = true; } if ((flags & RestrictionFlags.MaxExclusive) != 0) { this.MaxExclusive = maxExclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MaxInclusive) != 0) { this.MaxInclusive = maxInclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MaxLength) != 0) { this.MaxLength = maxLength; hasValueFacets = true; } if ((flags & RestrictionFlags.MinExclusive) != 0) { this.MinExclusive = minExclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MinInclusive) != 0) { this.MinInclusive = minInclusive; hasValueFacets = true; } if ((flags & RestrictionFlags.MinLength) != 0) { this.MinLength = minLength; hasValueFacets = true; } if ((flags & RestrictionFlags.Pattern) != 0) { CompilePatterns(patterns); hasLexicalFacets = true; } if ((flags & RestrictionFlags.TotalDigits) != 0) { this.TotalDigits = totalDigits; hasValueFacets = true; } if ((flags & RestrictionFlags.WhiteSpace) != 0) { hasLexicalFacets = true; this.WhiteSpace = whiteSpace; } this.Flags = flags; }