* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Configuration / WebServicesConfigurationSectionHandler.cs
index 601e22be65464f13e8aff969abeedaea9229eac6..f128cd81b8593a606bd5c6e8a822988ae52fd0d2 100644 (file)
@@ -7,6 +7,27 @@
 // (C) 2003 Ximian, Inc (http://www.ximian.com)
 //
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Collections;
 using System.Configuration;
@@ -21,29 +42,65 @@ namespace System.Web.Services.Configuration
                HttpPost = 1 << 1,
                HttpGet =  1 << 2,
                Documentation = 1 << 3,
-               All = 0x0F
+#if NET_1_1
+               HttpSoap12 = 1 << 4,
+               HttpPostLocalhost = 1 << 5,
+#endif
+               All = 0xFF
        }
        
        class WSConfig
        {
-               static WSConfig instance;
+#if !TARGET_JVM
+               volatile static WSConfig instance;
+#else
+               static WSConfig instance {
+                       get {
+                               return (WSConfig)AppDomain.CurrentDomain.GetData("WSConfig.instance");
+                       }
+                       set {
+                               AppDomain.CurrentDomain.SetData("WSConfig.instance", value);
+                       }
+               }
+
+#endif
                WSProtocol protocols;
                string wsdlHelpPage;
-               ArrayList extensionTypes;
+               string filePath;
+               ArrayList extensionTypes = new ArrayList();
+               ArrayList extensionImporterTypes = new ArrayList();
+               ArrayList extensionReflectorTypes = new ArrayList();
+               ArrayList formatExtensionTypes = new ArrayList();
+               static readonly object lockobj = new object ();
                
-               public WSConfig (WSConfig parent)
+               public WSConfig (WSConfig parent, object context)
                {
                        if (parent == null)
                                return;
                        
                        protocols = parent.protocols;
                        wsdlHelpPage = parent.wsdlHelpPage;
+                       if (wsdlHelpPage != null)
+                               filePath = parent.filePath;
+                       else
+                               filePath = context as string;
                }
                
                static WSProtocol ParseProtocol (string protoName, out string error)
                {
                        WSProtocol proto;
                        error = null;
+
+#if ONLY_1_1
+                       switch (protoName) {
+                               case "HttpSoap1.2":
+                                       protoName = "HttpSoap12";
+                                       break;
+                               case "HttpSoap12":
+                                       protoName = null;
+                                       break;
+                       }
+#endif
                        try {
                                proto = (WSProtocol) Enum.Parse (typeof (WSProtocol), protoName);
                        } catch {
@@ -90,14 +147,6 @@ namespace System.Web.Services.Configuration
                        protocols = 0;
                }
 
-               public void AddExtensionType (WSExtensionConfig wsExtension)
-               {
-                       if (extensionTypes == null)
-                               extensionTypes = new ArrayList ();
-
-                       extensionTypes.Add (wsExtension);
-               }
-
                // Methods to query/get configuration
                public static bool IsSupported (WSProtocol proto)
                {
@@ -110,13 +159,18 @@ namespace System.Web.Services.Configuration
                        set { wsdlHelpPage = value; }
                }
 
+               public string ConfigFilePath {
+                       get { return filePath; }
+                       set { filePath = value; }
+               }
+
                static public WSConfig Instance {
                        get {
                                //TODO: use HttpContext to get the configuration
                                if (instance != null)
                                        return instance;
 
-                               lock (typeof (WSConfig)) {
+                               lock (lockobj) {
                                        if (instance != null)
                                                return instance;
 
@@ -130,6 +184,19 @@ namespace System.Web.Services.Configuration
                public ArrayList ExtensionTypes {
                        get { return extensionTypes; }
                }
+
+               public ArrayList ExtensionImporterTypes {
+                       get { return extensionImporterTypes; }
+               }
+               
+               public ArrayList ExtensionReflectorTypes {
+                       get { return extensionReflectorTypes; }
+               }
+               
+               public ArrayList FormatExtensionTypes {
+                       get { return formatExtensionTypes; }
+               }
+               
        }
        
        enum WSExtensionGroup
@@ -180,7 +247,7 @@ namespace System.Web.Services.Configuration
                        Exception exc = null;
                        try {
                                group = (WSExtensionGroup) Int32.Parse (grp);
-                               if (group < WSExtensionGroup.Low || group > WSExtensionGroup.High)
+                               if (group < WSExtensionGroup.High || group > WSExtensionGroup.Low)
                                        throw new ArgumentOutOfRangeException ("group", "Must be 0 or 1");
                        } catch (Exception e) {
                                exc = e;
@@ -205,10 +272,9 @@ namespace System.Web.Services.Configuration
        
        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);    
+                       WSConfig config = new WSConfig (parent as WSConfig, context);
 
                        if (section.Attributes != null && section.Attributes.Count != 0)
                                ThrowException ("Unrecognized attribute", section);
@@ -229,22 +295,22 @@ namespace System.Web.Services.Configuration
                                }
 
                                if (name == "soapExtensionTypes") {
-                                       ConfigSoapExtensionTypes (child, config);
+                                       ConfigSoapExtensionTypes (child, config.ExtensionTypes);
                                        continue;
                                }
 
                                if (name == "soapExtensionReflectorTypes") {
-                                       //TODO: Not supported by now
+                                       ConfigSoapExtensionTypes (child, config.ExtensionReflectorTypes);
                                        continue;
                                }
 
                                if (name == "soapExtensionImporterTypes") {
-                                       //TODO: Not supported by now
+                                       ConfigSoapExtensionTypes (child, config.ExtensionImporterTypes);
                                        continue;
                                }
 
                                if (name == "serviceDescriptionFormatExtensionTypes") {
-                                       //TODO: Not supported by now
+                                       ConfigFormatExtensionTypes (child, config);
                                        continue;
                                }
 
@@ -253,6 +319,7 @@ namespace System.Web.Services.Configuration
                                        if (child.Attributes != null && child.Attributes.Count != 0)
                                                HandlersUtil.ThrowException ("Unrecognized attribute", child);
 
+                                       config.ConfigFilePath = context as string;
                                        config.WsdlHelpPage = href;
                                        continue;
                                }
@@ -313,7 +380,7 @@ namespace System.Web.Services.Configuration
                        }
                }
                
-               static void ConfigSoapExtensionTypes (XmlNode section, WSConfig config)
+               static void ConfigSoapExtensionTypes (XmlNode section, ArrayList extensions)
                {
                        if (section.Attributes != null && section.Attributes.Count != 0)
                                ThrowException ("Unrecognized attribute", section);
@@ -328,7 +395,6 @@ namespace System.Web.Services.Configuration
                                        ThrowException ("Only elements allowed", child);
                                
                                string name = child.Name;
-                               string error;
                                if (name == "add") {
                                        string seType = AttValue ("type", child, false);
                                        string priority = AttValue ("priority", child);
@@ -349,7 +415,39 @@ namespace System.Web.Services.Configuration
                                        if (e != null)
                                                ThrowException (e.Message, child);
 
-                                       config.AddExtensionType (wse);
+                                       extensions.Add (wse);
+                                       continue;
+                               }
+
+                               ThrowException ("Unexpected element", child);
+                       }
+               }
+               
+               static void ConfigFormatExtensionTypes (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;
+                               if (name == "add") {
+                                       string typeName = AttValue ("name", child, false);
+                                       if (child.Attributes != null && child.Attributes.Count != 0)
+                                               HandlersUtil.ThrowException ("Unrecognized attribute", child);
+
+                                       try {
+                                               config.FormatExtensionTypes.Add (Type.GetType (typeName, true));
+                                       } catch (Exception e) {
+                                               ThrowException (e.Message, child);
+                                       }
                                        continue;
                                }
 
@@ -420,4 +518,3 @@ namespace System.Web.Services.Configuration
        }
 
 }
-