Author: lluis
Date: 2005-03-08 06:58:25 -0500 (Tue, 08 Mar 2005)
New Revision: 41562
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
Log:
2005-03-08 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* XmlSchemaImporter.cs: Support importing schemas that define
extra types in the standard xml schema namespace. When using encoded
format, support the primitive types defined by the SOAP encoding
namespace.
Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2005-03-08 11:53:54 UTC (rev 41561)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2005-03-08 11:58:25 UTC (rev 41562)
@@ -1,3 +1,10 @@
+2005-03-08 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * XmlSchemaImporter.cs: Support importing schemas that define
+ extra types in the standard xml schema namespace. When using encoded
+ format, support the primitive types defined by the SOAP encoding
+ namespace.
+
2005-03-04 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* ReflectionHelper.cs: Avoid endless loop.
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
2005-03-08 11:53:54 UTC (rev 41561)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
2005-03-08 11:58:25 UTC (rev 41562)
@@ -277,9 +277,11 @@
else
{
if (elem.SchemaTypeName.IsEmpty) return null;
- if (elem.SchemaTypeName.Namespace ==
XmlSchema.Namespace) return null;
object type = schemas.Find
(elem.SchemaTypeName, typeof (XmlSchemaComplexType));
- if (type == null) throw new
InvalidOperationException ("Schema type '" + elem.SchemaTypeName + "' not
found");
+ if (type == null) {
+ if (IsPrimitiveTypeNamespace
(elem.SchemaTypeName.Namespace)) return null;
+ throw new InvalidOperationException
("Schema type '" + elem.SchemaTypeName + "' not found");
+ }
stype = type as XmlSchemaComplexType;
}
@@ -443,14 +445,15 @@
{
if (elem.SchemaTypeName.IsEmpty) return false;
- if (elem.SchemaTypeName.Namespace ==
XmlSchema.Namespace) {
- qname = elem.SchemaTypeName;
- return true;
- }
-
object type = schemas.Find
(elem.SchemaTypeName, typeof (XmlSchemaComplexType));
if (type == null) type = schemas.Find
(elem.SchemaTypeName, typeof (XmlSchemaSimpleType));
- if (type == null) throw new
InvalidOperationException ("Schema type '" + elem.SchemaTypeName + "' not
found");
+ if (type == null) {
+ if (IsPrimitiveTypeNamespace
(elem.SchemaTypeName.Namespace)) {
+ qname = elem.SchemaTypeName;
+ return true;
+ }
+ throw new InvalidOperationException
("Schema type '" + elem.SchemaTypeName + "' not found");
+ }
stype = (XmlSchemaType) type;
qname = stype.QualifiedName;
@@ -463,7 +466,7 @@
return true;
}
- XmlTypeMapping ImportType (XmlQualifiedName name,
XmlQualifiedName root)
+ XmlTypeMapping ImportType (XmlQualifiedName name,
XmlQualifiedName root, bool throwOnError)
{
XmlTypeMapping map = GetRegisteredTypeMapping (name);
if (map != null) {
@@ -476,10 +479,13 @@
if (type == null)
{
- if (name.Namespace ==
XmlSerializer.EncodingNamespace)
- throw new InvalidOperationException
("Referenced type '" + name + "' valid only for encoded SOAP");
- else
- throw new InvalidOperationException
("Referenced type '" + name + "' not found");
+ if (throwOnError) {
+ if (name.Namespace ==
XmlSerializer.EncodingNamespace)
+ throw new
InvalidOperationException ("Referenced type '" + name + "' valid only for
encoded SOAP.");
+ else
+ throw new
InvalidOperationException ("Referenced type '" + name + "' not found.");
+ } else
+ return null;
}
return ImportType (name, type, root);
@@ -487,7 +493,7 @@
XmlTypeMapping ImportClass (XmlQualifiedName name)
{
- XmlTypeMapping map = ImportType (name, null);
+ XmlTypeMapping map = ImportType (name, null, true);
if (map.TypeData.SchemaType == SchemaTypes.Class)
return map;
XmlSchemaComplexType stype = schemas.Find (name, typeof
(XmlSchemaComplexType)) as XmlSchemaComplexType;
return CreateClassMap (name, stype, new
XmlQualifiedName (map.ElementName, map.Namespace));
@@ -1074,11 +1080,11 @@
ClassMap cmap = (ClassMap)map.ObjectMap;
XmlQualifiedName qname = GetContentBaseType
(content.Content);
- if (qname.Namespace != XmlSchema.Namespace)
+ if (!IsPrimitiveTypeNamespace (qname.Namespace))
{
// Add base map members to this map
- XmlTypeMapping baseMap = ImportType (qname,
null);
+ XmlTypeMapping baseMap = ImportType (qname,
null, true);
BuildPendingMap (baseMap);
ClassMap baseClassMap =
(ClassMap)baseMap.ObjectMap;
@@ -1104,9 +1110,6 @@
TypeData FindBuiltInType (XmlQualifiedName qname)
{
- if (qname.Namespace == XmlSchema.Namespace)
- return TypeTranslator.GetPrimitiveTypeData
(qname.Name);
-
XmlSchemaComplexType ct = (XmlSchemaComplexType)
schemas.Find (qname, typeof(XmlSchemaComplexType));
if (ct != null)
{
@@ -1119,13 +1122,16 @@
if (st != null)
return FindBuiltInType (qname, st);
+ if (IsPrimitiveTypeNamespace (qname.Namespace))
+ return TypeTranslator.GetPrimitiveTypeData
(qname.Name);
+
throw new InvalidOperationException ("Definition of
type " + qname + " not found");
}
TypeData FindBuiltInType (XmlQualifiedName qname,
XmlSchemaSimpleType st)
{
if (CanBeEnum (st))
- return ImportType (qname, null).TypeData;
+ return ImportType (qname, null, true).TypeData;
if (st.Content is XmlSchemaSimpleTypeRestriction) {
return FindBuiltInType (GetContentBaseType
(st.Content));
@@ -1393,7 +1399,7 @@
// xml types can be mapped to a single CLR type
string t;
- if (type.Namespace == XmlSchema.Namespace)
+ if (IsPrimitiveTypeNamespace (type.Namespace))
t = TypeTranslator.GetPrimitiveTypeData
(type.Name).FullTypeName + ":" + type.Namespace;
else
@@ -1609,10 +1615,16 @@
TypeData GetTypeData (XmlQualifiedName typeQName,
XmlQualifiedName root)
{
- if (typeQName.Namespace == XmlSchema.Namespace ||
(encodedFormat && typeQName.Namespace == ""))
+ if (IsPrimitiveTypeNamespace (typeQName.Namespace)) {
+ XmlTypeMapping map = ImportType (typeQName,
root, false);
+ if (map != null) return map.TypeData;
+ else return TypeTranslator.GetPrimitiveTypeData
(typeQName.Name);
+ }
+
+ if (encodedFormat && typeQName.Namespace == "")
return TypeTranslator.GetPrimitiveTypeData
(typeQName.Name);
- return ImportType (typeQName, root).TypeData;
+ return ImportType (typeQName, root, true).TypeData;
}
TypeData GetTypeData (XmlSchemaType stype, XmlQualifiedName
typeQNname, string propertyName, bool sharedAnnType, XmlQualifiedName root)
@@ -1723,15 +1735,18 @@
XmlSchemaElement FindRefElement (XmlSchemaElement elem)
{
- if (elem.RefName.Namespace == XmlSchema.Namespace)
+ XmlSchemaElement refelem = (XmlSchemaElement)
schemas.Find (elem.RefName, typeof(XmlSchemaElement));
+ if (refelem != null) return refelem;
+
+ if (IsPrimitiveTypeNamespace (elem.RefName.Namespace))
{
if (anyElement != null) return anyElement;
anyElement = new XmlSchemaElement ();
anyElement.Name = "any";
anyElement.SchemaTypeName = anyType;
return anyElement;
- }
- return (XmlSchemaElement) schemas.Find (elem.RefName,
typeof(XmlSchemaElement));
+ } else
+ return null;
}
XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
@@ -1789,6 +1804,11 @@
}
return res;
}
+
+ bool IsPrimitiveTypeNamespace (string ns)
+ {
+ return (ns == XmlSchema.Namespace) || (encodedFormat &&
ns == XmlSerializer.EncodingNamespace);
+ }
#endregion // Methods
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches