NMS development

This commit is contained in:
markpollack
2008-07-25 04:53:19 +00:00
parent b6f610230f
commit a530e4720b
13 changed files with 166 additions and 17 deletions

View File

@@ -199,7 +199,86 @@ namespace Spring.Util
throw new ArgumentNullException("Collection cannot be null.");
}
return new ArrayList(inputCollection);
}
}
/// <summary>
/// Finds a value of the given type in the given collection.
/// </summary>
/// <param name="collection">The collection to search.</param>
/// <param name="type">The type to look for.</param>
/// <returns>a value of the given type found, or null if none.</returns>
/// <exception cref="ArgumentException">If more than one value of the given type is found</exception>
public static object FindValueOfType(ICollection collection, Type type)
{
if (IsEmpty(collection))
{
return null;
}
Type typeToUse = (type != null ? type : typeof (object));
object val = null;
foreach (object obj in collection)
{
if (typeToUse.IsAssignableFrom(obj.GetType()))
{
if (val != null)
{
throw new ArgumentException("More than one value of type[" + typeToUse.Name + "] found.");
}
val = obj;
}
}
return val;
}
/// <summary>
/// Find a value of one of the given types in the given Collection,
/// searching the Collection for a value of the first type, then
/// searching for a value of the second type, etc.
/// </summary>
/// <param name="collection">The collection to search.</param>
/// <param name="types">The types to look for, in prioritized order.</param>
/// <returns>a value of the given types found, or <code>null</code> if none</returns>
/// <exception cref="ArgumentException">If more than one value of the given type is found</exception>
public static object FindValueOfType(ICollection collection, Type[] types)
{
if (IsEmpty(collection) || ObjectUtils.IsEmpty(types))
{
return null;
}
foreach (Type type in types)
{
object val = FindValueOfType(collection, type);
if (val != null)
{
return val;
}
}
return null;
}
/// <summary>
/// Determines whether the specified collection is null or empty.
/// </summary>
/// <param name="collection">The collection to check.</param>
/// <returns>
/// <c>true</c> if the specified collection is empty or null; otherwise, <c>false</c>.
/// </returns>
public static bool IsEmpty(ICollection collection)
{
return (collection == null || collection.Count == 0);
}
/// <summary>
/// Determines whether the specified dictionary is null empty.
/// </summary>
/// <param name="dictionary">The dictionary to check.</param>
/// <returns>
/// <c>true</c> if the specified dictionary is empty or null; otherwise, <c>false</c>.
/// </returns>
public static bool IsEmpty(IDictionary dictionary)
{
return (dictionary == null || dictionary.Count == 0);
}
#endregion
}

View File

@@ -355,6 +355,18 @@ namespace Spring.Util
|| typeof(double[]).Equals(type);
}
/// <summary>
/// Determines whether the specified array is null or empty.
/// </summary>
/// <param name="array">The array to check.</param>
/// <returns>
/// <c>true</c> if the specified array is null empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsEmpty(object[] array)
{
return (array == null || array.Length == 0);
}
/// <summary>
/// Determine if the given objects are equal, returning <see langword="true"/>
/// if both are <see langword="null"/> respectively <see langword="false"/>

View File

@@ -451,18 +451,18 @@ namespace Spring.Transaction.Support
/// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.
/// </param>
/// <remarks>
/// <p>
/// <para>
/// Called after <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit"/>
/// and
/// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback"/>
/// execution on any outcome.
/// </p>
/// <p>
/// </para>
/// <para>
/// Should not throw any exceptions but just issue warnings on errors.
/// </p>
/// <p>
/// </para>
/// <para>
/// Default implementation does nothing.
/// </p>
/// </para>
/// </remarks>
protected virtual void DoCleanupAfterCompletion(object transaction)
{

View File

@@ -251,7 +251,7 @@ namespace Spring.Messaging.Listener
}
protected virtual string GetListenerMethodName(Message originalMessage, object extractedMessage)
protected virtual string GetHandlerMethodName(Message originalMessage, object extractedMessage)
{
return DefaultHandlerMethod;
}

View File

@@ -133,6 +133,10 @@ namespace Spring.Messaging.Support
#region IFactoryObject Members
/// <summary>
/// Retrun a configured MessageQueue object.
/// </summary>
/// <returns>A newly configured MessageQueue object</returns>
public object GetObject()
{
MessageQueue.EnableConnectionCache = enableConnectionCache;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using NUnit.Framework;
using Spring.Objects;
namespace Spring.Util
{
@@ -301,5 +302,58 @@ namespace Spring.Util
CollectionUtils.RemoveAll(target, source);
Assert.IsTrue(0 == target.Count);
}
[Test]
public void IsCollectionEmptyOrNull()
{
ArrayList list = new ArrayList();
Assert.IsTrue(CollectionUtils.IsEmpty(list));
list.Add("foo");
Assert.IsFalse(CollectionUtils.IsEmpty(list));
list = null;
Assert.IsTrue(CollectionUtils.IsEmpty(list));
}
[Test]
public void IsDictionaryEmptyOrNull()
{
Hashtable t = new Hashtable();
Assert.IsTrue(CollectionUtils.IsEmpty(t));
t["foo"] = "bar";
Assert.IsFalse(CollectionUtils.IsEmpty(t));
t = null;
Assert.IsTrue(CollectionUtils.IsEmpty(t));
}
[Test]
public void FindValueOfType()
{
ArrayList list = new ArrayList();
Assert.IsNull(CollectionUtils.FindValueOfType(list, typeof(String)));
list.Add("foo");
object obj = CollectionUtils.FindValueOfType(list, typeof (String));
Assert.IsNotNull(obj);
Assert.IsNotNull(obj as string);
string val = obj as string;
Assert.AreEqual("foo", val);
list.Add(new TestObject("Joe", 34));
obj = CollectionUtils.FindValueOfType(list, typeof (TestObject));
Assert.IsNotNull(obj);
TestObject to = obj as TestObject;
Assert.IsNotNull(to);
Assert.AreEqual("Joe", to.Name);
list.Add(new TestObject("Mary", 33));
try
{
obj = CollectionUtils.FindValueOfType(list, typeof(TestObject));
Assert.Fail("Should have thrown exception");
} catch (ArgumentException)
{
//ok
}
}
}
}

View File

@@ -26,7 +26,7 @@ using Rhino.Mocks;
#endregion
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
/// <summary>
/// This class contains tests for

View File

@@ -24,13 +24,13 @@ using System;
using Apache.NMS;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Messaging.Nms.Connection;
using Spring.Messaging.Nms.Connections;
using Spring.Transaction;
using Spring.Transaction.Support;
#endregion
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
/// <summary>
/// This class contains tests for

View File

@@ -24,11 +24,11 @@ using System;
using Apache.NMS;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Messaging.Nms.Connection;
using Spring.Messaging.Nms.Connections;
#endregion
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
/// <summary>
/// This class contains tests for the SingleConnectionFactory

View File

@@ -1,7 +1,7 @@
using System;
using Apache.NMS;
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
public class TestConnection : IConnection
{

View File

@@ -20,7 +20,7 @@
using System;
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
public class TestExceptionListener : IExceptionListener
{

View File

@@ -21,7 +21,7 @@
using System;
using Apache.NMS;
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
public class TestMessageProducer : IMessageProducer

View File

@@ -21,7 +21,7 @@
using System;
using Apache.NMS;
namespace Spring.Messaging.Nms.Connection
namespace Spring.Messaging.Nms.Connections
{
public class TestSession : ISession