Skip to content
Permalink
Browse files
Add support for setting the broker Uri after the connection factory i…
…s 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.
  • Loading branch information
Jim Gomes committed Jun 18, 2009
1 parent d1a32a7 commit a95290d13aae7644335a1a14aedaf5cb5006f907
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
@@ -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 @@ public interface IConnectionFactory
/// 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; }
}
}


@@ -48,7 +48,7 @@ public NMSConnectionFactory(string providerURI, params object[] constructorParam
/// <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 @@ public static IConnectionFactory CreateConnectionFactory(Uri uriProvider, params
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);
@@ -276,6 +278,15 @@ public IConnection CreateConnection(string userName, string password)
return this.factory.CreateConnection(userName, password);
}

/// <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.
@@ -120,15 +120,15 @@ protected bool CreateNMSFactory(string nameTestURI)
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);

0 comments on commit a95290d

Please sign in to comment.