提交 742f259d 编写于 作者: A Atsushi Eno

Remove old code.

上级 bf7e68c3
......@@ -157,110 +157,6 @@ namespace System.Runtime.Serialization
return (Type.GetTypeCode (type) != TypeCode.Object || type == typeof (object));
}
#if !NET_2_1
/* Returns the XmlSchemaType AND adds it to @schemas */
public virtual XmlSchemaType GetSchemaType (XmlSchemaSet schemas, Dictionary<QName, XmlSchemaType> generated_schema_types)
{
if (IsPrimitive (RuntimeType))
return null;
if (generated_schema_types.ContainsKey (XmlName)) // Caching
return generated_schema_types [XmlName] as XmlSchemaType;
XmlSchemaComplexType complex_type = null;
complex_type = new XmlSchemaComplexType ();
complex_type.Name = XmlName.Name;
generated_schema_types [XmlName] = complex_type;
if (RuntimeType.BaseType == typeof (object)) {
complex_type.Particle = GetSequence (schemas, generated_schema_types);
} else {
//Has a non-System.Object base class
XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension ();
XmlSchemaComplexContent content = new XmlSchemaComplexContent ();
complex_type.ContentModel = content;
content.Content = extension;
KnownTypes.Add (RuntimeType.BaseType);
SerializationMap map = KnownTypes.FindUserMap (RuntimeType.BaseType);
//FIXME: map == null ?
map.GetSchemaType (schemas, generated_schema_types);
extension.Particle = GetSequence (schemas, generated_schema_types);
extension.BaseTypeName = GetQualifiedName (RuntimeType.BaseType);
}
XmlSchemaElement schemaElement = GetSchemaElement (XmlName, complex_type);
XmlSchema schema = GetSchema (schemas, XmlName.Namespace);
schema.Items.Add (complex_type);
schema.Items.Add (schemaElement);
schemas.Reprocess (schema);
return complex_type;
}
/* Returns the <xs:sequence> for the data members */
XmlSchemaSequence GetSequence (XmlSchemaSet schemas,
Dictionary<QName, XmlSchemaType> generated_schema_types)
{
List<DataMemberInfo> members = GetMembers ();
XmlSchema schema = GetSchema (schemas, XmlName.Namespace);
XmlSchemaSequence sequence = new XmlSchemaSequence ();
foreach (DataMemberInfo dmi in members) {
// delegates are not supported.
if (!dmi.MemberType.IsAbstract && typeof (System.Delegate).IsAssignableFrom (dmi.MemberType))
continue;
XmlSchemaElement element = new XmlSchemaElement ();
element.Name = dmi.XmlName;
KnownTypes.Add (dmi.MemberType);
SerializationMap map = KnownTypes.FindUserMap (dmi.MemberType);
if (map != null) {
XmlSchemaType schema_type = map.GetSchemaType (schemas, generated_schema_types);
if (schema_type is XmlSchemaComplexType)
element.IsNillable = true;
} else {
//Primitive type
if (dmi.MemberType == typeof (string))
element.IsNillable = true;
}
element.MinOccurs = 0;
element.SchemaTypeName = GetQualifiedName (dmi.MemberType);
AddImport (schema, element.SchemaTypeName.Namespace);
sequence.Items.Add (element);
}
schemas.Reprocess (schema);
return sequence;
}
//FIXME: Replace with a dictionary ?
void AddImport (XmlSchema schema, string ns)
{
if (ns == XmlSchema.Namespace || schema.TargetNamespace == ns)
return;
foreach (XmlSchemaObject o in schema.Includes) {
XmlSchemaImport import = o as XmlSchemaImport;
if (import == null)
continue;
if (import.Namespace == ns)
return;
}
XmlSchemaImport imp = new XmlSchemaImport ();
imp.Namespace = ns;
schema.Includes.Add (imp);
}
#endif
//Returns list of data members for this type ONLY
public virtual List<DataMemberInfo> GetMembers ()
{
......@@ -513,14 +409,6 @@ namespace System.Runtime.Serialization
ixs.ReadXml (reader);
return ixs;
}
#if !NET_2_1
// FIXME: verify return value sanity.
public override XmlSchemaType GetSchemaType (XmlSchemaSet schemas, Dictionary<QName, XmlSchemaType> generated_schema_types)
{
return null;
}
#endif
}
internal partial class SharedContractMap : SerializationMap
......@@ -777,50 +665,6 @@ namespace System.Runtime.Serialization
//Shouldn't come here at all!
throw new NotImplementedException ();
}
#if !NET_2_1
public override XmlSchemaType GetSchemaType (XmlSchemaSet schemas, Dictionary<QName, XmlSchemaType> generated_schema_types)
{
if (generated_schema_types.ContainsKey (XmlName))
return null;
if (generated_schema_types.ContainsKey (XmlName))
return generated_schema_types [XmlName];
QName element_qname = GetQualifiedName (element_type);
XmlSchemaComplexType complex_type = new XmlSchemaComplexType ();
complex_type.Name = XmlName.Name;
XmlSchemaSequence sequence = new XmlSchemaSequence ();
XmlSchemaElement element = new XmlSchemaElement ();
element.MinOccurs = 0;
element.MaxOccursString = "unbounded";
element.Name = element_qname.Name;
KnownTypes.Add (element_type);
SerializationMap map = KnownTypes.FindUserMap (element_type);
if (map != null) {// non-primitive type
map.GetSchemaType (schemas, generated_schema_types);
element.IsNillable = true;
}
element.SchemaTypeName = element_qname;
sequence.Items.Add (element);
complex_type.Particle = sequence;
XmlSchema schema = GetSchema (schemas, XmlName.Namespace);
schema.Items.Add (complex_type);
schema.Items.Add (GetSchemaElement (XmlName, complex_type));
schemas.Reprocess (schema);
generated_schema_types [XmlName] = complex_type;
return complex_type;
}
#endif
}
internal partial class DictionaryTypeMap : SerializationMap, ICollectionTypeMap
......@@ -1018,13 +862,6 @@ namespace System.Runtime.Serialization
//Shouldn't come here at all!
throw new NotImplementedException ();
}
#if !NET_2_1
public override XmlSchemaType GetSchemaType (XmlSchemaSet schemas, Dictionary<QName, XmlSchemaType> generated_schema_types)
{
throw new NotImplementedException ();
}
#endif
}
internal partial class SharedTypeMap : SerializationMap
......@@ -1117,38 +954,6 @@ namespace System.Runtime.Serialization
return (EnumMemberAttribute) atts [0];
}
#if !NET_2_1
public override XmlSchemaType GetSchemaType (XmlSchemaSet schemas, Dictionary<QName, XmlSchemaType> generated_schema_types)
{
if (generated_schema_types.ContainsKey (XmlName))
return generated_schema_types [XmlName];
XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType ();
simpleType.Name = XmlName.Name;
XmlSchemaSimpleTypeRestriction simpleRestriction = new XmlSchemaSimpleTypeRestriction ();
simpleType.Content = simpleRestriction;
simpleRestriction.BaseTypeName = new XmlQualifiedName ("string", XmlSchema.Namespace);
foreach (EnumMemberInfo emi in enum_members) {
XmlSchemaEnumerationFacet e = new XmlSchemaEnumerationFacet ();
e.Value = emi.XmlName;
simpleRestriction.Facets.Add (e);
}
generated_schema_types [XmlName] = simpleType;
XmlSchema schema = GetSchema (schemas, XmlName.Namespace);
XmlSchemaElement element = GetSchemaElement (XmlName, simpleType);
element.IsNillable = true;
schema.Items.Add (simpleType);
schema.Items.Add (element);
return simpleType;
}
#endif
public override void Serialize (object graph,
XmlFormatterSerializer serializer)
{
......
//
// XsdDataContractExporter.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
// Ankit Jain <JAnkit@novell.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Schema;
using QName = System.Xml.XmlQualifiedName;
namespace System.Runtime.Serialization
{
public class XsdDataContractExporter
{
ExportOptions options;
KnownTypeCollection known_types;
XmlSchemaSet schemas;
Dictionary<QName, XmlSchemaType> generated_schema_types;
static XmlSchema mstypes_schema;
public XsdDataContractExporter ()
{
}
public XsdDataContractExporter (XmlSchemaSet schemas)
{
this.schemas = schemas;
}
public XmlSchemaSet Schemas {
get {
if (schemas == null) {
schemas = new XmlSchemaSet ();
schemas.Add (MSTypesSchema);
}
return schemas;
}
}
public ExportOptions Options {
get { return options; }
set { options = value; }
}
public bool CanExport (ICollection<Type> types)
{
foreach (Type t in types)
if (!CanExport (t))
return false;
return true;
}
public bool CanExport (ICollection<Assembly> assemblies)
{
foreach (Assembly a in assemblies)
foreach (Module m in a.GetModules ())
foreach (Type t in m.GetTypes ())
if (!CanExport (t))
return false;
return true;
}
public bool CanExport (Type type)
{
return !KnownTypes.GetQName (type).IsEmpty;
}
public void Export (ICollection<Type> types)
{
foreach (Type t in types)
Export (t);
}
public void Export (ICollection<Assembly> assemblies)
{
foreach (Assembly a in assemblies)
foreach (Module m in a.GetModules ())
foreach (Type t in m.GetTypes ())
Export (t);
}
[MonoTODO]
public void Export (Type type)
{
//FIXME: Which types to exclude?
KnownTypes.Add (type);
SerializationMap map = KnownTypes.FindUserMap (type);
if (map == null)
return;
map.GetSchemaType (Schemas, GeneratedTypes);
Schemas.Compile ();
}
[MonoTODO]
public XmlQualifiedName GetRootElementName (Type type)
{
throw new NotImplementedException ();
}
[MonoTODO]
public XmlSchemaType GetSchemaType (Type type)
{
SerializationMap map = KnownTypes.FindUserMap (type);
if (map == null)
return null;
return map.GetSchemaType (Schemas, GeneratedTypes);
}
public XmlQualifiedName GetSchemaTypeName (Type type)
{
QName qname = KnownTypes.GetQName (type);
if (qname.Namespace == KnownTypeCollection.MSSimpleNamespace)
//primitive type, mapping to XmlSchema ns
return new QName (qname.Name, XmlSchema.Namespace);
return qname;
}
KnownTypeCollection KnownTypes {
get {
if (known_types == null)
known_types = new KnownTypeCollection ();
return known_types;
}
}
Dictionary<QName, XmlSchemaType> GeneratedTypes {
get {
if (generated_schema_types == null)
generated_schema_types = new Dictionary<QName, XmlSchemaType> ();
return generated_schema_types;
}
}
static XmlSchema MSTypesSchema {
get {
if (mstypes_schema == null) {
Assembly a = Assembly.GetCallingAssembly ();
Stream s = a.GetManifestResourceStream ("mstypes.schema");
mstypes_schema= XmlSchema.Read (s, null);
}
return mstypes_schema;
}
}
}
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册