diff options
| author | Tomas Restrepo <tomasr@apache.org> | 2007-05-18 00:51:12 +0000 |
|---|---|---|
| committer | Tomas Restrepo <tomasr@apache.org> | 2007-05-18 00:51:12 +0000 |
| commit | dbe349500e458cdf38cd4e561d27c9fa24dff7ca (patch) | |
| tree | 2390c50d9a0d31506b6e9007ab7dfed5bb51ad16 /dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs | |
| parent | ee94c939a9d77f0de6ae0cb33c782a9015bb8452 (diff) | |
| download | qpid-python-dbe349500e458cdf38cd4e561d27c9fa24dff7ca.tar.gz | |
Merged revisions 537954-538078,538080-538083,538085-538097,538099-538108,538110-538239,538241-538881,538883-538906,538908-538911,538913-538921,538923-539191 via svnmerge from
https://svn.apache.org/repos/asf/incubator/qpid/branches/M2
........
r537954 | tomasr | 2007-05-14 14:10:59 -0500 (Mon, 14 May 2007) | 4 lines
* QPID-487 (Contributed by Carlos Medina) Fix QpidConnectionInfo.ToString()
* QPID-485 (Contributed by Carlos Medina) Fix AmqBrokerInfo.Equals()
* QPID-456 Enforce virtual host names start with '/'
........
r538035 | tomasr | 2007-05-14 20:33:00 -0500 (Mon, 14 May 2007) | 6 lines
* QPID-452 Improve message classes API
* Add XML documentation to IChannel and IMessage
* Add missing BrokerDetailTests
* Add new tests for message creation and message factories
* Fix wrong default encoding for text messages
........
r539178 | tomasr | 2007-05-17 18:50:50 -0500 (Thu, 17 May 2007) | 6 lines
* QPID-492 Fix Race condition in message decoding
* QPID-249 Make ServiceRequestingClient and ServiceProvidingClient a single, self contained test
* Fix incorrect exception message in Qpid.Buffers, improve tests
* Make ContentBody use an sliced buffer to avoid extra data copy
* Remove useless tests in Qpid.Client (Blocking IO tests)
........
r539191 | tomasr | 2007-05-17 19:18:26 -0500 (Thu, 17 May 2007) | 1 line
QPID-490 (Contributed by Carlos Medina) Implement PurgeQueue and DeleteQueue
........
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@539198 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs')
| -rw-r--r-- | dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs | 173 |
1 files changed, 92 insertions, 81 deletions
diff --git a/dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs b/dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs index 95257cef8a..f854a541fc 100644 --- a/dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs +++ b/dotnet/Qpid.Client/Client/Message/MessageFactoryRegistry.cs @@ -25,93 +25,104 @@ using Qpid.Messaging; namespace Qpid.Client.Message { - public class MessageFactoryRegistry - { - private readonly Hashtable _mimeToFactoryMap = new Hashtable(); + public class MessageFactoryRegistry + { + private readonly Hashtable _mimeToFactoryMap = new Hashtable(); + private IMessageFactory _defaultFactory; - public void RegisterFactory(string mimeType, IMessageFactory mf) - { - if (mf == null) - { - throw new ArgumentNullException("Message factory"); - } - if (mimeType == null) - { - throw new ArgumentNullException("mf"); - } - _mimeToFactoryMap[mimeType] = mf; - } + /// <summary> + /// Default factory to use for unknown message types + /// </summary> + public IMessageFactory DefaultFactory + { + get { return _defaultFactory; } + set { _defaultFactory = value; } + } - public void DeregisterFactory(string mimeType) - { - _mimeToFactoryMap.Remove(mimeType); - } + /// <summary> + /// Register a new message factory for a MIME type + /// </summary> + /// <param name="mimeType">Mime type to register</param> + /// <param name="mf"></param> + public void RegisterFactory(string mimeType, IMessageFactory mf) + { + if ( mf == null ) + throw new ArgumentNullException("mf"); + if ( mimeType == null || mimeType.Length == 0 ) + throw new ArgumentNullException("mimeType"); - /// <summary> - /// Create a message. This looks up the MIME type from the content header and instantiates the appropriate - /// concrete message type. - /// </summary> - /// <param name="messageNbr">the AMQ message id</param> - /// <param name="redelivered">true if redelivered</param> - /// <param name="contentHeader">the content header that was received</param> - /// <param name="bodies">a list of ContentBody instances</param> - /// <returns>the message.</returns> - /// <exception cref="AMQException"/> - /// <exception cref="QpidException"/> - public AbstractQmsMessage CreateMessage(long messageNbr, bool redelivered, - ContentHeaderBody contentHeader, - IList bodies) - { - BasicContentHeaderProperties properties = (BasicContentHeaderProperties) contentHeader.Properties; + _mimeToFactoryMap[mimeType] = mf; + } - if (properties.ContentType == null) - { - properties.ContentType = ""; - } + /// <summary> + /// Remove a message factory + /// </summary> + /// <param name="mimeType">MIME type to unregister</param> + public void DeregisterFactory(string mimeType) + { + _mimeToFactoryMap.Remove(mimeType); + } - IMessageFactory mf = (IMessageFactory) _mimeToFactoryMap[properties.ContentType]; - if (mf == null) - { - throw new AMQException("Unsupport MIME type of " + properties.ContentType); - } - else - { - return mf.CreateMessage(messageNbr, redelivered, contentHeader, bodies); - } - } + /// <summary> + /// Create a message. This looks up the MIME type from the content header and instantiates the appropriate + /// concrete message type. + /// </summary> + /// <param name="messageNbr">the AMQ message id</param> + /// <param name="redelivered">true if redelivered</param> + /// <param name="contentHeader">the content header that was received</param> + /// <param name="bodies">a list of ContentBody instances</param> + /// <returns>the message.</returns> + /// <exception cref="AMQException"/> + /// <exception cref="QpidException"/> + public AbstractQmsMessage CreateMessage(long messageNbr, bool redelivered, + ContentHeaderBody contentHeader, + IList bodies) + { + BasicContentHeaderProperties properties = (BasicContentHeaderProperties)contentHeader.Properties; - public AbstractQmsMessage CreateMessage(string mimeType) - { - if (mimeType == null) - { - throw new ArgumentNullException("Mime type must not be null"); - } - IMessageFactory mf = (IMessageFactory) _mimeToFactoryMap[mimeType]; - if (mf == null) - { - throw new AMQException("Unsupport MIME type of " + mimeType); - } - else - { - return mf.CreateMessage(); - } - } + if ( properties.ContentType == null ) + { + properties.ContentType = ""; + } - /// <summary> - /// Construct a new registry with the default message factories registered - /// </summary> - /// <returns>a message factory registry</returns> - public static MessageFactoryRegistry NewDefaultRegistry() - { - MessageFactoryRegistry mf = new MessageFactoryRegistry(); - mf.RegisterFactory("text/plain", new QpidTextMessageFactory()); - mf.RegisterFactory("text/xml", new QpidTextMessageFactory()); - mf.RegisterFactory("application/octet-stream", new QpidBytesMessageFactory()); - // TODO: use bytes message for default message factory - // MJA - just added this bit back in... - mf.RegisterFactory("", new QpidBytesMessageFactory()); - return mf; - } - } + IMessageFactory mf = GetFactory(properties.ContentType); + return mf.CreateMessage(messageNbr, redelivered, contentHeader, bodies); + } + + /// <summary> + /// Create a new message of the specified type + /// </summary> + /// <param name="mimeType">The Mime type</param> + /// <returns>The new message</returns> + public AbstractQmsMessage CreateMessage(string mimeType) + { + if ( mimeType == null || mimeType.Length == 0 ) + throw new ArgumentNullException("mimeType"); + + IMessageFactory mf = GetFactory(mimeType); + return mf.CreateMessage(mimeType); + } + + /// <summary> + /// Construct a new registry with the default message factories registered + /// </summary> + /// <returns>a message factory registry</returns> + public static MessageFactoryRegistry NewDefaultRegistry() + { + MessageFactoryRegistry mf = new MessageFactoryRegistry(); + mf.RegisterFactory("text/plain", new QpidTextMessageFactory()); + mf.RegisterFactory("text/xml", new QpidTextMessageFactory()); + mf.RegisterFactory("application/octet-stream", new QpidBytesMessageFactory()); + + mf.DefaultFactory = new QpidBytesMessageFactory(); + return mf; + } + + private IMessageFactory GetFactory(string mimeType) + { + IMessageFactory mf = (IMessageFactory)_mimeToFactoryMap[mimeType]; + return mf != null ? mf : _defaultFactory; + } + } } |
