the 2001 one when reading the xsi type.
* MapCodeGenerator.cs: Take into account that the root namespace and element
name may have changed from one export to another of the same type. In
this case the class attributes need to be regenerated.
* SoapCodeExporter.cs, XmlCodeExporter.cs: Take the enum name from XmlType,
not ElementName. Idem for namespace.
* XmlReflectionImporter.cs: Set nullable property of XmlTypeMapping.
* XmlRootAttribute.cs: Default value for nullable is true.
* XmlSchemaImporter.cs: The root name for a class may change in some
scenarios (for example, when the type is initially exported as part of
another type and later exported as a root type).
* XmlSerializationReader.cs: In GetXsiType(), if the type attribute is not
found using the standard namespace, try getting the type using
the 2000/10 and 1999 namespaces.
* XmlTypeMapping.cs: Added IsNullable property. Updated SetRoot method.
svn path=/trunk/mcs/; revision=28711
+2004-06-02 Lluis Sanchez Gual <lluis@ximian.com>
+
+ * XmlSerializationReader.cs: Support schamea instance namespaces other than
+ the 2001 one when reading the xsi type.
+ * MapCodeGenerator.cs: Take into account that the root namespace and element
+ name may have changed from one export to another of the same type. In
+ this case the class attributes need to be regenerated.
+ * SoapCodeExporter.cs, XmlCodeExporter.cs: Take the enum name from XmlType,
+ not ElementName. Idem for namespace.
+ * XmlReflectionImporter.cs: Set nullable property of XmlTypeMapping.
+ * XmlRootAttribute.cs: Default value for nullable is true.
+ * XmlSchemaImporter.cs: The root name for a class may change in some
+ scenarios (for example, when the type is initially exported as part of
+ another type and later exported as a root type).
+ * XmlSerializationReader.cs: In GetXsiType(), if the type attribute is not
+ found using the standard namespace, try getting the type using
+ the 2000/10 and 1999 namespaces.
+ * XmlTypeMapping.cs: Added IsNullable property. Updated SetRoot method ;-)
+
2004-05-26 Lluis Sanchez Gual <lluis@ximian.com>
* SerializationCodeGenerator.cs, XmlSerializationReaderInterpreter.cs:
void ExportClassCode (XmlTypeMapping map)
{
- if (IsMapExported (map)) return;
- SetMapExported (map);
+ CodeTypeDeclaration codeClass;
+
+ if (IsMapExported (map)) {
+ // Regenerate attributes, since things may have changed
+ codeClass = GetMapDeclaration (map);
+ if (codeClass != null) {
+ codeClass.CustomAttributes = null;
+ GenerateClass (map, codeClass);
+ ExportDerivedTypes (map, codeClass, true);
+ }
+ return;
+ }
if (map.TypeData.Type == typeof(object))
{
exportedAnyType = map;
+ SetMapExported (map, null);
return;
}
- CodeTypeDeclaration codeClass = new CodeTypeDeclaration (map.TypeData.TypeName);
+ codeClass = new CodeTypeDeclaration (map.TypeData.TypeName);
+ SetMapExported (map, codeClass);
+
AddCodeType (codeClass, map.Documentation);
codeClass.Attributes = MemberAttributes.Public;
ExportMapCode (map.BaseMap);
}
- ExportDerivedTypes (map, codeClass);
+ ExportDerivedTypes (map, codeClass, false);
}
- void ExportDerivedTypes (XmlTypeMapping map, CodeTypeDeclaration codeClass)
+ void ExportDerivedTypes (XmlTypeMapping map, CodeTypeDeclaration codeClass, bool onlyIncludes)
{
foreach (XmlTypeMapping tm in map.DerivedTypes)
{
codeClass.CustomAttributes = new CodeAttributeDeclarationCollection ();
GenerateClassInclude (codeClass.CustomAttributes, tm);
- ExportMapCode (tm);
- ExportDerivedTypes (tm, codeClass);
+ if (!onlyIncludes) ExportMapCode (tm);
+ ExportDerivedTypes (tm, codeClass, onlyIncludes);
}
}
void ExportEnumCode (XmlTypeMapping map)
{
if (IsMapExported (map)) return;
- SetMapExported (map);
CodeTypeDeclaration codeEnum = new CodeTypeDeclaration (map.TypeData.TypeName);
+ SetMapExported (map, codeEnum);
+
codeEnum.Attributes = MemberAttributes.Public;
codeEnum.IsEnum = true;
AddCodeType (codeEnum, map.Documentation);
return false;
}
- void SetMapExported (XmlTypeMapping map)
+ void SetMapExported (XmlTypeMapping map, CodeTypeDeclaration declaration)
+ {
+ exportedMaps.Add (map.TypeData.FullTypeName, declaration);
+ }
+
+ CodeTypeDeclaration GetMapDeclaration (XmlTypeMapping map)
{
- exportedMaps.Add (map.TypeData.FullTypeName, map);
+ return exportedMaps [map.TypeData.FullTypeName] as CodeTypeDeclaration;
}
public static void AddCustomAttribute (CodeTypeMember ctm, CodeAttributeDeclaration att, bool addIfNoParams)
protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)\r
{\r
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapType");\r
- if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.ElementName));\r
- if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));\r
+ if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.XmlType));\r
+ if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));\r
AddCustomAttribute (codeEnum, att, false);\r
} \r
\r
protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)\r
{\r
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlTypeAttribute");\r
- if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.ElementName));\r
- if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));\r
+ if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.XmlType));\r
+ if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));\r
AddCustomAttribute (codeEnum, att, false);\r
} \r
\r
{
string rootNamespace = defaultNamespace;
string typeNamespace = null;
-
string elementName;
bool includeInSchema = true;
XmlAttributes atts = null;
+ bool nullable = true;
+
if (defaultXmlType == null) defaultXmlType = typeData.XmlType;
if (!typeData.IsListType)
elementName = root.ElementName;
if (root.Namespace != null && root.Namespace != String.Empty)
rootNamespace = root.Namespace;
+ nullable = root.IsNullable;
}
if (rootNamespace == null) rootNamespace = "";
{\r
private string dataType;\r
private string elementName;\r
- private bool isNullable;\r
+ private bool isNullable = true;\r
private string ns;\r
\r
public XmlRootAttribute ()\r
// has the requested base type\r
\r
SetMapBaseType (map, baseType);\r
- map.SetRoot (name);\r
+ map.UpdateRoot (name);\r
return map;\r
}\r
\r
\r
XmlQualifiedName typeQName = new XmlQualifiedName ("Message", names[n].Namespace);\r
XmlTypeMapping tmap;\r
- TypeData td = GetElementTypeData (typeQName, elem, out tmap);\r
+ TypeData td = GetElementTypeData (typeQName, elem, names[n], out tmap);\r
\r
mapping[n] = ImportMemberMapping (elem.Name, typeQName.Namespace, elem.IsNillable, td, tmap);\r
}\r
XmlTypeMapping ImportType (XmlQualifiedName name, XmlQualifiedName root)\r
{\r
XmlTypeMapping map = GetRegisteredTypeMapping (name);\r
- if (map != null) return map;\r
+ if (map != null) {\r
+ map.UpdateRoot (root);\r
+ return map;\r
+ }\r
\r
XmlSchemaType type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaComplexType));\r
if (type == null) type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaSimpleType));\r
XmlTypeMapping map = GetRegisteredTypeMapping (name);\r
if (map != null) {\r
XmlSchemaComplexType ct = stype as XmlSchemaComplexType;\r
- if (map.TypeData.SchemaType != SchemaTypes.Class || ct == null || !CanBeArray (name, ct))\r
+ if (map.TypeData.SchemaType != SchemaTypes.Class || ct == null || !CanBeArray (name, ct)) {\r
+ map.UpdateRoot (root);\r
return map;\r
+ }\r
\r
// The map was initially imported as a class, but it turns out that it is an\r
// array. It has to be imported now as array.\r
string ns;\r
XmlSchemaElement elem = (XmlSchemaElement) item;\r
XmlTypeMapping emap;\r
- TypeData typeData = GetElementTypeData (typeQName, elem, out emap);\r
+ TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);\r
XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);\r
\r
if (elem.MaxOccurs == 1 && !multiValue)\r
string ns;\r
XmlSchemaElement elem = (XmlSchemaElement) item;\r
XmlTypeMapping emap;\r
- TypeData typeData = GetElementTypeData (typeQName, elem, out emap);\r
+ TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);\r
XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);\r
choices.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap));\r
if (elem.MaxOccurs > 1) multiValue = true;\r
}\r
}\r
\r
- TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, out XmlTypeMapping map)\r
+ TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, XmlQualifiedName root, out XmlTypeMapping map)\r
{\r
bool sharedAnnType = false;\r
- XmlQualifiedName root = null;\r
map = null;\r
\r
if (!elem.RefName.IsEmpty) {\r
protected XmlQualifiedName GetXsiType ()
{
string typeName = Reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
- if (typeName == string.Empty || typeName == null) return null;
+
+ if (typeName == string.Empty || typeName == null) {
+ typeName = Reader.GetAttribute ("type", w3InstanceNS1999);
+ if (typeName == string.Empty || typeName == null) {
+ typeName = Reader.GetAttribute ("type", w3InstanceNS2000);
+ if (typeName == string.Empty || typeName == null)
+ return null;
+ }
+ }
+
int i = typeName.IndexOf (":");
if (i == -1) return new XmlQualifiedName (typeName, Reader.NamespaceURI);
else
bool isSimpleType;\r
string documentation;\r
bool includeInSchema;\r
+ bool isNullable = true;\r
\r
ArrayList _derivedTypes = new ArrayList();\r
\r
get { return includeInSchema; }\r
set { includeInSchema = value; }\r
}\r
+ \r
+ internal bool IsNullable\r
+ {\r
+ get { return isNullable; }\r
+ set { isNullable = value; }\r
+ }\r
\r
internal XmlTypeMapping GetRealTypeMap (string objectFullTypeName)\r
{\r
return null;\r
}\r
\r
- internal void SetRoot (XmlQualifiedName qname)\r
+ internal void UpdateRoot (XmlQualifiedName qname)\r
{\r
- this.elementName = qname.Name;\r
- this.ns = qname.Namespace;\r
+ if (qname != null) {\r
+ this.elementName = qname.Name;\r
+ this.ns = qname.Namespace;\r
+ }\r
}\r
}\r
\r