Skip to content
Permalink
Browse files
Added extension methods for IMessage, IMessageProducer, and ISession.
  • Loading branch information
Jim Gomes committed Nov 10, 2009
1 parent 597a912 commit c7ef1597f0cb0e7268896395dc9e1970b070a305
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 115 deletions.
@@ -47,12 +47,23 @@
</target>

<target name="dependency-init" description="Initializes build dependencies">
<assemblyfileset failonempty="true" id="dependencies">
<include name="${current.build.framework.assembly.dir}/mscorlib.dll" />
<include name="${current.build.framework.assembly.dir}/System.dll" />
<include name="${current.build.framework.assembly.dir}/System.Web.dll" />
<include name="${current.build.framework.assembly.dir}/System.Xml.dll" />
</assemblyfileset>
<if test="${current.build.framework == 'net-3.5' or current.build.framework == 'mono-2.0'}">
<assemblyfileset failonempty="true" id="dependencies">
<include name="${current.build.framework.assembly.dir}/mscorlib.dll" />
<include name="${current.build.framework.assembly.dir}/System.dll" />
<include name="${current.build.framework.assembly.dir}/System.Core.dll" />
<include name="${current.build.framework.assembly.dir}/System.Web.dll" />
<include name="${current.build.framework.assembly.dir}/System.Xml.dll" />
</assemblyfileset>
</if>
<if test="${current.build.framework != 'net-3.5'}">
<assemblyfileset failonempty="true" id="dependencies">
<include name="${current.build.framework.assembly.dir}/mscorlib.dll" />
<include name="${current.build.framework.assembly.dir}/System.dll" />
<include name="${current.build.framework.assembly.dir}/System.Web.dll" />
<include name="${current.build.framework.assembly.dir}/System.Xml.dll" />
</assemblyfileset>
</if>

