You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2010/07/15 21:28:26 UTC

svn commit: r964548 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs

Author: jgomes
Date: Thu Jul 15 19:28:26 2010
New Revision: 964548

URL: http://svn.apache.org/viewvc?rev=964548&view=rev
Log:
Applied modified patch from Daniel Ellis.  Made a few fixups to use newer APIs to load assembly filenames, and made a fix to append .dll extension when looking for filenames.
Fixes [AMQNET-262]. (See https://issues.apache.org/activemq/browse/AMQNET-262)

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs?rev=964548&r1=964547&r2=964548&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs Thu Jul 15 19:28:26 2010
@@ -1,18 +1,18 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 using System;
@@ -45,7 +45,7 @@ namespace Apache.NMS
 	public class NMSConnectionFactory : IConnectionFactory
 	{
 		protected readonly IConnectionFactory factory;
-		protected static readonly Dictionary<string, ProviderFactoryInfo> schemaProviderFactoryMap;
+		protected static readonly Dictionary<string, ProviderFactoryInfo> schemaProviderFactoryMap;
 
 		/// <summary>
 		/// Static class constructor
@@ -53,12 +53,12 @@ namespace Apache.NMS
 		static NMSConnectionFactory()
 		{
 			schemaProviderFactoryMap = new Dictionary<string, ProviderFactoryInfo>();
-			schemaProviderFactoryMap["activemq"] = new ProviderFactoryInfo("Apache.NMS.ActiveMQ.dll", "Apache.NMS.ActiveMQ.ConnectionFactory");
-			schemaProviderFactoryMap["tcp"] = new ProviderFactoryInfo("Apache.NMS.ActiveMQ.dll", "Apache.NMS.ActiveMQ.ConnectionFactory");
-			schemaProviderFactoryMap["ems"] = new ProviderFactoryInfo("Apache.NMS.EMS.dll", "Apache.NMS.EMS.ConnectionFactory");
-			schemaProviderFactoryMap["msmq"] = new ProviderFactoryInfo("Apache.NMS.MSMQ.dll", "Apache.NMS.MSMQ.ConnectionFactory");
-			schemaProviderFactoryMap["stomp"] = new ProviderFactoryInfo("Apache.NMS.Stomp.dll", "Apache.NMS.Stomp.ConnectionFactory");
-			schemaProviderFactoryMap["xms"] = new ProviderFactoryInfo("Apache.NMS.XMS.dll", "Apache.NMS.XMS.ConnectionFactory");
+			schemaProviderFactoryMap["activemq"] = new ProviderFactoryInfo("Apache.NMS.ActiveMQ", "Apache.NMS.ActiveMQ.ConnectionFactory");
+			schemaProviderFactoryMap["tcp"] = new ProviderFactoryInfo("Apache.NMS.ActiveMQ", "Apache.NMS.ActiveMQ.ConnectionFactory");
+			schemaProviderFactoryMap["ems"] = new ProviderFactoryInfo("Apache.NMS.EMS", "Apache.NMS.EMS.ConnectionFactory");
+			schemaProviderFactoryMap["msmq"] = new ProviderFactoryInfo("Apache.NMS.MSMQ", "Apache.NMS.MSMQ.ConnectionFactory");
+			schemaProviderFactoryMap["stomp"] = new ProviderFactoryInfo("Apache.NMS.Stomp", "Apache.NMS.Stomp.ConnectionFactory");
+			schemaProviderFactoryMap["xms"] = new ProviderFactoryInfo("Apache.NMS.XMS", "Apache.NMS.XMS.ConnectionFactory");
 		}
 
 		/// <summary>
@@ -100,10 +100,10 @@ namespace Apache.NMS
 				// If an implementation was found, try to instantiate it.
 				if(factoryType != null)
 				{
-#if NETCF
-					// Compact framework does not allow the activator ta pass parameters to a constructor.
-					connectionFactory = (IConnectionFactory) Activator.CreateInstance(factoryType);
-					connectionFactory.BrokerUri = uriProvider;
+#if NETCF
+					// Compact framework does not allow the activator ta pass parameters to a constructor.
+					connectionFactory = (IConnectionFactory) Activator.CreateInstance(factoryType);
+					connectionFactory.BrokerUri = uriProvider;
 #else
 					object[] parameters = MakeParameterArray(uriProvider, constructorParams);
 					connectionFactory = (IConnectionFactory) Activator.CreateInstance(factoryType, parameters);
@@ -140,33 +140,72 @@ namespace Apache.NMS
 			string factoryClassName;
 			Type factoryType = null;
 
-			Tracer.Debug("Locating provider for scheme: " + scheme);
-
+			Tracer.DebugFormat("Locating provider for scheme: {0}", scheme);
 			if(LookupConnectionFactoryInfo(paths, scheme, out assemblyFileName, out factoryClassName))
 			{
 				Assembly assembly = null;
 
-				Tracer.Debug("Attempting to locate provider assembly: " + assemblyFileName);
-				foreach(string path in paths)
+				Tracer.DebugFormat("Attempting to load provider assembly: {0}", assemblyFileName);
+				try
+				{
+					assembly = Assembly.Load(assemblyFileName);
+					if(null != assembly)
+					{
+						Tracer.Debug("Succesfully loaded provider.");
+					}
+				}
+				catch(Exception ex)
 				{
-					string fullpath = Path.Combine(path, assemblyFileName);
-					Tracer.Debug("\tScanning folder: " + path);
+					Tracer.ErrorFormat("Exception loading assembly failed: {0}", ex.Message);
+					assembly = null;
+				}
 
-					if(File.Exists(fullpath))
+				if(null == assembly)
+				{
+					foreach(string path in paths)
 					{
-						Tracer.Debug("\tAssembly found!");
-						assembly = Assembly.LoadFrom(fullpath);
-						break;
+						string fullpath = Path.Combine(path, assemblyFileName) + ".dll";
+
+						Tracer.DebugFormat("Looking for: {0}", fullpath);
+						if(File.Exists(fullpath))
+						{
+							Tracer.Debug("\tAssembly found!  Attempting to load...");
+							try
+							{
+								assembly = Assembly.LoadFrom(fullpath);
+							}
+							catch(Exception ex)
+							{
+								Tracer.ErrorFormat("Exception loading assembly failed: {0}", ex.Message);
+								assembly = null;
+							}
+
+							if(null != assembly)
+							{
+								Tracer.Debug("Successfully loaded provider.");
+								break;
+							}
+
+							Tracer.Debug("Failed to load provider.  Continuing search...");
+						}
 					}
 				}
 
 				if(null != assembly)
 				{
-#if NETCF
-					factoryType = assembly.GetType(factoryClassName, true);
+#if NETCF
+					factoryType = assembly.GetType(factoryClassName, true);
 #else
 					factoryType = assembly.GetType(factoryClassName, true, true);
 #endif
+					if(null == factoryType)
+					{
+						Tracer.Fatal("Failed to load class factory from provider.");
+					}
+				}
+				else
+				{
+					Tracer.Fatal("Failed to load provider assembly.");
 				}
 			}
 
@@ -222,7 +261,7 @@ namespace Apache.NMS
 				foreach(string path in paths)
 				{
 					string fullpath = Path.Combine(path, configFileName);
-					Tracer.DebugFormat("\tScanning folder: {0}", path);
+					Tracer.DebugFormat("Looking for: {0}", fullpath);
 
 					try
 					{
@@ -343,17 +382,17 @@ namespace Apache.NMS
 		public IConnectionFactory ConnectionFactory
 		{
 			get { return factory; }
-		}
-
-        /// <summary>
-        /// Get/or Set the IRedeliveryPolicy instance using the IConnectionFactory implementation
-        /// that is being used.
-        /// </summary>
-        public IRedeliveryPolicy RedeliveryPolicy
-        {
-            get { return this.factory.RedeliveryPolicy; }
-            set { this.factory.RedeliveryPolicy = value; }
-        }
-        
+		}
+
+		/// <summary>
+		/// Get/or Set the IRedeliveryPolicy instance using the IConnectionFactory implementation
+		/// that is being used.
+		/// </summary>
+		public IRedeliveryPolicy RedeliveryPolicy
+		{
+			get { return this.factory.RedeliveryPolicy; }
+			set { this.factory.RedeliveryPolicy = value; }
+		}
+
 	}
 }