fd1a81d1cf9c7b8a22bfd18cf311395b9604ef96
[mono.git] / mcs / class / System.Runtime.Serialization / System.Runtime.Serialization / XmlObjectSerializer.cs
1 //
2 // XmlObjectSerializer.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 #if NET_2_0
29 using System;
30 using System.Collections;
31 using System.IO;
32 using System.Reflection;
33 using System.Runtime.Serialization.Formatters.Binary;
34 using System.Xml;
35 using System.Xml.Schema;
36
37 using QName = System.Xml.XmlQualifiedName;
38
39 namespace System.Runtime.Serialization
40 {
41         public abstract class XmlObjectSerializer
42         {
43                 internal const string DefaultNamespaceBase =
44                         "http://schemas.datacontract.org/2004/07/";
45
46                 // This is only for compatible mode.
47                 IDataContractSurrogate surrogate;
48
49                 SerializationBinder binder;
50                 ISurrogateSelector selector;
51
52                 int max_items = 0x10000; // FIXME: could be from config.
53
54                 protected XmlObjectSerializer ()
55                 {
56                 }
57
58                 public virtual bool IsStartObject (XmlReader reader)
59                 {
60                         return IsStartObject (XmlDictionaryReader.CreateDictionaryReader (reader));
61                 }
62
63                 public abstract bool IsStartObject (XmlDictionaryReader reader);
64
65                 public virtual object ReadObject (Stream stream)
66                 {
67                         return ReadObject (XmlReader.Create (stream));
68                 }
69
70                 public virtual object ReadObject (XmlReader reader)
71                 {
72                         return ReadObject (XmlDictionaryReader.CreateDictionaryReader (reader));
73                 }
74
75                 public virtual object ReadObject (XmlDictionaryReader reader)
76                 {
77                         return ReadObject (reader, true);
78                 }
79
80                 public virtual object ReadObject (XmlReader reader, bool readContentOnly)
81                 {
82                         return ReadObject (
83                                 XmlDictionaryReader.CreateDictionaryReader (reader),
84                                 readContentOnly);
85                 }
86
87                 [MonoTODO]
88                 public abstract object ReadObject (XmlDictionaryReader reader, bool readContentOnly);
89
90                 public virtual void WriteObject (Stream stream, object graph)
91                 {
92                         using (XmlWriter xw = XmlDictionaryWriter.CreateTextWriter (stream)) {
93                                 WriteObject (xw, graph);
94                         }
95                 }
96
97                 public virtual void WriteObject (XmlWriter writer, object graph)
98                 {
99                         WriteObject (XmlDictionaryWriter.CreateDictionaryWriter (writer), graph);
100                 }
101
102                 public virtual void WriteStartObject (XmlWriter writer, object graph)
103                 {
104                         WriteStartObject (XmlDictionaryWriter.CreateDictionaryWriter (writer), graph);
105                 }
106
107                 public virtual void WriteObject (XmlDictionaryWriter writer, object graph)
108                 {
109                         WriteStartObject (writer, graph);
110                         WriteObjectContent (writer, graph);
111                         WriteEndObject (writer);
112                 }
113
114                 public abstract void WriteStartObject (
115                         XmlDictionaryWriter writer, object graph);
116
117                 public virtual void WriteObjectContent (XmlWriter writer, object graph)
118                 {
119                         WriteObjectContent (
120                                 XmlDictionaryWriter.CreateDictionaryWriter (writer),
121                                 graph);
122                 }
123
124                 public abstract void WriteObjectContent (
125                         XmlDictionaryWriter writer, object graph);
126
127                 public virtual void WriteEndObject (XmlWriter writer)
128                 {
129                         WriteEndObject (XmlDictionaryWriter.CreateDictionaryWriter (writer));
130                 }
131
132                 public abstract void WriteEndObject (
133                         XmlDictionaryWriter writer);
134         }
135 }
136 #endif