<assemblyfileset failonempty="true" id="test.dependencies">
<include name="${current.build.framework.assembly.dir}/mscorlib.dll" />
@@ -0,0 +1,53 @@
/*
* 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;
using Apache.NMS.Util;

namespace Apache.NMS
{
#if NET_3_5 || MONO
public static class MessageExtensions
{
/// <summary>
/// Deserializes the object from Xml, and returns it.
/// </summary>
public static object ToObject(this IMessage message)
{
if(null != message)
{
return NMSConvert.DeserializeObjFromMessage(message);
}

return null;
}

/// <summary>
/// Deserializes the object from Xml, and returns it.
/// </summary>
public static T ToObject<T>(this IMessage message) where T : class
{
if(null != message)
{
return (T) NMSConvert.DeserializeObjFromMessage(message);
}

return null;
}
}
#endif
}
@@ -0,0 +1,108 @@
/*
* 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;
using System.Text;
using Apache.NMS.Util;

namespace Apache.NMS
{
#if NET_3_5 || MONO
public static class MessageProducerExtensions
{
/// <summary>
/// Extension function to create a text message from an object. The object must be serializable to XML.
/// </summary>
public static ITextMessage CreateXmlMessage(this IMessageProducer producer, object obj)
{
return CreateXmlMessage(producer, obj, Encoding.Unicode);
}

/// <summary>
/// Extension function to create a text message from an object. The object must be serializable to XML.
/// </summary>
public static ITextMessage CreateXmlMessage(this IMessageProducer producer, object obj, Encoding encoding)
{
return NMSConvert.SerializeObjToMessage(producer.CreateTextMessage(), obj, encoding);
}

/// <summary>
/// Sends the message to the default destination for this producer. The object must be serializable to XML.
/// </summary>
public static void Send(this IMessageProducer producer, object objMessage)
{
producer.Send(producer.CreateXmlMessage(objMessage));
}

/// <summary>
/// Sends the message to the default destination for this producer. The object must be serializable to XML.
/// </summary>
public static void Send(this IMessageProducer producer, object objMessage, Encoding encoding)
{
producer.Send(producer.CreateXmlMessage(objMessage, encoding));
}

/// <summary>
/// Sends the message to the default destination with the explicit QoS configuration. The object must be serializable to XML.
/// </summary>
public static void Send(this IMessageProducer producer, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
{
producer.Send(producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive);
}

/// <summary>
/// Sends the message to the default destination with the explicit QoS configuration. The object must be serializable to XML.
/// </summary>
public static void Send(this IMessageProducer producer, object objMessage, Encoding encoding, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
{
producer.Send(producer.CreateXmlMessage(objMessage, encoding), deliveryMode, priority, timeToLive);
}

/// <summary>
/// Sends the message to the given destination
/// </summary>
public static void Send(this IMessageProducer producer, IDestination destination, object objMessage)
{
producer.Send(destination, producer.CreateXmlMessage(objMessage));
}

/// <summary>
/// Sends the message to the given destination
/// </summary>
public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, Encoding encoding)
{
producer.Send(destination, producer.CreateXmlMessage(objMessage, encoding));
}

/// <summary>
/// Sends the message to the given destination with the explicit QoS configuration. The object must be serializable to XML.
/// </summary>
public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
{
producer.Send(destination, producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive);
}

/// <summary>
/// Sends the message to the given destination with the explicit QoS configuration. The object must be serializable to XML.
/// </summary>
public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, Encoding encoding, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
{
producer.Send(destination, producer.CreateXmlMessage(objMessage, encoding), deliveryMode, priority, timeToLive);
}
}
#endif
}
@@ -0,0 +1,109 @@
/*
* 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.Text;
using Apache.NMS.Util;

namespace Apache.NMS
{
#if NET_3_5 || MONO
public static class SessionExtensions
{
/// <summary>
/// Extension function to create a text message from an object. The object must be serializable to XML.
/// </summary>
public static ITextMessage CreateXmlMessage(this ISession session, object obj)
{
return CreateXmlMessage(session, obj, Encoding.Unicode);
}

/// <summary>
/// Extension function to create a text message from an object. The object must be serializable to XML.
/// </summary>
public static ITextMessage CreateXmlMessage(this ISession session, object obj, Encoding encoding)
{
return NMSConvert.SerializeObjToMessage(session.CreateTextMessage(), obj, encoding);
}

/// <summary>
/// Extension function to get the destination by parsing the embedded type prefix. Default is Queue if no prefix is
/// embedded in the destinationName.
/// </summary>
public static IDestination GetDestination(this ISession session, string destinationName)
{
return SessionUtil.GetDestination(session, destinationName);
}

/// <summary>
/// Extension function to get the destination by parsing the embedded type prefix.
/// </summary>
public static IDestination GetDestination(this ISession session, string destinationName, DestinationType defaultType)
{
return SessionUtil.GetDestination(session, destinationName, defaultType);
}

/// <summary>
/// Extension function to get the destination by parsing the embedded type prefix.
/// </summary>
public static IQueue GetQueue(this ISession session, string queueName)
{
return SessionUtil.GetQueue(session, queueName);
}

/// <summary>
/// Extension function to get the destination by parsing the embedded type prefix.
/// </summary>
public static ITopic GetTopic(this ISession session, string topicName)
{
return SessionUtil.GetTopic(session, topicName);
}

/// <summary>
/// Extension function to delete the named destination by parsing the embedded type prefix. Default is Queue if no prefix is
/// embedded in the destinationName.
/// </summary>
public static void DeleteDestination(this ISession session, string destinationName)
{
SessionUtil.DeleteDestination(session, destinationName);
}

/// <summary>
/// Extension function to delete the named destination by parsing the embedded type prefix.
/// </summary>
public static void DeleteDestination(this ISession session, string destinationName, DestinationType defaultType)
{
SessionUtil.DeleteDestination(session, destinationName, defaultType);
}

/// <summary>
/// Extension function to delete the named destination by parsing the embedded type prefix.
/// </summary>
public static void DeleteQueue(this ISession session, string queueName)
{
SessionUtil.DeleteDestination(session, queueName);
}

/// <summary>
/// Extension function to delete the named destination by parsing the embedded type prefix.
/// </summary>
public static void DeleteTopic(this ISession session, string topicName)
{
SessionUtil.DeleteDestination(session, topicName);
}
}
#endif
}

0 comments on commit c7ef159

Please sign in to comment.