private SimpleType(SerializationInfo info, StreamingContext context) { this.name = ""; this.length = -1; this.minLength = -1; this.maxLength = -1; this.pattern = ""; this.ns = ""; this.maxExclusive = ""; this.maxInclusive = ""; this.minExclusive = ""; this.minInclusive = ""; this.enumeration = ""; this.baseType = info.GetString("SimpleType.BaseType"); this.baseSimpleType = (SimpleType) info.GetValue("SimpleType.BaseSimpleType", typeof(SimpleType)); if (info.GetBoolean("SimpleType.XmlBaseType.XmlQualifiedNameExists")) { string name = info.GetString("SimpleType.XmlBaseType.Name"); string ns = info.GetString("SimpleType.XmlBaseType.Namespace"); this.xmlBaseType = new XmlQualifiedName(name, ns); } else { this.xmlBaseType = null; } this.name = info.GetString("SimpleType.Name"); this.ns = info.GetString("SimpleType.NS"); this.maxLength = info.GetInt32("SimpleType.MaxLength"); this.length = info.GetInt32("SimpleType.Length"); }
private SimpleType(SerializationInfo info, StreamingContext context) { this.baseType = info.GetString("SimpleType.BaseType"); this.baseSimpleType = (SimpleType)info.GetValue("SimpleType.BaseSimpleType", typeof(SimpleType)); if (info.GetBoolean("SimpleType.XmlBaseType.XmlQualifiedNameExists")) { string xmlQNName = info.GetString("SimpleType.XmlBaseType.Name"); string xmlQNNamespace = info.GetString("SimpleType.XmlBaseType.Namespace"); this.xmlBaseType = new XmlQualifiedName(xmlQNName, xmlQNNamespace); } else { this.xmlBaseType = null; } this.name = info.GetString("SimpleType.Name"); this.ns = info.GetString("SimpleType.NS"); this.maxLength = info.GetInt32("SimpleType.MaxLength"); this.length = info.GetInt32("SimpleType.Length"); }
private Type ParseDataType(string dt) { if (IsXsdType(dt) || (this.udSimpleTypes == null)) { return FindNameType(dt).type; } XmlSchemaSimpleType node = (XmlSchemaSimpleType) this.udSimpleTypes[dt]; if (node == null) { throw ExceptionBuilder.UndefinedDatatype(dt); } SimpleType baseSimpleType = new SimpleType(node); while (baseSimpleType.BaseSimpleType != null) { baseSimpleType = baseSimpleType.BaseSimpleType; } return this.ParseDataType(baseSimpleType.BaseType); }
internal void LoadTypeValues(XmlSchemaSimpleType node) { if ((node.Content is XmlSchemaSimpleTypeList) || (node.Content is XmlSchemaSimpleTypeUnion)) throw ExceptionBuilder.SimpleTypeNotSupported(); if (node.Content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)node.Content; XmlSchemaSimpleType ancestor = node.BaseXmlSchemaType as XmlSchemaSimpleType; if ((ancestor != null) && (ancestor.QualifiedName.Namespace != Keywords.XSDNS)) { _baseSimpleType = new SimpleType(node.BaseXmlSchemaType as XmlSchemaSimpleType); } // do we need to put qualified name? // for user defined simpletype, always go with qname if (content.BaseTypeName.Namespace == Keywords.XSDNS) _baseType = content.BaseTypeName.Name; else _baseType = content.BaseTypeName.ToString(); if (_baseSimpleType != null && _baseSimpleType.Name != null && _baseSimpleType.Name.Length > 0) { _xmlBaseType = _baseSimpleType.XmlBaseType;// SimpleTypeQualifiedName; } else { _xmlBaseType = content.BaseTypeName; } if (_baseType == null || _baseType.Length == 0) { _baseType = content.BaseType.Name; _xmlBaseType = null; } if (_baseType == "NOTATION") _baseType = "string"; foreach (XmlSchemaFacet facet in content.Facets) { if (facet is XmlSchemaLengthFacet) _length = Convert.ToInt32(facet.Value, null); if (facet is XmlSchemaMinLengthFacet) _minLength = Convert.ToInt32(facet.Value, null); if (facet is XmlSchemaMaxLengthFacet) _maxLength = Convert.ToInt32(facet.Value, null); if (facet is XmlSchemaPatternFacet) _pattern = facet.Value; if (facet is XmlSchemaEnumerationFacet) _enumeration = !string.IsNullOrEmpty(_enumeration) ? _enumeration + " " + facet.Value : facet.Value; if (facet is XmlSchemaMinExclusiveFacet) _minExclusive = facet.Value; if (facet is XmlSchemaMinInclusiveFacet) _minInclusive = facet.Value; if (facet is XmlSchemaMaxExclusiveFacet) _maxExclusive = facet.Value; if (facet is XmlSchemaMaxInclusiveFacet) _maxInclusive = facet.Value; } } string tempStr = XSDSchema.GetMsdataAttribute(node, Keywords.TARGETNAMESPACE); if (tempStr != null) _ns = tempStr; }
// Assumption is otherSimpleType and current ST name and NS matches. // if existing simpletype is being redefined with different facets, then it will return no-empty string defining the error internal string HasConflictingDefinition(SimpleType otherSimpleType) { if (otherSimpleType == null) return nameof(otherSimpleType); if (MaxLength != otherSimpleType.MaxLength) return ("MaxLength"); if (!string.Equals(BaseType, otherSimpleType.BaseType, StringComparison.Ordinal)) return ("BaseType"); if ((BaseSimpleType == null && otherSimpleType.BaseSimpleType != null) && (BaseSimpleType.HasConflictingDefinition(otherSimpleType.BaseSimpleType)).Length != 0) return ("BaseSimpleType"); return string.Empty; }
internal static SimpleType CreateByteArrayType(string encoding) { SimpleType byteArrayType = new SimpleType("base64Binary"); return byteArrayType; }
internal void HandleElementColumn(XmlSchemaElement elem, DataTable table, bool isBase){ Type type = null; XmlSchemaElement el = elem.Name != null ? elem : (XmlSchemaElement) elementsTable[elem.RefName]; if (el == null) // it's possible due to some XSD compiler optimizations return; // do nothing XmlSchemaAnnotated typeNode = FindTypeNode(el); String strType = null; SimpleType xsdType = null; if (typeNode == null) { strType = el.SchemaTypeName.Name; if (Common.ADP.IsEmpty(strType)) { strType = ""; type = typeof(string); } else { type = ParseDataType(el.SchemaTypeName.Name); } } else if (typeNode is XmlSchemaSimpleType) { // XmlSchemaSimpleType simpleTypeNode = typeNode as XmlSchemaSimpleType; xsdType = new SimpleType(simpleTypeNode); // ((XmlSchemaSimpleType)typeNode).Name != null && ((XmlSchemaSimpleType)typeNode).Name.Length != 0 check is for annonymos simple type, // it should be user defined Named simple type if (((XmlSchemaSimpleType)typeNode).Name != null && ((XmlSchemaSimpleType)typeNode).Name.Length != 0 && ((XmlSchemaSimpleType)typeNode).QualifiedName.Namespace != Keywords.XSDNS) { string targetNamespace = XSDSchema.GetMsdataAttribute(typeNode, Keywords.TARGETNAMESPACE); strType = ((XmlSchemaSimpleType)typeNode).QualifiedName.ToString(); // use qualifed name type = ParseDataType(strType); } else { simpleTypeNode = (xsdType.XmlBaseType!= null && xsdType.XmlBaseType.Namespace != Keywords.XSDNS) ? schemaTypes[xsdType.XmlBaseType] as XmlSchemaSimpleType : null; while (simpleTypeNode != null) { xsdType.LoadTypeValues(simpleTypeNode); simpleTypeNode = (xsdType.XmlBaseType!= null && xsdType.XmlBaseType.Namespace != Keywords.XSDNS) ? schemaTypes[xsdType.XmlBaseType] as XmlSchemaSimpleType : null; } type = ParseDataType(xsdType.BaseType); strType = xsdType.Name; if(xsdType.Length == 1 && type == typeof(string)) { type = typeof(Char); } } } else if (typeNode is XmlSchemaElement) { // theoratically no named simpletype should come here strType = ((XmlSchemaElement)typeNode).SchemaTypeName.Name; type = ParseDataType(strType); } else if (typeNode is XmlSchemaComplexType) { if (ADP.IsEmpty(XSDSchema.GetMsdataAttribute(elem, Keywords.MSD_DATATYPE))) { throw ExceptionBuilder.DatatypeNotDefined(); } else { type = typeof(object); } } else { if (typeNode.Id == null) throw ExceptionBuilder.DatatypeNotDefined(); else throw ExceptionBuilder.UndefinedDatatype(typeNode.Id); } DataColumn column; string columnName = XmlConvert.DecodeName(GetInstanceName(el)); bool isToAdd = true; if (((!isBase) || FromInference) && (table.Columns.Contains(columnName, true))) { column = table.Columns[columnName]; isToAdd = false; if (FromInference) { // for backward compatability with old inference if (column.ColumnMapping != MappingType.Element) throw ExceptionBuilder.ColumnTypeConflict(column.ColumnName); // in previous inference , if we have incoming column with different NS, we think as different column and //while adding , since there is no NS concept for datacolumn, we used to throw exception // simulate the same behavior. if ((Common.ADP.IsEmpty(elem.QualifiedName.Namespace) && Common.ADP.IsEmpty(column._columnUri)) || // backward compatability :SQL BU DT 310912 (string.Compare(elem.QualifiedName.Namespace, column.Namespace, StringComparison.Ordinal) == 0)) { return; // backward compatability } column = new DataColumn(columnName, type, null, MappingType.Element);// this is to fix issue with Exception we used to throw for old inference engine if column //exists with different namespace; while adding it to columncollection isToAdd = true; } } else { column = new DataColumn(columnName, type, null, MappingType.Element); } SetProperties(column, el.UnhandledAttributes); HandleColumnExpression(column, el.UnhandledAttributes); SetExtProperties(column, el.UnhandledAttributes); if (!Common.ADP.IsEmpty(column.Expression)) { ColumnExpressions.Add(column); } // Update XSD type to point to simple types actual namespace instead of normalized default namespace in case of remoting if (xsdType != null && xsdType.Name != null && xsdType.Name.Length > 0) { if (XSDSchema.GetMsdataAttribute(typeNode, Keywords.TARGETNAMESPACE)!= null) { column.XmlDataType = xsdType.SimpleTypeQualifiedName; } } else { column.XmlDataType = strType; } column.SimpleType = xsdType; column.AllowDBNull = this.FromInference ||(elem.MinOccurs == 0 ) || elem.IsNillable; if (!elem.RefName.IsEmpty || elem.QualifiedName.Namespace != table.Namespace) { // if ref element (or in diferent NS) it is global element, so form MUST BE Qualified column.Namespace = elem.QualifiedName.Namespace; column.Namespace = GetStringAttribute(el, "targetNamespace", column.Namespace); } else { // it is local, hence check for 'form' on local element, if not specified, check for 'elemenfformdefault' on schema element if (elem.Form == XmlSchemaForm.Unqualified) { column.Namespace = String.Empty; } else if (elem.Form == XmlSchemaForm.None) { XmlSchemaObject e = (XmlSchemaObject)elem.Parent; while (e.Parent != null) { e = e.Parent; } if (((XmlSchema)e).ElementFormDefault == XmlSchemaForm.Unqualified) { column.Namespace = String.Empty; } } else { column.Namespace = elem.QualifiedName.Namespace; column.Namespace = GetStringAttribute(el, "targetNamespace", column.Namespace); } } String tmp = GetStringAttribute(elem, Keywords.MSD_ORDINAL, (-1).ToString(CultureInfo.CurrentCulture)); int ordinal = (int)Convert.ChangeType(tmp, typeof(int), null); if(isToAdd) { if(ordinal>-1 && ordinal<table.Columns.Count) table.Columns.AddAt(ordinal, column); else table.Columns.Add(column); } if (column.Namespace == table.Namespace) column._columnUri = null; // to not raise a column change namespace again if(this.FromInference) {// search for prefix after adding to table, so NS has its final value, and column.Prefix = GetPrefix(column.Namespace); // it can inherit its NS from DataTable, if it is null } string strDefault = el.DefaultValue; if (strDefault != null ) try { column.DefaultValue = column.ConvertXmlToObject(strDefault); } catch (System.FormatException) { throw ExceptionBuilder.CannotConvert(strDefault, type.FullName); } }
internal void HandleSimpleTypeSimpleContentColumn(XmlSchemaSimpleType typeNode, string strType, DataTable table, bool isBase, XmlAttribute[] attrs, bool isNillable){ // disallow multiple simple content columns for the table if(FromInference && table.XmlText != null) { // backward compatability for inference return; } Type type = null; SimpleType xsdType = null; // if (typeNode.QualifiedName.Namespace != Keywords.XSDNS) { // this means UDSimpleType if (typeNode.QualifiedName.Name != null && typeNode.QualifiedName.Name.Length != 0 && typeNode.QualifiedName.Namespace != Keywords.XSDNS) { // this means UDSimpleType xsdType = new SimpleType(typeNode); strType = typeNode.QualifiedName.ToString(); // use qualifed name type = ParseDataType(typeNode.QualifiedName.ToString()); } else {// previous code V 1.1 XmlSchemaSimpleType ancestor = typeNode.BaseXmlSchemaType as XmlSchemaSimpleType; if ((ancestor != null) && (ancestor.QualifiedName.Namespace != Keywords.XSDNS)) { xsdType = new SimpleType(typeNode); SimpleType rootType = xsdType; while (rootType.BaseSimpleType != null) { rootType = rootType.BaseSimpleType; } type = ParseDataType(rootType.BaseType); strType = xsdType.Name; } else { type = ParseDataType(strType); } } DataColumn column; string colName; if (this.FromInference) { int i = 0; colName = table.TableName + "_Text"; while (table.Columns[colName] != null) { colName = colName + i++; } } else colName = table.TableName + "_text"; string columnName = colName; bool isToAdd = true; if ((!isBase) && (table.Columns.Contains(columnName, true))){ column = table.Columns[columnName]; isToAdd = false; } else { column = new DataColumn(columnName, type, null, MappingType.SimpleContent); } SetProperties(column, attrs); HandleColumnExpression(column, attrs); SetExtProperties(column, attrs); String tmp = (-1).ToString(CultureInfo.CurrentCulture); string defValue = null; //try to see if attributes contain allownull column.AllowDBNull = isNillable; if(attrs!=null) for(int i=0; i< attrs.Length;i++) { if ( attrs[i].LocalName == Keywords.MSD_ALLOWDBNULL && attrs[i].NamespaceURI == Keywords.MSDNS) if ( attrs[i].Value == Keywords.FALSE) column.AllowDBNull = false; if ( attrs[i].LocalName == Keywords.MSD_ORDINAL && attrs[i].NamespaceURI == Keywords.MSDNS) tmp = attrs[i].Value; if ( attrs[i].LocalName == Keywords.MSD_DEFAULTVALUE && attrs[i].NamespaceURI == Keywords.MSDNS) defValue = attrs[i].Value; } int ordinal = (int)Convert.ChangeType(tmp, typeof(int), null); //SetExtProperties(column, attr.UnhandledAttributes); if ((column.Expression!=null)&&(column.Expression.Length!=0)) { ColumnExpressions.Add(column); } // Update XSD type to point to simple types actual namespace instead of normalized default namespace in case of remoting if (xsdType != null && xsdType.Name != null && xsdType.Name.Length > 0) { if (XSDSchema.GetMsdataAttribute(typeNode, Keywords.TARGETNAMESPACE)!= null) { column.XmlDataType = xsdType.SimpleTypeQualifiedName; } } else { column.XmlDataType = strType; } column.SimpleType = xsdType; //column.Namespace = typeNode.SourceUri; if (isToAdd) { if (this.FromInference) { column.Prefix = GetPrefix(table.Namespace); column.AllowDBNull = true; } if(ordinal>-1 && ordinal<table.Columns.Count) table.Columns.AddAt(ordinal, column); else table.Columns.Add(column); } if (defValue != null) try { column.DefaultValue = column.ConvertXmlToObject(defValue); } catch (System.FormatException) { throw ExceptionBuilder.CannotConvert(defValue, type.FullName); } }
private void CollectElementsAnnotations(XmlSchema schema, ArrayList schemaList){ if (schemaList.Contains(schema)) { return; } schemaList.Add(schema); foreach(object item in schema.Items) { if (item is XmlSchemaAnnotation) { annotations.Add((XmlSchemaAnnotation)item); } if (item is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement)item; elements.Add(elem); elementsTable[elem.QualifiedName] = elem; } if (item is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)item; attributes[attr.QualifiedName] = attr; } if (item is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attr = (XmlSchemaAttributeGroup)item; attributeGroups[attr.QualifiedName] = attr; } if (item is XmlSchemaType) { string MSDATATargetNamespace = null; if (item is XmlSchemaSimpleType) { MSDATATargetNamespace = XSDSchema.GetMsdataAttribute((XmlSchemaType)item, Keywords.TARGETNAMESPACE); } XmlSchemaType type = (XmlSchemaType)item; schemaTypes[type.QualifiedName] = type; // Webdata 92054 if we have a User Defined simple type, cache it so later we may need for mapping // meanwhile more convinient solution would be to directly use schemaTypes, but it would be more complex to handle XmlSchemaSimpleType xmlSimpleType = (item as XmlSchemaSimpleType ); if (xmlSimpleType != null) { if (udSimpleTypes == null) { udSimpleTypes = new Hashtable(); } udSimpleTypes[type.QualifiedName.ToString()] = xmlSimpleType; DataColumn dc = (DataColumn)existingSimpleTypeMap[type.QualifiedName.ToString()]; // Assumption is that our simple type qualified name ihas the same output as XmlSchemaSimpleType type.QualifiedName.ToString() SimpleType tmpSimpleType = (dc != null)? dc.SimpleType: null; // if (tmpSimpleType != null) { SimpleType tmpDataSimpleType = new SimpleType(xmlSimpleType); string errorStr = tmpSimpleType.HasConflictingDefinition(tmpDataSimpleType); if (errorStr.Length != 0) { throw ExceptionBuilder.InvalidDuplicateNamedSimpleTypeDelaration(tmpDataSimpleType.SimpleTypeQualifiedName, errorStr); } } } } } foreach(XmlSchemaExternal include in schema.Includes) { if (include is XmlSchemaImport) continue; if (include.Schema != null) { CollectElementsAnnotations(include.Schema, schemaList); } } }
internal void ConvertToAnnonymousSimpleType() { this.name = null; this.ns = string.Empty; SimpleType baseSimpleType = this; while (baseSimpleType.baseSimpleType != null) { baseSimpleType = baseSimpleType.baseSimpleType; } this.baseType = baseSimpleType.baseType; this.baseSimpleType = baseSimpleType.baseSimpleType; this.xmlBaseType = baseSimpleType.xmlBaseType; }
internal void HandleColumn(XmlElement node, DataTable table) { Debug.Assert(FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS) || FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS), "Illegal node type"); string instanceName; string strName; Type type; string strType; string strValues; int minOccurs = 0; int maxOccurs = 1; string strDefault; DataColumn column; // Get the name if (node.Attributes.Count > 0) { string strRef = node.GetAttribute(Keywords.REF); if (strRef != null && strRef.Length > 0) { return; //skip ref nodes. B2 item } strName = instanceName = GetInstanceName(node); column = table.Columns[instanceName, _schemaUri]; if (column != null) { if (column.ColumnMapping == MappingType.Attribute) { if (FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS)) { throw ExceptionBuilder.DuplicateDeclaration(strName); } } else { if (FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS)) { throw ExceptionBuilder.DuplicateDeclaration(strName); } } instanceName = GenUniqueColumnName(strName, table); } } else { strName = instanceName = string.Empty; } // Now get the type XmlElement typeNode = FindTypeNode(node); SimpleType xsdType = null; if (typeNode == null) { strType = node.GetAttribute(Keywords.TYPE); throw ExceptionBuilder.UndefinedDatatype(strType); } strType = typeNode.GetAttribute(Keywords.DT_TYPE, Keywords.DTNS); strValues = typeNode.GetAttribute(Keywords.DT_VALUES, Keywords.DTNS); if (strType == null || strType.Length == 0) { strType = string.Empty; type = typeof(string); } else { type = ParseDataType(strType, strValues); // HACK: temp work around special types if (strType == "float") { strType = string.Empty; } if (strType == "char") { strType = string.Empty; xsdType = SimpleType.CreateSimpleType(StorageType.Char, type); } if (strType == "enumeration") { strType = string.Empty; xsdType = SimpleType.CreateEnumeratedType(strValues); } if (strType == "bin.base64") { strType = string.Empty; xsdType = SimpleType.CreateByteArrayType("base64"); } if (strType == "bin.hex") { strType = string.Empty; xsdType = SimpleType.CreateByteArrayType("hex"); } } bool isAttribute = FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS); GetMinMax(node, isAttribute, ref minOccurs, ref maxOccurs); strDefault = null; // Does XDR has default? strDefault = node.GetAttribute(Keywords.DEFAULT); bool bNullable = false; column = new DataColumn(XmlConvert.DecodeName(instanceName), type, null, isAttribute ? MappingType.Attribute : MappingType.Element); SetProperties(column, node.Attributes); // xmlschema.SetProperties will skipp setting expressions column.XmlDataType = strType; column.SimpleType = xsdType; column.AllowDBNull = (minOccurs == 0) || bNullable; column.Namespace = (isAttribute) ? string.Empty : _schemaUri; // We will skip handling expression columns in SetProperties, so we need set the expressions here if (node.Attributes != null) { for (int i = 0; i < node.Attributes.Count; i++) { if (node.Attributes[i].NamespaceURI == Keywords.MSDNS) { if (node.Attributes[i].LocalName == "Expression") { column.Expression = node.Attributes[i].Value; break; } } } } string targetNamespace = node.GetAttribute(Keywords.TARGETNAMESPACE); if (targetNamespace != null && targetNamespace.Length > 0) { column.Namespace = targetNamespace; } table.Columns.Add(column); if (strDefault != null && strDefault.Length != 0) { try { column.DefaultValue = SqlConvert.ChangeTypeForXML(strDefault, type); } catch (System.FormatException) { throw ExceptionBuilder.CannotConvert(strDefault, type.FullName); } } }
internal void LoadTypeValues(XmlSchemaSimpleType node) { if ((node.Content is XmlSchemaSimpleTypeList) || (node.Content is XmlSchemaSimpleTypeUnion)) { throw ExceptionBuilder.SimpleTypeNotSupported(); } if (node.Content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)node.Content; XmlSchemaSimpleType ancestor = node.BaseXmlSchemaType as XmlSchemaSimpleType; if ((ancestor != null) && (ancestor.QualifiedName.Namespace != Keywords.XSDNS)) { _baseSimpleType = new SimpleType(node.BaseXmlSchemaType as XmlSchemaSimpleType); } // do we need to put qualified name? // for user defined simpletype, always go with qname if (content.BaseTypeName.Namespace == Keywords.XSDNS) { _baseType = content.BaseTypeName.Name; } else { _baseType = content.BaseTypeName.ToString(); } if (_baseSimpleType != null && _baseSimpleType.Name != null && _baseSimpleType.Name.Length > 0) { _xmlBaseType = _baseSimpleType.XmlBaseType;// SimpleTypeQualifiedName; } else { _xmlBaseType = content.BaseTypeName; } if (_baseType == null || _baseType.Length == 0) { _baseType = content.BaseType.Name; _xmlBaseType = null; } if (_baseType == "NOTATION") { _baseType = "string"; } foreach (XmlSchemaFacet facet in content.Facets) { if (facet is XmlSchemaLengthFacet) { _length = Convert.ToInt32(facet.Value, null); } if (facet is XmlSchemaMinLengthFacet) { _minLength = Convert.ToInt32(facet.Value, null); } if (facet is XmlSchemaMaxLengthFacet) { _maxLength = Convert.ToInt32(facet.Value, null); } if (facet is XmlSchemaPatternFacet) { _pattern = facet.Value; } if (facet is XmlSchemaEnumerationFacet) { _enumeration = !string.IsNullOrEmpty(_enumeration) ? _enumeration + " " + facet.Value : facet.Value; } if (facet is XmlSchemaMinExclusiveFacet) { _minExclusive = facet.Value; } if (facet is XmlSchemaMinInclusiveFacet) { _minInclusive = facet.Value; } if (facet is XmlSchemaMaxExclusiveFacet) { _maxExclusive = facet.Value; } if (facet is XmlSchemaMaxInclusiveFacet) { _maxInclusive = facet.Value; } } } string tempStr = XSDSchema.GetMsdataAttribute(node, Keywords.TARGETNAMESPACE); if (tempStr != null) { _ns = tempStr; } }
internal static SimpleType CreateByteArrayType(string encoding) { SimpleType byteArrayType = new SimpleType("base64Binary"); return(byteArrayType); }
internal void HandleElementColumn(XmlSchemaElement elem, DataTable table, bool isBase) { Type dataType = null; XmlSchemaElement node = (elem.Name != null) ? elem : ((XmlSchemaElement) this.elementsTable[elem.RefName]); if (node != null) { DataColumn column; XmlSchemaAnnotated annotated = this.FindTypeNode(node); string str = null; SimpleType type = null; if (annotated == null) { str = node.SchemaTypeName.Name; if (ADP.IsEmpty(str)) { str = ""; dataType = typeof(string); } else { dataType = this.ParseDataType(node.SchemaTypeName.Name); } } else if (annotated is XmlSchemaSimpleType) { XmlSchemaSimpleType type3 = annotated as XmlSchemaSimpleType; type = new SimpleType(type3); if (((((XmlSchemaSimpleType) annotated).Name != null) && (((XmlSchemaSimpleType) annotated).Name.Length != 0)) && (((XmlSchemaSimpleType) annotated).QualifiedName.Namespace != "http://www.w3.org/2001/XMLSchema")) { GetMsdataAttribute(annotated, "targetNamespace"); str = ((XmlSchemaSimpleType) annotated).QualifiedName.ToString(); dataType = this.ParseDataType(str); } else { for (type3 = ((type.XmlBaseType != null) && (type.XmlBaseType.Namespace != "http://www.w3.org/2001/XMLSchema")) ? (this.schemaTypes[type.XmlBaseType] as XmlSchemaSimpleType) : null; type3 != null; type3 = ((type.XmlBaseType != null) && (type.XmlBaseType.Namespace != "http://www.w3.org/2001/XMLSchema")) ? (this.schemaTypes[type.XmlBaseType] as XmlSchemaSimpleType) : null) { type.LoadTypeValues(type3); } dataType = this.ParseDataType(type.BaseType); str = type.Name; if ((type.Length == 1) && (dataType == typeof(string))) { dataType = typeof(char); } } } else if (annotated is XmlSchemaElement) { str = ((XmlSchemaElement) annotated).SchemaTypeName.Name; dataType = this.ParseDataType(str); } else if (annotated is XmlSchemaComplexType) { if (ADP.IsEmpty(GetMsdataAttribute(elem, "DataType"))) { throw ExceptionBuilder.DatatypeNotDefined(); } dataType = typeof(object); } else { if (annotated.Id == null) { throw ExceptionBuilder.DatatypeNotDefined(); } throw ExceptionBuilder.UndefinedDatatype(annotated.Id); } string name = XmlConvert.DecodeName(this.GetInstanceName(node)); bool flag = true; if ((!isBase || this.FromInference) && table.Columns.Contains(name, true)) { column = table.Columns[name]; flag = false; if (this.FromInference) { if (column.ColumnMapping != MappingType.Element) { throw ExceptionBuilder.ColumnTypeConflict(column.ColumnName); } if ((ADP.IsEmpty(elem.QualifiedName.Namespace) && ADP.IsEmpty(column._columnUri)) || (string.Compare(elem.QualifiedName.Namespace, column.Namespace, StringComparison.Ordinal) == 0)) { return; } column = new DataColumn(name, dataType, null, MappingType.Element); flag = true; } } else { column = new DataColumn(name, dataType, null, MappingType.Element); } SetProperties(column, node.UnhandledAttributes); this.HandleColumnExpression(column, node.UnhandledAttributes); SetExtProperties(column, node.UnhandledAttributes); if (!ADP.IsEmpty(column.Expression)) { this.ColumnExpressions.Add(column); } if (((type != null) && (type.Name != null)) && (type.Name.Length > 0)) { if (GetMsdataAttribute(annotated, "targetNamespace") != null) { column.XmlDataType = type.SimpleTypeQualifiedName; } } else { column.XmlDataType = str; } column.SimpleType = type; column.AllowDBNull = (this.FromInference || (elem.MinOccurs == 0M)) || elem.IsNillable; if (!elem.RefName.IsEmpty || (elem.QualifiedName.Namespace != table.Namespace)) { column.Namespace = elem.QualifiedName.Namespace; column.Namespace = this.GetStringAttribute(node, "targetNamespace", column.Namespace); } else if (elem.Form == XmlSchemaForm.Unqualified) { column.Namespace = string.Empty; } else if (elem.Form == XmlSchemaForm.None) { XmlSchemaObject parent = elem.Parent; while (parent.Parent != null) { parent = parent.Parent; } if (((XmlSchema) parent).ElementFormDefault == XmlSchemaForm.Unqualified) { column.Namespace = string.Empty; } } else { column.Namespace = elem.QualifiedName.Namespace; column.Namespace = this.GetStringAttribute(node, "targetNamespace", column.Namespace); } int index = (int) Convert.ChangeType(this.GetStringAttribute(elem, "Ordinal", "-1"), typeof(int), null); if (flag) { if ((index > -1) && (index < table.Columns.Count)) { table.Columns.AddAt(index, column); } else { table.Columns.Add(column); } } if (column.Namespace == table.Namespace) { column._columnUri = null; } if (this.FromInference) { column.Prefix = this.GetPrefix(column.Namespace); } string defaultValue = node.DefaultValue; if (defaultValue != null) { try { column.DefaultValue = column.ConvertXmlToObject(defaultValue); } catch (FormatException) { throw ExceptionBuilder.CannotConvert(defaultValue, dataType.FullName); } } } }
private void CollectElementsAnnotations(XmlSchema schema, ArrayList schemaList) { if (!schemaList.Contains(schema)) { schemaList.Add(schema); foreach (object obj2 in schema.Items) { if (obj2 is XmlSchemaAnnotation) { this.annotations.Add((XmlSchemaAnnotation) obj2); } if (obj2 is XmlSchemaElement) { XmlSchemaElement item = (XmlSchemaElement) obj2; this.elements.Add(item); this.elementsTable[item.QualifiedName] = item; } if (obj2 is XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute) obj2; this.attributes[attribute.QualifiedName] = attribute; } if (obj2 is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup) obj2; this.attributeGroups[group.QualifiedName] = group; } if (obj2 is XmlSchemaType) { if (obj2 is XmlSchemaSimpleType) { GetMsdataAttribute((XmlSchemaType) obj2, "targetNamespace"); } XmlSchemaType type = (XmlSchemaType) obj2; this.schemaTypes[type.QualifiedName] = type; XmlSchemaSimpleType node = obj2 as XmlSchemaSimpleType; if (node != null) { if (this.udSimpleTypes == null) { this.udSimpleTypes = new Hashtable(); } this.udSimpleTypes[type.QualifiedName.ToString()] = node; DataColumn column = (DataColumn) this.existingSimpleTypeMap[type.QualifiedName.ToString()]; SimpleType type4 = (column != null) ? column.SimpleType : null; if (type4 != null) { SimpleType otherSimpleType = new SimpleType(node); string errorStr = type4.HasConflictingDefinition(otherSimpleType); if (errorStr.Length != 0) { throw ExceptionBuilder.InvalidDuplicateNamedSimpleTypeDelaration(otherSimpleType.SimpleTypeQualifiedName, errorStr); } } } } } foreach (XmlSchemaExternal external in schema.Includes) { if (!(external is XmlSchemaImport) && (external.Schema != null)) { this.CollectElementsAnnotations(external.Schema, schemaList); } } } }
internal void HandleAttributeColumn(XmlSchemaAttribute attrib, DataTable table, bool isBase) { DataColumn column; Type dataType = null; XmlSchemaAttribute node = (attrib.Name != null) ? attrib : ((XmlSchemaAttribute) this.attributes[attrib.RefName]); XmlSchemaAnnotated annotated = this.FindTypeNode(node); string str = null; SimpleType type2 = null; if (annotated == null) { str = node.SchemaTypeName.Name; if (ADP.IsEmpty(str)) { str = ""; dataType = typeof(string); } else if (node.SchemaTypeName.Namespace != "http://www.w3.org/2001/XMLSchema") { dataType = this.ParseDataType(node.SchemaTypeName.ToString()); } else { dataType = this.ParseDataType(node.SchemaTypeName.Name); } } else if (annotated is XmlSchemaSimpleType) { XmlSchemaSimpleType type3 = annotated as XmlSchemaSimpleType; type2 = new SimpleType(type3); if (((type3.QualifiedName.Name != null) && (type3.QualifiedName.Name.Length != 0)) && (type3.QualifiedName.Namespace != "http://www.w3.org/2001/XMLSchema")) { str = type3.QualifiedName.ToString(); dataType = this.ParseDataType(type3.QualifiedName.ToString()); } else { dataType = this.ParseDataType(type2.BaseType); str = type2.Name; if ((type2.Length == 1) && (dataType == typeof(string))) { dataType = typeof(char); } } } else if (annotated is XmlSchemaElement) { str = ((XmlSchemaElement) annotated).SchemaTypeName.Name; dataType = this.ParseDataType(str); } else { if (annotated.Id == null) { throw ExceptionBuilder.DatatypeNotDefined(); } throw ExceptionBuilder.UndefinedDatatype(annotated.Id); } string name = XmlConvert.DecodeName(this.GetInstanceName(node)); bool flag = true; if ((!isBase || this.FromInference) && table.Columns.Contains(name, true)) { column = table.Columns[name]; flag = false; if (this.FromInference) { if (column.ColumnMapping != MappingType.Attribute) { throw ExceptionBuilder.ColumnTypeConflict(column.ColumnName); } if ((ADP.IsEmpty(attrib.QualifiedName.Namespace) && ADP.IsEmpty(column._columnUri)) || (string.Compare(attrib.QualifiedName.Namespace, column.Namespace, StringComparison.Ordinal) == 0)) { return; } column = new DataColumn(name, dataType, null, MappingType.Attribute); flag = true; } } else { column = new DataColumn(name, dataType, null, MappingType.Attribute); } SetProperties(column, node.UnhandledAttributes); this.HandleColumnExpression(column, node.UnhandledAttributes); SetExtProperties(column, node.UnhandledAttributes); if ((column.Expression != null) && (column.Expression.Length != 0)) { this.ColumnExpressions.Add(column); } if (((type2 != null) && (type2.Name != null)) && (type2.Name.Length > 0)) { if (GetMsdataAttribute(annotated, "targetNamespace") != null) { column.XmlDataType = type2.SimpleTypeQualifiedName; } } else { column.XmlDataType = str; } column.SimpleType = type2; column.AllowDBNull = attrib.Use != XmlSchemaUse.Required; column.Namespace = attrib.QualifiedName.Namespace; column.Namespace = this.GetStringAttribute(attrib, "targetNamespace", column.Namespace); if (flag) { if (this.FromInference) { column.AllowDBNull = true; column.Prefix = this.GetPrefix(column.Namespace); } table.Columns.Add(column); } if (attrib.Use == XmlSchemaUse.Prohibited) { column.ColumnMapping = MappingType.Hidden; column.AllowDBNull = this.GetBooleanAttribute(node, "AllowDBNull", true); string msdataAttribute = GetMsdataAttribute(node, "DefaultValue"); if (msdataAttribute != null) { try { column.DefaultValue = column.ConvertXmlToObject(msdataAttribute); } catch (FormatException) { throw ExceptionBuilder.CannotConvert(msdataAttribute, dataType.FullName); } } } string s = (attrib.Use == XmlSchemaUse.Required) ? GetMsdataAttribute(node, "DefaultValue") : node.DefaultValue; if ((node.Use == XmlSchemaUse.Optional) && (s == null)) { s = node.FixedValue; } if (s != null) { try { column.DefaultValue = column.ConvertXmlToObject(s); } catch (FormatException) { throw ExceptionBuilder.CannotConvert(s, dataType.FullName); } } }
internal void LoadTypeValues (XmlSchemaSimpleType node) { if ((node.Content is XmlSchemaSimpleTypeList) || (node.Content is XmlSchemaSimpleTypeUnion)) throw ExceptionBuilder.SimpleTypeNotSupported(); if (node.Content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction) node.Content; XmlSchemaSimpleType ancestor = node.BaseXmlSchemaType as XmlSchemaSimpleType; if ((ancestor != null) && (ancestor.QualifiedName.Namespace != Keywords.XSDNS)) { // I'm assuming that built-in types don't have a name! // Console.WriteLine("In simpleNode, ancestor.Name = '{0}'", ancestor.Name); baseSimpleType = new SimpleType(node.BaseXmlSchemaType as XmlSchemaSimpleType); // baseSimpleType = new SimpleType(node); } // do we need to put qualified name? // for user defined simpletype, always go with qname if (content.BaseTypeName.Namespace == Keywords.XSDNS) baseType = content.BaseTypeName.Name; else baseType = content.BaseTypeName.ToString(); if (baseSimpleType != null && baseSimpleType.Name != null && baseSimpleType.Name.Length > 0) { xmlBaseType = baseSimpleType.XmlBaseType;// SimpleTypeQualifiedName; } else { xmlBaseType = content.BaseTypeName; } if (baseType == null || baseType.Length == 0) { // Console.WriteLine("baseType == null, setting it to ", content.BaseType.Name); baseType = content.BaseType.Name; xmlBaseType = null; } if (baseType == "NOTATION") baseType = "string"; foreach(XmlSchemaFacet facet in content.Facets) { if (facet is XmlSchemaLengthFacet) length = Convert.ToInt32(facet.Value, null); if (facet is XmlSchemaMinLengthFacet) minLength = Convert.ToInt32(facet.Value, null); if (facet is XmlSchemaMaxLengthFacet) maxLength = Convert.ToInt32(facet.Value, null); if (facet is XmlSchemaPatternFacet) pattern = facet.Value; if (facet is XmlSchemaEnumerationFacet) enumeration = !Common.ADP.IsEmpty(enumeration) ? enumeration + " " + facet.Value : facet.Value; if (facet is XmlSchemaMinExclusiveFacet) minExclusive = facet.Value; if (facet is XmlSchemaMinInclusiveFacet) minInclusive = facet.Value; if (facet is XmlSchemaMaxExclusiveFacet) maxExclusive = facet.Value; if (facet is XmlSchemaMaxInclusiveFacet) maxInclusive = facet.Value; } } string tempStr = XSDSchema.GetMsdataAttribute(node, Keywords.TARGETNAMESPACE); if (tempStr != null) ns = tempStr; }
internal static SimpleType CreateSimpleType(Type type) { SimpleType type2 = null; if (type == typeof(char)) { type2 = new SimpleType("string") { length = 1 }; } return type2; }
// input param dt is a "qName" for UDSimpleType else it assumes it's a XSD builtin simpleType private Type ParseDataType(string dt) { if (!IsXsdType(dt)) { if (udSimpleTypes != null) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) udSimpleTypes[dt]; if (simpleType == null) { // it is not named simple type, it is not XSD type, it should be unsupported type like xs:token throw ExceptionBuilder.UndefinedDatatype(dt); } SimpleType rootType = new SimpleType(simpleType); while (rootType.BaseSimpleType != null) { rootType = rootType.BaseSimpleType; } return ParseDataType(rootType.BaseType); } } NameType nt = FindNameType(dt); return nt.type; }
internal string HasConflictingDefinition(SimpleType otherSimpleType) { if (otherSimpleType == null) { return "otherSimpleType"; } if (this.MaxLength != otherSimpleType.MaxLength) { return "MaxLength"; } if (string.Compare(this.BaseType, otherSimpleType.BaseType, StringComparison.Ordinal) != 0) { return "BaseType"; } if (((this.BaseSimpleType == null) && (otherSimpleType.BaseSimpleType != null)) && (this.BaseSimpleType.HasConflictingDefinition(otherSimpleType.BaseSimpleType).Length != 0)) { return "BaseSimpleType"; } return string.Empty; }
internal void HandleAttributeColumn(XmlSchemaAttribute attrib, DataTable table, bool isBase){ Type type = null; XmlSchemaAttribute attr = attrib.Name != null ? attrib : (XmlSchemaAttribute) attributes[attrib.RefName]; XmlSchemaAnnotated typeNode = FindTypeNode(attr); String strType = null; SimpleType xsdType = null; if (typeNode == null) { strType = attr.SchemaTypeName.Name; if (Common.ADP.IsEmpty(strType)) { strType = ""; type = typeof(string); } else { if (attr.SchemaTypeName.Namespace != Keywords.XSDNS) // it is UD Simple Type, can it be? // type = ParseDataType(attr.SchemaTypeName.ToString()); else type = ParseDataType(attr.SchemaTypeName.Name); } } else if (typeNode is XmlSchemaSimpleType) { // XmlSchemaSimpleType node = typeNode as XmlSchemaSimpleType; xsdType = new SimpleType(node); if (node.QualifiedName.Name != null && node.QualifiedName.Name.Length != 0 && node.QualifiedName.Namespace != Keywords.XSDNS) { // this means UDSimpleType strType = node.QualifiedName.ToString(); // use qualifed name type = ParseDataType(node.QualifiedName.ToString());// search with QName } else { type = ParseDataType(xsdType.BaseType); strType = xsdType.Name; if(xsdType.Length == 1 && type == typeof(string)) { type = typeof(Char); } } } else if (typeNode is XmlSchemaElement) { strType = ((XmlSchemaElement)typeNode).SchemaTypeName.Name; type = ParseDataType(strType); } else { if (typeNode.Id == null) throw ExceptionBuilder.DatatypeNotDefined(); else throw ExceptionBuilder.UndefinedDatatype(typeNode.Id); } DataColumn column; string columnName = XmlConvert.DecodeName(GetInstanceName(attr)); bool isToAdd = true; if ((!isBase || FromInference) && (table.Columns.Contains(columnName, true))) { column = table.Columns[columnName]; isToAdd = false; if (FromInference) { // for backward compatability with old inference // throw eception if same column is being aded with different mapping if (column.ColumnMapping != MappingType.Attribute) throw ExceptionBuilder.ColumnTypeConflict(column.ColumnName); // in previous inference , if we have incoming column with different NS, we think as different column and //while adding , since there is no NS concept for datacolumn, we used to throw exception // simulate the same behavior. if ((Common.ADP.IsEmpty(attrib.QualifiedName.Namespace) && Common.ADP.IsEmpty(column._columnUri)) || // backward compatability :SQL BU DT 310912 (string.Compare(attrib.QualifiedName.Namespace, column.Namespace, StringComparison.Ordinal) == 0)) { return; // backward compatability } column = new DataColumn(columnName, type, null, MappingType.Attribute); // this is to fix issue with Exception we used to throw for old inference engine if column //exists with different namespace; while adding it to columncollection isToAdd = true; } } else { column = new DataColumn(columnName, type, null, MappingType.Attribute); } SetProperties(column, attr.UnhandledAttributes); HandleColumnExpression(column, attr.UnhandledAttributes); SetExtProperties(column, attr.UnhandledAttributes); if ((column.Expression!=null)&&(column.Expression.Length!=0)) { ColumnExpressions.Add(column); } if (xsdType != null && xsdType.Name != null && xsdType.Name.Length > 0) { if (XSDSchema.GetMsdataAttribute(typeNode, Keywords.TARGETNAMESPACE)!= null) { column.XmlDataType = xsdType.SimpleTypeQualifiedName; } } else { column.XmlDataType = strType; } column.SimpleType = xsdType; column.AllowDBNull = !(attrib.Use == XmlSchemaUse.Required); column.Namespace = attrib.QualifiedName.Namespace; column.Namespace = GetStringAttribute(attrib, "targetNamespace", column.Namespace); if (isToAdd) { if (this.FromInference) { // move this setting to SetProperties column.AllowDBNull = true; column.Prefix = GetPrefix(column.Namespace); } table.Columns.Add(column); } if (attrib.Use == XmlSchemaUse.Prohibited) { column.ColumnMapping = MappingType.Hidden; column.AllowDBNull = GetBooleanAttribute(attr, Keywords.MSD_ALLOWDBNULL, true) ; String defValue = GetMsdataAttribute(attr, Keywords.MSD_DEFAULTVALUE); if (defValue != null) try { column.DefaultValue = column.ConvertXmlToObject(defValue); } catch (System.FormatException) { throw ExceptionBuilder.CannotConvert(defValue, type.FullName); } } // XDR [....] change string strDefault = (attrib.Use == XmlSchemaUse.Required) ? GetMsdataAttribute(attr, Keywords.MSD_DEFAULTVALUE) : attr.DefaultValue; if ((attr.Use == XmlSchemaUse.Optional) && (strDefault == null )) strDefault = attr.FixedValue; if (strDefault != null) try { column.DefaultValue = column.ConvertXmlToObject(strDefault); } catch (System.FormatException) { throw ExceptionBuilder.CannotConvert(strDefault, type.FullName); } }
internal void LoadTypeValues(XmlSchemaSimpleType node) { if ((node.Content is XmlSchemaSimpleTypeList) || (node.Content is XmlSchemaSimpleTypeUnion)) { throw ExceptionBuilder.SimpleTypeNotSupported(); } if (node.Content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction) node.Content; XmlSchemaSimpleType baseXmlSchemaType = node.BaseXmlSchemaType as XmlSchemaSimpleType; if ((baseXmlSchemaType != null) && (baseXmlSchemaType.QualifiedName.Namespace != "http://www.w3.org/2001/XMLSchema")) { this.baseSimpleType = new SimpleType(node.BaseXmlSchemaType as XmlSchemaSimpleType); } if (content.BaseTypeName.Namespace == "http://www.w3.org/2001/XMLSchema") { this.baseType = content.BaseTypeName.Name; } else { this.baseType = content.BaseTypeName.ToString(); } if (((this.baseSimpleType != null) && (this.baseSimpleType.Name != null)) && (this.baseSimpleType.Name.Length > 0)) { this.xmlBaseType = this.baseSimpleType.XmlBaseType; } else { this.xmlBaseType = content.BaseTypeName; } if ((this.baseType == null) || (this.baseType.Length == 0)) { this.baseType = content.BaseType.Name; this.xmlBaseType = null; } if (this.baseType == "NOTATION") { this.baseType = "string"; } foreach (XmlSchemaFacet facet in content.Facets) { if (facet is XmlSchemaLengthFacet) { this.length = Convert.ToInt32(facet.Value, (IFormatProvider) null); } if (facet is XmlSchemaMinLengthFacet) { this.minLength = Convert.ToInt32(facet.Value, (IFormatProvider) null); } if (facet is XmlSchemaMaxLengthFacet) { this.maxLength = Convert.ToInt32(facet.Value, (IFormatProvider) null); } if (facet is XmlSchemaPatternFacet) { this.pattern = facet.Value; } if (facet is XmlSchemaEnumerationFacet) { this.enumeration = !ADP.IsEmpty(this.enumeration) ? (this.enumeration + " " + facet.Value) : facet.Value; } if (facet is XmlSchemaMinExclusiveFacet) { this.minExclusive = facet.Value; } if (facet is XmlSchemaMinInclusiveFacet) { this.minInclusive = facet.Value; } if (facet is XmlSchemaMaxExclusiveFacet) { this.maxExclusive = facet.Value; } if (facet is XmlSchemaMaxInclusiveFacet) { this.maxInclusive = facet.Value; } } } string msdataAttribute = XSDSchema.GetMsdataAttribute(node, "targetNamespace"); if (msdataAttribute != null) { this.ns = msdataAttribute; } }
internal static SimpleType CreateEnumeratedType(string values) { SimpleType enumType = new SimpleType("string"); enumType._enumeration = values; return enumType; }
internal bool CanHaveMaxLength() { SimpleType baseSimpleType = this; while (baseSimpleType.BaseSimpleType != null) { baseSimpleType = baseSimpleType.BaseSimpleType; } return (string.Compare(baseSimpleType.BaseType, "string", StringComparison.OrdinalIgnoreCase) == 0); }
internal static SimpleType CreateLimitedStringType(int length) { SimpleType limitedString = new SimpleType("string"); limitedString._maxLength = length; return limitedString; }
// Assumption is otherSimpleType and current ST name and NS matches. // if existing simpletype is being redefined with different facets, then it will return no-empty string defining the error internal string HasConflictingDefinition(SimpleType otherSimpleType) { if (otherSimpleType == null) return "otherSimpleType"; if (this.MaxLength != otherSimpleType.MaxLength) return ("MaxLength"); if (string.Compare(this.BaseType, otherSimpleType.BaseType, StringComparison.Ordinal) != 0) return ("BaseType"); if ((this.BaseSimpleType == null && otherSimpleType.BaseSimpleType != null) && (this.BaseSimpleType.HasConflictingDefinition(otherSimpleType.BaseSimpleType)).Length != 0) return ("BaseSimpleType"); return string.Empty; }
internal void ConvertToAnnonymousSimpleType() { _name = null; _ns = string.Empty; SimpleType tmpSimpleType = this; while (tmpSimpleType._baseSimpleType != null) { tmpSimpleType = tmpSimpleType._baseSimpleType; } _baseType = tmpSimpleType._baseType; _baseSimpleType = tmpSimpleType._baseSimpleType; _xmlBaseType = tmpSimpleType._xmlBaseType; }
internal void ConvertToAnnonymousSimpleType() { this.name = null; this.ns = string.Empty; SimpleType tmpSimpleType = this; while (tmpSimpleType.baseSimpleType != null) { tmpSimpleType = tmpSimpleType.baseSimpleType; } baseType = tmpSimpleType.baseType; baseSimpleType = tmpSimpleType.baseSimpleType; xmlBaseType = tmpSimpleType.xmlBaseType; }
private void SetMaxLengthSimpleType() { if (_simpleType != null) { Debug.Assert(_simpleType.CanHaveMaxLength(), "expected simpleType to be string"); _simpleType.MaxLength = _maxLength; // check if we reset the simpleType back to plain string if (_simpleType.IsPlainString()) { _simpleType = null; } else { // Named Simple Type's Name should not be null if (_simpleType.Name != null && XmlDataType != null) { // if MaxLength is changed, we need to make namedsimpletype annonymous simpletype _simpleType.ConvertToAnnonymousSimpleType(); XmlDataType = null; } } } else if (-1 < _maxLength) { SimpleType = SimpleType.CreateLimitedStringType(_maxLength); } }
internal void HandleSimpleTypeSimpleContentColumn(XmlSchemaSimpleType typeNode, string strType, DataTable table, bool isBase, XmlAttribute[] attrs, bool isNillable) { if (!this.FromInference || (table.XmlText == null)) { DataColumn column; string str; Type dataType = null; SimpleType type = null; if (((typeNode.QualifiedName.Name != null) && (typeNode.QualifiedName.Name.Length != 0)) && (typeNode.QualifiedName.Namespace != "http://www.w3.org/2001/XMLSchema")) { type = new SimpleType(typeNode); strType = typeNode.QualifiedName.ToString(); dataType = this.ParseDataType(typeNode.QualifiedName.ToString()); } else { XmlSchemaSimpleType baseXmlSchemaType = typeNode.BaseXmlSchemaType as XmlSchemaSimpleType; if ((baseXmlSchemaType != null) && (baseXmlSchemaType.QualifiedName.Namespace != "http://www.w3.org/2001/XMLSchema")) { type = new SimpleType(typeNode); SimpleType baseSimpleType = type; while (baseSimpleType.BaseSimpleType != null) { baseSimpleType = baseSimpleType.BaseSimpleType; } dataType = this.ParseDataType(baseSimpleType.BaseType); strType = type.Name; } else { dataType = this.ParseDataType(strType); } } if (this.FromInference) { int num3 = 0; for (str = table.TableName + "_Text"; table.Columns[str] != null; str = str + num3++) { } } else { str = table.TableName + "_text"; } string name = str; bool flag = true; if (!isBase && table.Columns.Contains(name, true)) { column = table.Columns[name]; flag = false; } else { column = new DataColumn(name, dataType, null, MappingType.SimpleContent); } SetProperties(column, attrs); this.HandleColumnExpression(column, attrs); SetExtProperties(column, attrs); string str4 = "-1"; string s = null; column.AllowDBNull = isNillable; if (attrs != null) { for (int i = 0; i < attrs.Length; i++) { if (((attrs[i].LocalName == "AllowDBNull") && (attrs[i].NamespaceURI == "urn:schemas-microsoft-com:xml-msdata")) && (attrs[i].Value == "false")) { column.AllowDBNull = false; } if ((attrs[i].LocalName == "Ordinal") && (attrs[i].NamespaceURI == "urn:schemas-microsoft-com:xml-msdata")) { str4 = attrs[i].Value; } if ((attrs[i].LocalName == "DefaultValue") && (attrs[i].NamespaceURI == "urn:schemas-microsoft-com:xml-msdata")) { s = attrs[i].Value; } } } int index = (int) Convert.ChangeType(str4, typeof(int), null); if ((column.Expression != null) && (column.Expression.Length != 0)) { this.ColumnExpressions.Add(column); } if (((type != null) && (type.Name != null)) && (type.Name.Length > 0)) { if (GetMsdataAttribute(typeNode, "targetNamespace") != null) { column.XmlDataType = type.SimpleTypeQualifiedName; } } else { column.XmlDataType = strType; } column.SimpleType = type; if (flag) { if (this.FromInference) { column.Prefix = this.GetPrefix(table.Namespace); column.AllowDBNull = true; } if ((index > -1) && (index < table.Columns.Count)) { table.Columns.AddAt(index, column); } else { table.Columns.Add(column); } } if (s != null) { try { column.DefaultValue = column.ConvertXmlToObject(s); } catch (FormatException) { throw ExceptionBuilder.CannotConvert(s, dataType.FullName); } } } }