2008-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / WebReferenceOptions.cs
1 // 
2 // WebReferenceOptions.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.
8 //
9
10 //
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.
29 //
30
31 #if NET_2_0
32
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;
41
42 namespace System.Web.Services.Description
43 {
44         [XmlRoot ("webReferenceOptions", Namespace = "http://microsoft.com/webReference/")]
45         [XmlType ("webReferenceOptions", Namespace = "http://microsoft.com/webReference/")]
46         public class WebReferenceOptions
47         {
48                 #region Static members
49                 static XmlSchema schema;
50                 static XmlSerializerImplementation implementation =
51                         new WebReferenceOptionsSerializerImplementation ();
52
53                 public const string TargetNamespace = "http://microsoft.com/webReference/";
54
55                 public static XmlSchema Schema {
56                         get {
57                                 if (schema == null) {
58                                         schema = XmlSchema.Read (typeof (ServiceDescription).Assembly.GetManifestResourceStream ("web-reference.xsd"), null);
59                                 }
60                                 return schema;
61                         }
62                 }
63
64                 public static WebReferenceOptions Read (Stream stream, ValidationEventHandler validationEventHandler)
65                 {
66                         return Read (XmlReader.Create (stream), validationEventHandler);
67                 }
68
69                 public static WebReferenceOptions Read (TextReader reader, ValidationEventHandler validationEventHandler)
70                 {
71                         return Read (XmlReader.Create (reader), validationEventHandler);
72                 }
73
74                 public static WebReferenceOptions Read (XmlReader xmlReader,
75                         ValidationEventHandler validationEventHandler)
76                 {
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);
88                                 }
89                         }
90                 }
91
92                 #endregion
93
94                 #region Instance members
95
96                 CodeGenerationOptions code_options;
97                 StringCollection importer_extensions = new StringCollection ();
98                 ServiceDescriptionImportStyle style;
99                 bool verbose;
100
101                 [XmlElement ("codeGenerationOptions")]
102                 [DefaultValue (CodeGenerationOptions.GenerateOldAsync)]
103                 public CodeGenerationOptions CodeGenerationOptions {
104                         get { return code_options; }
105                         set { code_options = value; }
106                 }
107
108                 [XmlArray ("schemaImporterExtensions")]
109                 [XmlArrayItem ("type")]
110                 public StringCollection SchemaImporterExtensions {
111                         get { return importer_extensions; }
112                 }
113
114                 [XmlElement ("style")]
115                 [DefaultValue (ServiceDescriptionImportStyle.Client)]
116                 public ServiceDescriptionImportStyle Style {
117                         get { return style; }
118                         set { style = value; }
119                 }
120
121                 [XmlElement ("verbose")]
122                 public bool Verbose {
123                         get { return verbose; }
124                         set { verbose = value; }
125                 }
126
127                 #endregion
128         }
129 }
130
131 #endif