2 // ServiceDocumentFormatter.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2009 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.Collections.Generic;
31 using System.Runtime.Serialization;
32 using System.ServiceModel;
33 using System.ServiceModel.Channels;
36 namespace System.ServiceModel.Syndication
39 public abstract class ServiceDocumentFormatter
41 protected static SyndicationCategory CreateCategory (InlineCategoriesDocument inlineCategories)
43 return inlineCategories.CreateCategory ();
46 protected static ResourceCollectionInfo CreateCollection (Workspace workspace)
48 return workspace.CreateResourceCollection ();
51 protected static InlineCategoriesDocument CreateInlineCategories (ResourceCollectionInfo collection)
53 return collection.CreateInlineCategoriesDocument ();
56 protected static ReferencedCategoriesDocument CreateReferencedCategories (ResourceCollectionInfo collection)
58 return collection.CreateReferencedCategoriesDocument ();
61 protected static Workspace CreateWorkspace (ServiceDocument document)
63 return document.CreateWorkspace ();
66 [MonoTODO ("Use maxExtensionSize somewhere")]
67 protected static void LoadElementExtensions (XmlReader reader, CategoriesDocument categories, int maxExtensionSize)
69 categories.ElementExtensions.Add (reader);
72 [MonoTODO ("Use maxExtensionSize somewhere")]
73 protected static void LoadElementExtensions (XmlReader reader,ResourceCollectionInfo collection, int maxExtensionSize)
75 collection.ElementExtensions.Add (reader);
78 [MonoTODO ("Use maxExtensionSize somewhere")]
79 protected static void LoadElementExtensions (XmlReader reader, ServiceDocument document, int maxExtensionSize)
81 document.ElementExtensions.Add (reader);
84 [MonoTODO ("Use maxExtensionSize somewhere")]
85 protected static void LoadElementExtensions (XmlReader reader, Workspace workspace, int maxExtensionSize)
87 workspace.ElementExtensions.Add (reader);
90 protected static bool TryParseAttribute (string name, string ns, string value, CategoriesDocument categories, string version)
92 return categories.TryParseAttribute (name, ns, value, version);
95 protected static bool TryParseAttribute (string name, string ns, string value, ResourceCollectionInfo collection, string version)
97 return collection.TryParseAttribute (name, ns, value, version);
100 protected static bool TryParseAttribute (string name, string ns, string value, ServiceDocument document, string version)
102 return document.TryParseAttribute (name, ns, value, version);
105 protected static bool TryParseAttribute (string name, string ns, string value, Workspace workspace, string version)
107 return workspace.TryParseAttribute (name, ns, value, version);
110 protected static bool TryParseElement (XmlReader reader, CategoriesDocument categories, string version)
112 return categories.TryParseElement (reader, version);
115 protected static bool TryParseElement (XmlReader reader, ResourceCollectionInfo collection, string version)
117 return collection.TryParseElement (reader, version);
120 protected static bool TryParseElement (XmlReader reader, ServiceDocument document, string version)
122 return document.TryParseElement (reader, version);
125 protected static bool TryParseElement (XmlReader reader, Workspace workspace, string version)
127 return workspace.TryParseElement (reader, version);
130 protected static void WriteAttributeExtensions (XmlWriter writer, CategoriesDocument categories, string version)
132 categories.WriteAttributeExtensions (writer, version);
135 protected static void WriteAttributeExtensions (XmlWriter writer, ResourceCollectionInfo collection, string version)
137 collection.WriteAttributeExtensions (writer, version);
140 protected static void WriteAttributeExtensions (XmlWriter writer, ServiceDocument document, string version)
142 document.WriteAttributeExtensions (writer, version);
145 protected static void WriteAttributeExtensions (XmlWriter writer, Workspace workspace, string version)
147 workspace.WriteAttributeExtensions (writer, version);
150 protected static void WriteElementExtensions (XmlWriter writer, CategoriesDocument categories, string version)
152 categories.WriteElementExtensions (writer, version);
155 protected static void WriteElementExtensions (XmlWriter writer, ResourceCollectionInfo collection, string version)
157 collection.WriteElementExtensions (writer, version);
160 protected static void WriteElementExtensions (XmlWriter writer, ServiceDocument document, string version)
162 document.WriteElementExtensions (writer, version);
165 protected static void WriteElementExtensions (XmlWriter writer, Workspace workspace, string version)
167 workspace.WriteElementExtensions (writer, version);
172 protected ServiceDocumentFormatter ()
173 : this (new ServiceDocument ())
177 protected ServiceDocumentFormatter (ServiceDocument documentToWrite)
179 SetDocument (documentToWrite);
182 public ServiceDocument Document { get; private set; }
184 public abstract string Version { get; }
187 public abstract bool CanRead (XmlReader reader);
189 protected virtual ServiceDocument CreateDocumentInstance ()
191 return new ServiceDocument () { InternalFormatter = this };
194 public abstract void ReadFrom (XmlReader reader);
196 protected virtual void SetDocument (ServiceDocument document)
198 if (document == null)
199 throw new ArgumentNullException ("document");
203 public abstract void WriteTo (XmlWriter writer);