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 (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 (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);
}
}