From 0c68ebef384a47b30e50a6e017a87e4641222a39 Mon Sep 17 00:00:00 2001 From: markpollack Date: Thu, 14 Aug 2008 21:15:03 +0000 Subject: [PATCH] Added MSMQ gateway base class. --- .../Core/MessageQueueGatewaySupport.cs | 85 +++++++++++++++++++ .../Spring.Messaging.2005.csproj | 1 + 2 files changed, 86 insertions(+) create mode 100644 src/Spring/Spring.Messaging/Messaging/Core/MessageQueueGatewaySupport.cs diff --git a/src/Spring/Spring.Messaging/Messaging/Core/MessageQueueGatewaySupport.cs b/src/Spring/Spring.Messaging/Messaging/Core/MessageQueueGatewaySupport.cs new file mode 100644 index 00000000..1bc68813 --- /dev/null +++ b/src/Spring/Spring.Messaging/Messaging/Core/MessageQueueGatewaySupport.cs @@ -0,0 +1,85 @@ +#region License + +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed 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. + */ + +#endregion + +using System; +using Spring.Context; +using Spring.Objects.Factory; + +namespace Spring.Messaging.Core +{ + /// + /// Convenient super class for application classes that need MSMQ access. + /// + /// + /// Override the InitGateway method to perform custom startup tasks. + /// + /// Mark Pollack + public class MessageQueueGatewaySupport : IInitializingObject + { + private MessageQueueTemplate messageQueueTemplate; + + + /// + /// Gets or sets the message queue template. . + /// + /// The message queue template. + public MessageQueueTemplate MessageQueueTemplate + { + get { return messageQueueTemplate; } + set { messageQueueTemplate = value; } + } + + /// + /// Gets the message queue factory, a convenience method. + /// + /// The message queue factory. + protected IMessageQueueFactory MessageQueueFactory + { + get { return MessageQueueTemplate.MessageQueueFactory; } + } + + + public void AfterPropertiesSet() + { + if (this.MessageQueueTemplate == null) + { + throw new ArgumentException("MessageQueueTemplate is required"); + } + try + { + InitGateway(); + } + catch (Exception e) + { + throw new ObjectInitializationException("Initialization of the MessageQueue gateway failed: " + e.Message, e); + } + } + + + /// + /// Subclasses can override this for custom initialization behavior. + /// Gets called after population of this instance's properties. + /// + protected virtual void InitGateway() + { + + } + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj b/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj index e5dc190b..110b5da1 100644 --- a/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj +++ b/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj @@ -51,6 +51,7 @@ +