added WebServicesConfigurationSectionHandler.cs
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 2 Jul 2003 16:28:09 +0000 (16:28 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 2 Jul 2003 16:28:09 +0000 (16:28 -0000)
svn path=/trunk/mcs/; revision=15871

mcs/class/System.Web.Services/System.Web.Services.Configuration/ChangeLog
mcs/class/System.Web.Services/System.Web.Services.Configuration/WebServicesConfigurationSectionHandler.cs [new file with mode: 0644]
mcs/class/System.Web.Services/list

index b91825974fc90949c68950d6b2f9739d0c6587c7..2ab07bc38d742564263e0d04e9622bbf61dd6d70 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-02  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * WebServicesConfigurationSectionHandler.cs: New file that handles
+       system.web/webServices section.
+
 2002-07-21 Tim Coleman  <tim@timcoleman.com>
        * ChangeLog:
        * XmlFormatExtensionAttribute.cs:
diff --git a/mcs/class/System.Web.Services/System.Web.Services.Configuration/WebServicesConfigurationSectionHandler.cs b/mcs/class/System.Web.Services/System.Web.Services.Configuration/WebServicesConfigurationSectionHandler.cs
new file mode 100644 (file)
index 0000000..6737589
--- /dev/null
@@ -0,0 +1,243 @@
+//
+// System.Web.Services.Configuration.WebServicesConfigurationSectionHandler
+//
+// Authors:
+//     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2003 Ximian, Inc (http://www.ximian.com)
+//
+
+using System;
+using System.Configuration;
+using System.Xml;
+
+namespace System.Web.Services.Configuration
+{
+       [Flags]
+       enum WSProtocol
+       {
+               HttpSoap = 1,
+               HttpPost = 1 << 1,
+               HttpGet =  1 << 2,
+               Documentation = 1 << 3,
+               All = 0x0F
+       }
+       
+       class WSConfig
+       {
+               WSProtocol protocols;
+               string wsdlHelpPage;
+               
+               public WSConfig (WSConfig parent)
+               {
+                       if (parent == null)
+                               return;
+                       
+                       protocols = parent.protocols;
+                       wsdlHelpPage = parent.wsdlHelpPage;
+               }
+               
+               static WSProtocol ParseProtocol (string protoName, out string error)
+               {
+                       WSProtocol proto;
+                       error = null;
+                       try {
+                               proto = (WSProtocol) Enum.Parse (typeof (WSProtocol), protoName);
+                       } catch {
+                               error = "Invalid protocol name";
+                               return 0;
+                       }
+
+                       return proto;
+               }
+
+               // Methods to modify configuration values
+               public bool AddProtocol (string protoName, out string error)
+               {
+                       if (protoName == "All") {
+                               error = "Invalid protocol name";
+                               return false;
+                       }
+
+                       WSProtocol proto = ParseProtocol (protoName, out error);
+                       if (error != null)
+                               return false;
+
+                       if ((protocols & proto) != 0) {
+                               error = "Protocol already added";
+                               return false;
+                       }
+
+                       protocols |= proto;
+                       return true;
+               }
+
+               // Methods to query/get configuration
+               public bool IsSupported (WSProtocol proto)
+               {
+                       return (proto & WSProtocol.All) == proto;
+               }
+
+               // Properties
+               public string WsdlHelpPage {
+                       get { return wsdlHelpPage; }
+                       set { wsdlHelpPage = value; }
+               }
+
+       }
+       
+       class WebServicesConfigurationSectionHandler : IConfigurationSectionHandler
+       {
+               [MonoTODO("Some nodes not supported, see below")]
+               public object Create (object parent, object context, XmlNode section)
+               {
+                       WSConfig config = new WSConfig (parent as WSConfig);    
+
+                       if (section.Attributes != null && section.Attributes.Count != 0)
+                               ThrowException ("Unrecognized attribute", section);
+
+                       XmlNodeList nodes = section.ChildNodes;
+                       foreach (XmlNode child in nodes) {
+                               XmlNodeType ntype = child.NodeType;
+                               if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
+                                       continue;
+
+                               if (ntype != XmlNodeType.Element)
+                                       ThrowException ("Only elements allowed", child);
+                               
+                               string name = child.Name;
+                               if (name == "protocols") {
+                                       ConfigProtocols (child, config);
+                                       continue;
+                               }
+
+                               if (name == "soapExtensionTypes") {
+                                       //TODO: Not supported by now
+                                       continue;
+                               }
+
+                               if (name == "soapExtensionReflectorTypes") {
+                                       //TODO: Not supported by now
+                                       continue;
+                               }
+
+                               if (name == "soapExtensionImporterTypes") {
+                                       //TODO: Not supported by now
+                                       continue;
+                               }
+
+                               if (name == "serviceDescriptionFormatExtensionTypes") {
+                                       //TODO: Not supported by now
+                                       continue;
+                               }
+
+                               if (name == "wsdlHelpGenerator") {
+                                       string href = AttValue ("href", child, false);
+                                       if (child.Attributes != null && child.Attributes.Count != 0)
+                                               HandlersUtil.ThrowException ("Unrecognized attribute", child);
+
+                                       config.WsdlHelpPage = href;
+                                       continue;
+                               }
+
+                               ThrowException ("Unexpected element", child);
+                       }
+
+                       return null;
+               }
+
+               static void ConfigProtocols (XmlNode section, WSConfig config)
+               {
+                       if (section.Attributes != null && section.Attributes.Count != 0)
+                               ThrowException ("Unrecognized attribute", section);
+
+                       XmlNodeList nodes = section.ChildNodes;
+                       foreach (XmlNode child in nodes) {
+                               XmlNodeType ntype = child.NodeType;
+                               if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
+                                       continue;
+
+                               if (ntype != XmlNodeType.Element)
+                                       ThrowException ("Only elements allowed", child);
+                               
+                               string name = child.Name;
+                               string error;
+                               if (name == "add") {
+                                       string protoName = AttValue ("name", child, false);
+                                       if (child.Attributes != null && child.Attributes.Count != 0)
+                                               HandlersUtil.ThrowException ("Unrecognized attribute", child);
+
+                                       if (!config.AddProtocol (protoName, out error))
+                                               ThrowException (error, child);
+                                       
+                                       continue;
+                               }
+
+                               ThrowException ("Unexpected element", child);
+                       }
+               }
+               
+               // To save some typing...
+               static string AttValue (string name, XmlNode node, bool optional)
+               {
+                       return HandlersUtil.ExtractAttributeValue (name, node, optional);
+               }
+
+               static string AttValue (string name, XmlNode node)
+               {
+                       return HandlersUtil.ExtractAttributeValue (name, node, true);
+               }
+
+               static void ThrowException (string message, XmlNode node)
+               {
+                       HandlersUtil.ThrowException (message, node);
+               }
+               //
+       }
+       
+       class HandlersUtil
+       {
+               private HandlersUtil ()
+               {
+               }
+
+               static internal string ExtractAttributeValue (string attKey, XmlNode node)
+               {
+                       return ExtractAttributeValue (attKey, node, false);
+               }
+                       
+               static internal string ExtractAttributeValue (string attKey, XmlNode node, bool optional)
+               {
+                       if (node.Attributes == null) {
+                               if (optional)
+                                       return null;
+
+                               ThrowException ("Required attribute not found: " + attKey, node);
+                       }
+
+                       XmlNode att = node.Attributes.RemoveNamedItem (attKey);
+                       if (att == null) {
+                               if (optional)
+                                       return null;
+                               ThrowException ("Required attribute not found: " + attKey, node);
+                       }
+
+                       string value = att.Value;
+                       if (value == String.Empty) {
+                               string opt = optional ? "Optional" : "Required";
+                               ThrowException (opt + " attribute is empty: " + attKey, node);
+                       }
+
+                       return value;
+               }
+
+               static internal void ThrowException (string msg, XmlNode node)
+               {
+                       if (node != null && node.Name != String.Empty)
+                               msg = msg + " (node name: " + node.Name + ") ";
+                       throw new ConfigurationException (msg, node);
+               }
+       }
+
+}
+
index e3f02a8dd2ae8045eb8d76a6451142ef1f07fb8a..fe9daabd56aa835c6b2e6c11028b8c6549a03995 100644 (file)
@@ -4,6 +4,7 @@ System.Web.Services/WebService.cs
 System.Web.Services/WebServiceAttribute.cs
 System.Web.Services/WebServiceBindingAttribute.cs
 System.Web.Services/WebServicesDescriptionAttribute.cs
+System.Web.Services.Configuration/WebServicesConfigurationSectionHandler.cs
 System.Web.Services.Configuration/XmlFormatExtensionAttribute.cs
 System.Web.Services.Configuration/XmlFormatExtensionPointAttribute.cs
 System.Web.Services.Configuration/XmlFormatExtensionPrefixAttribute.cs