* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels / SoapMessageFormatter.cs
index e0508f1cb82fa2e00ec28cc982e266415b7e9fdd..e958e557cdfcb0e354592ebf1feb2af1072e060c 100644 (file)
@@ -5,27 +5,27 @@
 // Author:     Jean-Marc Andre (jean-marc.andre@polymtl.ca)\r
 //\r
 //\r
-
-//
-// 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.
-//
+\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
 \r
 using System;\r
 using System.Collections;\r
@@ -74,6 +74,34 @@ namespace System.Runtime.Remoting.Channels {
                        if (sf != null) {\r
                                if(_serverFaultExceptionField != null)\r
                                        e = (Exception) _serverFaultExceptionField.GetValue(sf);\r
+#if TARGET_JVM                         \r
+                               if (e == null && sf.ExceptionType != null)\r
+                               {\r
+                                       try\r
+                                       {\r
+                                               Type te = Type.GetType(sf.ExceptionType);\r
+                                               if (te != null)\r
+                                               {\r
+                                                       ConstructorInfo ce = te.GetConstructor(\r
+                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance,\r
+                                                               null, new Type[] {typeof(string)}, null);\r
+\r
+                                                       if (ce != null)\r
+                                                       {\r
+                                                               e = (Exception) ce.Invoke(new object[] {sf.ExceptionMessage});\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               e = (Exception) Activator.CreateInstance(te);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       catch\r
+                                       {\r
+                                               e = null;\r
+                                       }\r
+                               }\r
+#endif\r
                        }\r
                        if (e == null)\r
                                e = new RemotingException (fault.FaultString);\r
@@ -99,7 +127,7 @@ namespace System.Runtime.Remoting.Channels {
                        }\r
                        else {\r
                                object rtnObject = null;\r
-                               RemMessageType messageType;\r
+                               //RemMessageType messageType;\r
                                \r
                                // Get the output of the function if it is not *void*\r
                                if(_methodCallInfo.ReturnType != typeof(void)){\r
@@ -149,13 +177,12 @@ namespace System.Runtime.Remoting.Channels {
                        \r
                        requestHeaders = new TransportHeaders();\r
                        SoapMessage soapMsg = new SoapMessage();\r
-                       string uri = mcm.Uri;\r
 \r
                        GetInfoFromMethodCallMessage(mcm);\r
 \r
                        // Format the SoapMessage that will be used to create the RPC\r
                        soapMsg.MethodName = mcm.MethodName;\r
-                       int count = mcm.ArgCount;\r
+                       //int count = mcm.ArgCount;\r
                        ArrayList paramNames = new ArrayList(_methodCallParameters.Length);\r
                        ArrayList paramTypes = new ArrayList(_methodCallParameters.Length);\r
                        ArrayList paramValues = new ArrayList(_methodCallParameters.Length);\r
@@ -195,7 +222,7 @@ namespace System.Runtime.Remoting.Channels {
                        headersList.Add(new Header("__Uri", uri));\r
                        headersList.Add(new Header("__MethodName", soapMessage.MethodName));\r
                        string typeNamespace, assemblyName;\r
-                       bool b = SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMessage.XmlNameSpace, out typeNamespace, out assemblyName);\r
+                       SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMessage.XmlNameSpace, out typeNamespace, out assemblyName);\r
 \r
                        _serverType = RemotingServices.GetServerTypeForUri(uri);\r
                        headersList.Add(new Header("__TypeName", _serverType.FullName, false));\r
@@ -209,7 +236,7 @@ namespace System.Runtime.Remoting.Channels {
                        }\r
                        \r
                        _xmlNamespace = soapMessage.XmlNameSpace;\r
-                       RemMessageType messageType;\r
+                       //RemMessageType messageType;\r
                        \r
                        BindingFlags bflags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;\r
                        \r
@@ -222,21 +249,21 @@ namespace System.Runtime.Remoting.Channels {
                        // have to add them here\r
                        _methodCallParameters = _methodCallInfo.GetParameters();\r
                        object[] args = new object[_methodCallParameters.Length];\r
-                       \r
-                       foreach(ParameterInfo paramInfo in _methodCallParameters)\r
+                       int sn = 0;\r
+                       for (int n=0; n<_methodCallParameters.Length; n++)\r
                        {\r
+                               ParameterInfo paramInfo = _methodCallParameters [n];\r
                                Type paramType = (paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType);\r
 \r
                                if (paramInfo.IsOut && paramInfo.ParameterType.IsByRef) {\r
-                                       args [paramInfo.Position] = GetNullValue (paramType);\r
+                                       args [n] = GetNullValue (paramType);\r
                                }\r
                                else{\r
-                                       int index = Array.IndexOf(soapMessage.ParamNames, paramInfo.Name);\r
-                                       if(soapMessage.ParamValues[index] is IConvertible) \r
-                                               soapMessage.ParamValues[index] = Convert.ChangeType(\r
-                                                               soapMessage.ParamValues[index],\r
-                                                               paramType);\r
-                                       args [paramInfo.Position] = soapMessage.ParamValues[index];\r
+                                       object val = soapMessage.ParamValues[sn++];\r
+                                       if(val is IConvertible) \r
+                                               args [n] = Convert.ChangeType (val, paramType);\r
+                                       else\r
+                                               args [n] = val;\r
                                }\r
                        }\r
                        \r
@@ -267,10 +294,16 @@ namespace System.Runtime.Remoting.Channels {
                                ArrayList paramValues = new ArrayList();\r
                                ArrayList paramTypes = new ArrayList();\r
                                soapMessage.MethodName = mrm.MethodName+"Response";\r
-                               if(mrm.ReturnValue != null && mrm.ReturnValue.GetType() != typeof(void)) {\r
+                               \r
+                               Type retType = ((MethodInfo)mrm.MethodBase).ReturnType;\r
+                               \r
+                               if(retType != typeof(void)) {\r
                                        paramNames.Add("return");\r
                                        paramValues.Add(mrm.ReturnValue);\r
-                                       paramTypes.Add(mrm.ReturnValue.GetType());\r
+                                       if (mrm.ReturnValue != null)\r
+                                               paramTypes.Add(mrm.ReturnValue.GetType());\r
+                                       else\r
+                                               paramTypes.Add(retType);\r
                                }\r
                                \r
                                for(int i = 0; i < mrm.OutArgCount; i++){\r
@@ -287,7 +320,7 @@ namespace System.Runtime.Remoting.Channels {
                        }\r
                        else {\r
                                // an Exception was thrown while executing the function\r
-                               responseHeaders["__HttpStatusCode"] = "400";\r
+                               responseHeaders["__HttpStatusCode"] = "500";\r
                                responseHeaders["__HttpReasonPhrase"] = "Bad Request";\r
                                // fill the transport headers\r
                                responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";\r
@@ -394,6 +427,12 @@ namespace System.Runtime.Remoting.Channels {
                \r
                object GetNullValue (Type paramType)\r
                {\r
+#if TARGET_JVM                 \r
+                       if (paramType.IsEnum)\r
+                       {\r
+                               return Activator.CreateInstance(paramType);\r
+                       }\r
+#endif\r
                        switch (Type.GetTypeCode (paramType))\r
                        {\r
                                case TypeCode.Boolean: return false;\r
@@ -409,8 +448,15 @@ namespace System.Runtime.Remoting.Channels {
                                case TypeCode.UInt16: return (ushort)0;\r
                                case TypeCode.UInt32: return (uint)0;\r
                                case TypeCode.UInt64: return (ulong)0;\r
-                               default: return null;\r
+                               default: \r
+#if TARGET_JVM                 \r
+                                       if (paramType.IsValueType)\r
+                                       {\r
+                                               return Activator.CreateInstance(paramType);\r
+                                       }\r
+#endif                                 \r
+                                       return null;\r
                        }\r
                }\r
        }\r
-}
+}\r