2010-04-15 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Web.Services / System.Web.Services.Description / WebReferenceOptions.cs
blob42bbdddb141289a6dd726aa06ffc71839207d16e
1 //
2 // WebReferenceOptions.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #if NET_2_0
33 using System;
34 using System.ComponentModel;
35 using System.IO;
36 using System.Collections.Specialized;
37 using System.Web.Services;
38 using System.Xml;
39 using System.Xml.Schema;
40 using System.Xml.Serialization;
42 namespace System.Web.Services.Description
44 [XmlRoot ("webReferenceOptions", Namespace = "http://microsoft.com/webReference/")]
45 [XmlType ("webReferenceOptions", Namespace = "http://microsoft.com/webReference/")]
46 public class WebReferenceOptions
48 #region Static members
49 static XmlSchema schema;
50 static XmlSerializerImplementation implementation =
51 new WebReferenceOptionsSerializerImplementation ();
53 public const string TargetNamespace = "http://microsoft.com/webReference/";
55 public static XmlSchema Schema {
56 get {
57 if (schema == null) {
58 schema = XmlSchema.Read (typeof (ServiceDescription).Assembly.GetManifestResourceStream ("web-reference.xsd"), null);
60 return schema;
64 public static WebReferenceOptions Read (Stream stream, ValidationEventHandler validationEventHandler)
66 return Read (XmlReader.Create (stream), validationEventHandler);
69 public static WebReferenceOptions Read (TextReader reader, ValidationEventHandler validationEventHandler)
71 return Read (XmlReader.Create (reader), validationEventHandler);
74 public static WebReferenceOptions Read (XmlReader xmlReader,
75 ValidationEventHandler validationEventHandler)
77 XmlReaderSettings s = new XmlReaderSettings ();
78 s.ValidationType = ValidationType.Schema;
79 s.Schemas.Add (Schema);
80 if (validationEventHandler != null)
81 s.ValidationEventHandler += validationEventHandler;
82 using (XmlReader r = XmlReader.Create (xmlReader, s)) {
83 XmlSerializer ser = implementation.GetSerializer (typeof (WebReferenceOptions));
84 try {
85 return (WebReferenceOptions) ser.Deserialize (r);
86 } catch (XmlSchemaValidationException ex) {
87 throw new InvalidOperationException ("There is an error in input webReference XML", ex);
92 #endregion
94 #region Instance members
96 CodeGenerationOptions code_options;
97 StringCollection importer_extensions = new StringCollection ();
98 ServiceDescriptionImportStyle style;
99 bool verbose;
101 [XmlElement ("codeGenerationOptions")]
102 [DefaultValue (CodeGenerationOptions.GenerateOldAsync)]
103 public CodeGenerationOptions CodeGenerationOptions {
104 get { return code_options; }
105 set { code_options = value; }
108 [XmlArray ("schemaImporterExtensions")]
109 [XmlArrayItem ("type")]
110 public StringCollection SchemaImporterExtensions {
111 get { return importer_extensions; }
114 [XmlElement ("style")]
115 [DefaultValue (ServiceDescriptionImportStyle.Client)]
116 public ServiceDescriptionImportStyle Style {
117 get { return style; }
118 set { style = value; }
121 [XmlElement ("verbose")]
122 public bool Verbose {
123 get { return verbose; }
124 set { verbose = value; }
127 #endregion
131 #endif