62896f256fb9eac8c414a8cdfb25a9a34faea60f
[mono.git] / mcs / class / System.ServiceModel.Discovery / System.ServiceModel.Discovery.Configuration / EndpointDiscoveryElement.cs
1 //
2 // Author: Atsushi Enomoto <atsushi@ximian.com>
3 //
4 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 // 
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 // 
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //
25 #if NET_4_0
26 using System;
27 using System.ComponentModel;
28 using System.Configuration;
29 using System.ServiceModel.Configuration;
30 using System.Xml;
31 using System.Xml.Linq;
32
33 namespace System.ServiceModel.Discovery.Configuration
34 {
35         public sealed class EndpointDiscoveryElement : BehaviorExtensionElement
36         {
37                 static ConfigurationPropertyCollection properties;
38                 static ConfigurationProperty types, enabled, extensions, scopes;
39                 
40                 static EndpointDiscoveryElement ()
41                 {
42                         types = new ConfigurationProperty ("types", typeof (ContractTypeNameElementCollection), null, null, null, ConfigurationPropertyOptions.None);
43                         enabled = new ConfigurationProperty ("enabled", typeof (bool), null, null, null, ConfigurationPropertyOptions.None);
44                         extensions = new ConfigurationProperty ("extensions", typeof (XmlElementElementCollection), null, null, null, ConfigurationPropertyOptions.None);
45                         scopes = new ConfigurationProperty ("scopes", typeof (ScopeElementCollection), null, null, null, ConfigurationPropertyOptions.None);
46                         properties = new ConfigurationPropertyCollection ();
47                         properties.Add (types);
48                         properties.Add (enabled);
49                         properties.Add (extensions);
50                         properties.Add (scopes);
51                 }
52
53                 public EndpointDiscoveryElement ()
54                 {
55                 }
56                 
57                 public override Type BehaviorType {
58                         get { return typeof (EndpointDiscoveryBehavior); }
59                 }
60
61                 [ConfigurationProperty ("types")]
62                 public ContractTypeNameElementCollection ContractTypeNames {
63                         get { return (ContractTypeNameElementCollection) base [types]; }
64                 }
65                 
66                 [ConfigurationPropertyAttribute("enabled", DefaultValue = true)]
67                 public bool Enabled {
68                         get { return (bool) base [enabled]; }
69                         set { base [enabled] = value; }
70                 }
71                 
72                 [ConfigurationPropertyAttribute("extensions")]
73                 public XmlElementElementCollection Extensions {
74                         get { return (XmlElementElementCollection) base [extensions]; }
75                 }
76                 
77                 [ConfigurationPropertyAttribute("scopes")]
78                 public ScopeElementCollection Scopes {
79                         get { return (ScopeElementCollection) base [scopes]; }
80                 }
81                 
82                 protected override ConfigurationPropertyCollection Properties {
83                         get { return properties; }
84                 }
85                 
86                 protected internal override object CreateBehavior ()
87                 {
88                         var ret = new EndpointDiscoveryBehavior () { Enabled = this.Enabled };
89                         foreach (ContractTypeNameElement ctn in ContractTypeNames)
90                                 ret.ContractTypeNames.Add (new XmlQualifiedName (ctn.Name, ctn.Namespace));
91                         foreach (XmlElementElement xee in Extensions)
92                                 ret.Extensions.Add (XElement.Load (new XmlNodeReader (xee.XmlElement)));
93                         foreach (ScopeElement se in Scopes)
94                                 ret.Scopes.Add (se.Scope);
95                         return ret;
96                 }
97         }
98 }
99
100 #endif