Author: jgomes
Date: Thu Jun 18 22:48:24 2009
New Revision: 786327

URL: http://svn.apache.org/viewvc?rev=786327&view=rev
Log:
Add support for setting the broker Uri after the connection factory is created. 
 This is generally useful, but it is critical to fully support the Compact 
Framework.
The Compact Framework Activator class only allows dynamic creation of classes 
using the default constructor.  Any kind of settings need to be done after the 
object is created.

Modified:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
    
activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/ConnectionFactory.cs
    
activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/ConnectionFactory.cs
    
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IConnectionFactory.cs
    
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs?rev=786327&r1=786326&r2=786327&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
 Thu Jun 18 22:48:24 2009
@@ -105,6 +105,9 @@
 
                // Properties
 
+               /// <summary>
+               /// Get/or set the broker Uri.
+               /// </summary>
                public Uri BrokerUri
                {
                        get { return brokerUri; }

Modified: 
activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/ConnectionFactory.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/ConnectionFactory.cs?rev=786327&r1=786326&r2=786327&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/ConnectionFactory.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/ConnectionFactory.cs
 Thu Jun 18 22:48:24 2009
@@ -14,17 +14,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using System.Collections;
 
 namespace Apache.NMS.EMS
 {
-    /// <summary>
-    /// A Factory that can estbalish NMS connections to TIBCO
-    /// </summary>
-    public class ConnectionFactory : Apache.NMS.IConnectionFactory
-    {
-       public TIBCO.EMS.ConnectionFactory tibcoConnectionFactory;
+       /// <summary>
+       /// A Factory that can estbalish NMS connections to TIBCO
+       /// </summary>
+       public class ConnectionFactory : Apache.NMS.IConnectionFactory
+       {
+               public TIBCO.EMS.ConnectionFactory tibcoConnectionFactory;
+               private Uri brokerUri;
+               private string clientId;
+               private Hashtable properties;
 
                public ConnectionFactory()
                {
@@ -55,6 +59,7 @@
                        try
                        {
                                this.tibcoConnectionFactory = new 
TIBCO.EMS.ConnectionFactory(serverUrl);
+                               this.brokerUri = new Uri(serverUrl);
                        }
                        catch(Exception ex)
                        {
@@ -69,6 +74,8 @@
                        try
                        {
                                this.tibcoConnectionFactory = new 
TIBCO.EMS.ConnectionFactory(serverUrl, clientId);
+                               this.brokerUri = new Uri(serverUrl);
+                               this.clientId = clientId;
                        }
                        catch(Exception ex)
                        {
@@ -83,6 +90,9 @@
                        try
                        {
                                this.tibcoConnectionFactory = new 
TIBCO.EMS.ConnectionFactory(serverUrl, clientId, properties);
+                               this.brokerUri = new Uri(serverUrl);
+                               this.clientId = clientId;
+                               this.properties = properties;
                        }
                        catch(Exception ex)
                        {
@@ -106,18 +116,56 @@
                /// Creates a new connection to TIBCO.
                /// </summary>
                public Apache.NMS.IConnection CreateConnection()
-        {
+               {
                        return 
EMSConvert.ToNMSConnection(this.tibcoConnectionFactory.CreateConnection());
-        }
+               }
 
                /// <summary>
                /// Creates a new connection to TIBCO.
                /// </summary>
                public Apache.NMS.IConnection CreateConnection(string userName, 
string password)
-        {
+               {
                        return 
EMSConvert.ToNMSConnection(this.tibcoConnectionFactory.CreateConnection(userName,
 password));
                }
 
+               /// <summary>
+               /// Get/or set the broker Uri.
+               /// </summary>
+               public Uri BrokerUri
+               {
+                       get { return this.brokerUri; }
+                       set
+                       {
+                               if(null == this.brokerUri || 
!this.brokerUri.Equals(value))
+                               {
+                                       // Re-create the TIBCO connection 
factory.
+                                       this.brokerUri = value;
+                                       if(null == this.brokerUri)
+                                       {
+                                               this.tibcoConnectionFactory = 
new TIBCO.EMS.ConnectionFactory();
+                                       }
+                                       else
+                                       {
+                                               if(null == this.clientId)
+                                               {
+                                                       
this.tibcoConnectionFactory = new 
TIBCO.EMS.ConnectionFactory(this.brokerUri.OriginalString);
+                                               }
+                                               else
+                                               {
+                                                       if(null == 
this.properties)
+                                                       {
+                                                               
this.tibcoConnectionFactory = new 
TIBCO.EMS.ConnectionFactory(this.brokerUri.OriginalString, this.clientId);
+                                                       }
+                                                       else
+                                                       {
+                                                               
this.tibcoConnectionFactory = new 
TIBCO.EMS.ConnectionFactory(this.brokerUri.OriginalString, this.clientId, 
this.properties);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+
                #endregion
        }
 }

Modified: 
activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/ConnectionFactory.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/ConnectionFactory.cs?rev=786327&r1=786326&r2=786327&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/ConnectionFactory.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/ConnectionFactory.cs
 Thu Jun 18 22:48:24 2009
@@ -25,6 +25,7 @@
        {
                public const string DEFAULT_BROKER_URL = "msmq://localhost";
                public const string ENV_BROKER_URL = "MSMQ_BROKER_URL";
+               private Uri brokerUri;
 
                public static string GetDefaultBrokerUrl()
                {
@@ -58,7 +59,7 @@
 
                public ConnectionFactory(Uri brokerUri, string clientID)
                {
-
+                       this.brokerUri = brokerUri;
                }
 
                /// <summary>
@@ -84,5 +85,14 @@
                {
                        return new Connection();
                }
+
+               /// <summary>
+               /// Get/or set the broker Uri.
+               /// </summary>
+               public Uri BrokerUri
+               {
+                       get { return brokerUri; }
+                       set { brokerUri = value; }
+               }
        }
 }

Modified: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IConnectionFactory.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IConnectionFactory.cs?rev=786327&r1=786326&r2=786327&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IConnectionFactory.cs 
(original)
+++ 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IConnectionFactory.cs 
Thu Jun 18 22:48:24 2009
@@ -14,15 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+using System;
+
 namespace Apache.NMS
 {
-       
        /// <summary>
        /// A Factory of IConnection objects
        /// </summary>
        public interface IConnectionFactory
        {
-               
                /// <summary>
                /// Creates a new connection
                /// </summary>
@@ -32,7 +33,10 @@
                /// Creates a new connection with the given user name and 
password
                /// </summary>
                IConnection CreateConnection(string userName, string password);
+
+               /// <summary>
+               /// Get/or set the broker Uri.
+               /// </summary>
+               Uri BrokerUri { get; set; }
        }
 }
-
-

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=786327&r1=786326&r2=786327&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 Jun 18 22:48:24 2009
@@ -48,7 +48,7 @@
                /// <param name="constructorParams">Optional parameters to use 
when creating the ConnectionFactory.</param>
                public NMSConnectionFactory(Uri uriProvider, params object[] 
constructorParams)
                {
-                       this.factory = CreateConnectionFactory(uriProvider, 
constructorParams);
+                       this.factory = CreateConnectionFactory(uriProvider, 
constructorParams);
                }
 
                /// <summary>
@@ -69,7 +69,9 @@
                                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;
 #else
                                        object[] parameters = 
MakeParameterArray(uriProvider, constructorParams);
                                        connectionFactory = 
(IConnectionFactory) Activator.CreateInstance(factoryType, parameters);
@@ -277,6 +279,15 @@
                }
 
                /// <summary>
+               /// Get/or set the broker Uri.
+               /// </summary>
+               public Uri BrokerUri
+               {
+                       get { return ConnectionFactory.BrokerUri; }
+                       set { ConnectionFactory.BrokerUri = value; }
+               }
+
+               /// <summary>
                /// The actual IConnectionFactory implementation that is being 
used.  This implementation
                /// depends on the scheme of the URI used when constructed.
                /// </summary>

Modified: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs?rev=786327&r1=786326&r2=786327&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs 
(original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs 
Thu Jun 18 22:48:24 2009
@@ -120,15 +120,15 @@
                                clientId = 
ReplaceEnvVar(GetNodeValueAttribute(uriNode, "clientId", "NMSTestClientId"));
                                userName = 
ReplaceEnvVar(GetNodeValueAttribute(uriNode, "userName", "guest"));
                                passWord = 
ReplaceEnvVar(GetNodeValueAttribute(uriNode, "passWord", "guest"));
+                       }
 
-                               if(null == factoryParams)
-                               {
-                                       NMSFactory = new 
Apache.NMS.NMSConnectionFactory(brokerUri);
-                               }
-                               else
-                               {
-                                       NMSFactory = new 
Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams);
-                               }
+                       if(null == factoryParams)
+                       {
+                               NMSFactory = new 
Apache.NMS.NMSConnectionFactory(brokerUri);
+                       }
+                       else
+                       {
+                               NMSFactory = new 
Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams);
                        }
 
                        return (null != NMSFactory);


Reply via email to