/* * 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.Collections; using IBM.XMS; namespace Apache.NMS.XMS.Util { /// /// This class implements conversion methods between the IBM XMS and /// the Apache NMS models. /// public class XMSConvert { #region IBM XMS to Apache NMS objects conversion /// /// Converts an IBM XMS connection interface /// into an NMS connection interface. /// /// IBM XMS connection interface. /// Apache NMS connection interface. public static Apache.NMS.IConnection ToNMSConnection( IBM.XMS.IConnection xmsConnection) { return (xmsConnection != null ? new Apache.NMS.XMS.Connection(xmsConnection) : null); } /// /// Converts an IBM XMS session interface /// into an NMS session interface. /// /// IBM XMS session interface. /// Apache NMS session interface. public static Apache.NMS.ISession ToNMSSession( IBM.XMS.ISession xmsSession) { return (xmsSession != null ? new Apache.NMS.XMS.Session(xmsSession) : null); } /// /// Converts an IBM XMS destination interface /// into an NMS destination interface. /// /// XMS destination. /// Apache NMS destination interface. public static Apache.NMS.IDestination ToNMSDestination( IBM.XMS.IDestination xmsDestination) { return ToNMSDestination(xmsDestination, false); } /// /// Converts an IBM XMS destination interface /// into an NMS destination interface. /// /// XMS destination. /// Destination is temporary. /// Apache NMS destination interface. public static Apache.NMS.IDestination ToNMSDestination( IBM.XMS.IDestination xmsDestination, bool isTemporary) { if(xmsDestination.TypeId == IBM.XMS.DestinationType.Queue) { return (isTemporary ? ToNMSTemporaryQueue(xmsDestination) : ToNMSQueue(xmsDestination)); } if(xmsDestination.TypeId == IBM.XMS.DestinationType.Topic) { return (isTemporary ? ToNMSTemporaryTopic(xmsDestination) : ToNMSTopic(xmsDestination)); } return null; } /// /// Converts an IBM XMS queue interface /// into an NMS queue interface. /// /// XMS destination of type /// DestinationType.Queue. /// Apache NMS queue interface. public static Apache.NMS.IQueue ToNMSQueue( IBM.XMS.IDestination xmsQueue) { if((xmsQueue != null) && (xmsQueue.TypeId != IBM.XMS.DestinationType.Queue)) { throw new ArgumentException( "Cannot convert IBM XMS destination to NMS destination: invalid destination type id.", "xmsQueue"); } return (xmsQueue != null ? new Apache.NMS.XMS.Queue(xmsQueue) : null); } /// /// Converts an IBM XMS topic interface /// into an NMS topic interface. /// /// XMS destination of type /// DestinationType.Topic. /// Apache NMS topic interface. public static Apache.NMS.ITopic ToNMSTopic( IBM.XMS.IDestination xmsTopic) { if((xmsTopic != null) && (xmsTopic.TypeId != IBM.XMS.DestinationType.Topic)) { throw new ArgumentException( "Cannot convert IBM XMS destination to NMS destination: invalid destination type id.", "xmsTopic"); } return (xmsTopic != null ? new Apache.NMS.XMS.Topic(xmsTopic) : null); } /// /// Converts an IBM XMS temporary queue interface /// into an NMS temporary queue interface. /// /// XMS destination of type /// DestinationType.Queue. /// Apache NMS temporary queue interface. // Couldn't find a means to test whether a XMS destination is temporary. public static Apache.NMS.ITemporaryQueue ToNMSTemporaryQueue( IBM.XMS.IDestination xmsTemporaryQueue) { if((xmsTemporaryQueue != null) && (xmsTemporaryQueue.TypeId != IBM.XMS.DestinationType.Queue)) { throw new ArgumentException( "Cannot convert IBM XMS destination to NMS destination: invalid destination type id.", "xmsTemporaryQueue"); } return (xmsTemporaryQueue != null ? new Apache.NMS.XMS.TemporaryQueue(xmsTemporaryQueue) : null); } /// /// Converts an IBM XMS temporary topic interface /// into an NMS temporary topic interface. /// /// XMS destination of type /// DestinationType.Topic. /// Apache NMS temporary topic interface. // Couldn't find a means to test whether a XMS destination is temporary. public static Apache.NMS.ITemporaryTopic ToNMSTemporaryTopic( IBM.XMS.IDestination xmsTemporaryTopic) { if((xmsTemporaryTopic != null) && (xmsTemporaryTopic.TypeId != IBM.XMS.DestinationType.Queue)) { throw new ArgumentException( "Cannot convert IBM XMS destination to NMS destination: invalid destination type id.", "xmsTemporaryTopic"); } return (xmsTemporaryTopic != null ? new Apache.NMS.XMS.TemporaryTopic(xmsTemporaryTopic) : null); } /// /// Converts an IBM XMS message producer interface /// into an NMS message producer interface. /// /// NMS session. /// XMS message producer. /// Apache NMS message producer interface. public static Apache.NMS.IMessageProducer ToNMSMessageProducer( Apache.NMS.XMS.Session session, IBM.XMS.IMessageProducer xmsMessageProducer) { return (xmsMessageProducer != null ? new Apache.NMS.XMS.MessageProducer(session, xmsMessageProducer) : null); } /// /// Converts an IBM XMS message consumer interface /// into an NMS message consumer interface. /// /// NMS session. /// XMS message consumer. /// Apache NMS message consumer interface. public static Apache.NMS.IMessageConsumer ToNMSMessageConsumer( Apache.NMS.XMS.Session session, IBM.XMS.IMessageConsumer xmsMessageConsumer) { return (xmsMessageConsumer != null ? new Apache.NMS.XMS.MessageConsumer(session, xmsMessageConsumer) : null); } /// /// Converts an IBM XMS queue browser interface /// into an NMS queue browser interface. /// /// XMS queue browser. /// Apache NMS queue browser interface. public static Apache.NMS.IQueueBrowser ToNMSQueueBrowser( IBM.XMS.IQueueBrowser xmsQueueBrowser) { return (xmsQueueBrowser != null ? new Apache.NMS.XMS.QueueBrowser(xmsQueueBrowser) : null); } /// /// Converts an IBM XMS message /// into an NMS message. /// /// IBM XMS message. /// NMS message. public static Apache.NMS.IMessage ToNMSMessage(IBM.XMS.IMessage xmsMessage) { if(xmsMessage is IBM.XMS.ITextMessage) { return ToNMSTextMessage((IBM.XMS.ITextMessage)xmsMessage); } if(xmsMessage is IBM.XMS.IBytesMessage) { return ToNMSBytesMessage((IBM.XMS.IBytesMessage)xmsMessage); } if(xmsMessage is IBM.XMS.IStreamMessage) { return ToNMSStreamMessage((IBM.XMS.IStreamMessage)xmsMessage); } if(xmsMessage is IBM.XMS.IMapMessage) { return ToNMSMapMessage((IBM.XMS.IMapMessage)xmsMessage); } if(xmsMessage is IBM.XMS.IObjectMessage) { return ToNMSObjectMessage((IBM.XMS.IObjectMessage)xmsMessage); } return (xmsMessage != null ? new Apache.NMS.XMS.Message(xmsMessage) : null); } /// /// Converts an IBM XMS text message /// into an NMS text message. /// /// IBM XMS text message. /// NMS text message. public static Apache.NMS.ITextMessage ToNMSTextMessage( IBM.XMS.ITextMessage xmsTextMessage) { return (xmsTextMessage != null ? new Apache.NMS.XMS.TextMessage(xmsTextMessage) : null); } /// /// Converts an IBM XMS bytes message /// into an NMS bytes message. /// /// IBM XMS bytes message. /// NMS bytes message. public static Apache.NMS.IBytesMessage ToNMSBytesMessage( IBM.XMS.IBytesMessage xmsBytesMessage) { return (xmsBytesMessage != null ? new Apache.NMS.XMS.BytesMessage(xmsBytesMessage) : null); } /// /// Converts an IBM XMS stream message /// into an NMS stream message. /// /// IBM XMS stream message. /// NMS stream message. public static Apache.NMS.IStreamMessage ToNMSStreamMessage( IBM.XMS.IStreamMessage xmsStreamMessage) { return (xmsStreamMessage != null ? new Apache.NMS.XMS.StreamMessage(xmsStreamMessage) : null); } /// /// Converts an IBM XMS map message /// into an NMS map message. /// /// IBM XMS map message. /// NMS map message. public static Apache.NMS.IMapMessage ToNMSMapMessage( IBM.XMS.IMapMessage xmsMapMessage) { return (xmsMapMessage != null ? new Apache.NMS.XMS.MapMessage(xmsMapMessage) : null); } /// /// Converts an IBM XMS object message /// into an NMS object message. /// /// IBM XMS object message. /// NMS object message. public static Apache.NMS.IObjectMessage ToNMSObjectMessage( IBM.XMS.IObjectMessage xmsObjectMessage) { return (xmsObjectMessage != null ? new Apache.NMS.XMS.ObjectMessage(xmsObjectMessage) : null); } /// /// Converts an IBM XMS message /// into an NMS primitive map. /// /// IBM XMS message. /// NMS primitive map. public static Apache.NMS.IPrimitiveMap ToMessageProperties( IBM.XMS.IMessage xmsMessage) { return (xmsMessage != null ? new Apache.NMS.XMS.MessageProperties(xmsMessage) : null); } #endregion #region Apache NMS to IBM XMS objects conversion /// /// Converts an NMS destination /// into an IBM XMS destination. /// /// NMS destination. /// IBM XMS destination. public static IBM.XMS.IDestination ToXMSDestination( Apache.NMS.IDestination nmsDestination) { if(nmsDestination is Apache.NMS.XMS.Destination) { return ((Apache.NMS.XMS.Destination)nmsDestination).xmsDestination; } return null; } #endregion #region Property values conversion #region Exception handling /// /// Throws a conversion exception. /// private static void ThrowCantConvertValueException(object value, string conversionMethod) { throw new ArgumentException(string.Format( "Cannot convert {0} using {1}.", value, conversionMethod), conversionMethod); } #endregion #region Encoding /// /// Converts an XMS encoding key. /// /// Input value. /// Converted value. public static Encoding ToEncoding(Int32 inputValue) { return (Encoding)inputValue; } /// /// Converts an encoding to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSEncoding(Encoding inputValue) { return (Int32)inputValue; } #endregion #region Message Type /// /// Converts an XMS message type key. /// /// Input value. /// Converted value. public static MessageType ToMessageType(Int32 inputValue) { return (MessageType)inputValue; } /// /// Converts a message type to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSMessageType(MessageType inputValue) { return (Int32)inputValue; } #endregion #region Report Confirm On Arrival /// /// Converts an XMS "confirm on arrival" key. /// /// Input value. /// Converted value. public static ReportConfirmOnArrival ToReportConfirmOnArrival( Int32 inputValue) { return (ReportConfirmOnArrival)inputValue; } /// /// Converts a "confirm on arrival" to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReportConfirmOnArrival( ReportConfirmOnArrival inputValue) { return (Int32)inputValue; } #endregion #region Report Confirm On Delivery /// /// Converts an XMS "confirm on delivery" key. /// /// Input value. /// Converted value. public static ReportConfirmOnDelivery ToReportConfirmOnDelivery( Int32 inputValue) { return (ReportConfirmOnDelivery)inputValue; } /// /// Converts a "confirm on delivery" to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReportConfirmOnDelivery( ReportConfirmOnDelivery inputValue) { return (Int32)inputValue; } #endregion #region Report Exception /// /// Converts an XMS "report exceptions" key. /// /// Input value. /// Converted value. public static ReportExceptions ToReportExceptions( Int32 inputValue) { return (ReportExceptions)inputValue; } /// /// Converts a "report exceptions" to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReportExceptions( ReportExceptions inputValue) { return (Int32)inputValue; } #endregion #region Report Expiration /// /// Converts an XMS "report expiration" key. /// /// Input value. /// Converted value. public static ReportExpiration ToReportExpiration( Int32 inputValue) { return (ReportExpiration)inputValue; } /// /// Converts a "report expiration" to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReportExpiration( ReportExpiration inputValue) { return (Int32)inputValue; } #endregion #region Report Correlation Id /// /// Converts an XMS "report correlation id." key. /// /// Input value. /// Converted value. public static ReportCorrelationId ToReportCorrelationId( Int32 inputValue) { return (ReportCorrelationId)inputValue; } /// /// Converts a "report correlation id." to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReportCorrelationId( ReportCorrelationId inputValue) { return (Int32)inputValue; } #endregion #region Report Message Id /// /// Converts an XMS "report message id." key. /// /// Input value. /// Converted value. public static ReportMessageId ToReportMessageId( Int32 inputValue) { return (ReportMessageId)inputValue; } /// /// Converts a "report message id." to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReportMessageId( ReportMessageId inputValue) { return (Int32)inputValue; } #endregion #region Asynchronous Exceptions /// /// Converts an XMS asynchronous exceptions handling directive key. /// /// Input value. /// Converted value. public static AsynchronousExceptions ToAsynchronousExceptions( Int32 inputValue) { return (AsynchronousExceptions)inputValue; } /// /// Converts an asynchronous exceptions handling directive to the /// equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSAsynchronousExceptions( AsynchronousExceptions inputValue) { return (Int32)inputValue; } #endregion #region Connection Type /// /// Converts an XMS connection type key. /// /// Input value. /// Converted value. public static ConnectionType ToConnectionType(Int32 inputValue) { return (ConnectionType)inputValue; } /// /// Converts a connection type to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSConnectionType(ConnectionType inputValue) { return (Int32)inputValue; } #endregion #region Delivery Mode /// /// Converts an XMS delivery mode key. /// /// Input value. /// Converted value. public static DeliveryMode ToDeliveryMode(Int32 inputValue) { return (DeliveryMode)inputValue; } /// /// Converts a delivery mode to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSDeliveryMode(DeliveryMode inputValue) { return (Int32)inputValue; } #endregion #region Priority /// /// Converts an XMS priority key. /// /// Input value. /// Converted value. public static Priority ToPriority(Int32 inputValue) { return (Priority)inputValue; } /// /// Converts a priority to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSPriority(Priority inputValue) { return (Int32)inputValue; } #endregion #region Connection Protocol (RTT) /// /// Converts an RTT connection protocol key. /// /// Input value. /// Converted value. public static RTTConnectionProtocol ToRTTConnectionProtocol( Int32 inputValue) { return (RTTConnectionProtocol)inputValue; } /// /// Converts an RTT connection protocol to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSRTTConnectionProtocol( RTTConnectionProtocol inputValue) { return (Int32)inputValue; } #endregion #region Multicast (RTT) /// /// Converts an RTT multicast state key. /// /// Input value. /// Converted value. public static Multicast ToMulticast(Int32 inputValue) { return (Multicast)inputValue; } /// /// Converts a multicast state to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSMulticast(Multicast inputValue) { return (Int32)inputValue; } #endregion #region Broker Version (WMQ) /// /// Converts a WMQ broker version key. /// /// Input value. /// Converted value. public static BrokerVersion ToBrokerVersion(Int32 inputValue) { return (BrokerVersion)inputValue; } /// /// Converts a broker version to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSBrokerVersion(BrokerVersion inputValue) { return (Int32)inputValue; } #endregion #region Reconnect Options (WMQ) /// /// Converts a WMQ reconnect option key. /// /// Input value. /// Converted value. public static ReconnectOptions ToReconnectOptions(Int32 inputValue) { return (ReconnectOptions)inputValue; } /// /// Converts a reconnect option to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReconnectOptions(ReconnectOptions inputValue) { return (Int32)inputValue; } #endregion #region Connection Mode (WMQ) /// /// Converts a WMQ connection mode key. /// /// Input value. /// Converted value. public static ConnectionMode ToConnectionMode(Int32 inputValue) { return (ConnectionMode)inputValue; } /// /// Converts a connection mode to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSConnectionMode(ConnectionMode inputValue) { return (Int32)inputValue; } #endregion #region Fail If Quiesce (WMQ) /// /// Converts a WMQ yes/no key to the equivalent boolean. /// /// Input value. /// Converted value. public static bool ToFailIfQuiesce(Int32 inputValue) { switch(inputValue) { case XMSC.WMQ_FIQ_YES: return true; case XMSC.WMQ_FIQ_NO : return false; default: ThrowCantConvertValueException(inputValue, "ToFailIfQuiesce"); return false; } } /// /// Converts a WMQ boolean to the equivalent XMS yes/no value. /// /// Input value. /// Converted value. public static Int32 ToXMSFailIfQuiesce(bool inputValue) { return inputValue ? XMSC.WMQ_FIQ_YES : XMSC.WMQ_FIQ_NO; } #endregion #region Message Body (WMQ) /// /// Converts a WMQ message body key. /// /// Input value. /// Converted value. public static MessageBody ToMessageBody(Int32 inputValue) { return (MessageBody)inputValue; } /// /// Converts a message body to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSMessageBody(MessageBody inputValue) { return (Int32)inputValue; } #endregion #region Message Context (WMQ) /// /// Converts a WMQ message context key. /// /// Input value. /// Converted value. public static MessageContext ToMessageContext(Int32 inputValue) { return (MessageContext)inputValue; } /// /// Converts a message context to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSMessageContext(MessageContext inputValue) { return (Int32)inputValue; } #endregion #region MQMD Read Enabled (WMQ) /// /// Converts a WMQ yes/no key to the equivalent boolean. /// /// Input value. /// Converted value. public static bool ToMQMDReadEnabled(Int32 inputValue) { return (inputValue != 0); //switch(inputValue) //{ //case XMSC.WMQ_READ_ENABLED_YES: return true; //case XMSC.WMQ_READ_ENABLED_NO : return false; //default: // ThrowCantConvertValueException(inputValue, "ToMQMDReadEnabled"); // return false; //} } /// /// Converts a WMQ boolean to the equivalent XMS yes/no value. /// /// Input value. /// Converted value. public static Int32 ToXMSMQMDReadEnabled(bool inputValue) { return inputValue ? 1 : 0; // XMSC.WMQ_READ_ENABLED_YES : XMSC.WMQ_READ_ENABLED_NO; } #endregion #region MQMD Write Enabled (WMQ) /// /// Converts a WMQ yes/no key to the equivalent boolean. /// /// Input value. /// Converted value. public static bool ToMQMDWriteEnabled(Int32 inputValue) { return (inputValue != 0); //switch(inputValue) //{ //case XMSC.WMQ_WRITE_ENABLED_YES: return true; //case XMSC.WMQ_WRITE_ENABLED_NO : return false; //default: // ThrowCantConvertValueException(inputValue, "ToMQMDWriteEnabled"); // return false; //} } /// /// Converts a WMQ boolean to the equivalent XMS yes/no value. /// /// Input value. /// Converted value. public static Int32 ToXMSMQMDWriteEnabled(bool inputValue) { return inputValue ? 1 : 0; // XMSC.WMQ_WRITE_ENABLED_YES : XMSC.WMQ_WRITE_ENABLED_NO; } #endregion #region Asynchronous Puts Allowed (WMQ) /// /// Converts a WMQ asynchronous puts allowed key. /// /// Input value. /// Converted value. public static AsynchronousPutsAllowed ToAsynchronousPutsAllowed( Int32 inputValue) { return (AsynchronousPutsAllowed)inputValue; } /// /// Converts a WMQ asynchronous puts allowed to the equivalent /// XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSAsynchronousPutsAllowed( AsynchronousPutsAllowed inputValue) { return (Int32)inputValue; } #endregion #region Read Ahead Allowed (WMQ) /// /// Converts a WMQ read ahead allowed key. /// /// Input value. /// Converted value. public static ReadAheadAllowed ToReadAheadAllowed( Int32 inputValue) { return (ReadAheadAllowed)inputValue; } /// /// Converts a WMQ read ahead allowed to the equivalent /// XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReadAheadAllowed( ReadAheadAllowed inputValue) { return (Int32)inputValue; } #endregion #region Read Ahead Close Policy (WMQ) /// /// Converts a WMQ read ahead close policy key. /// /// Input value. /// Converted value. public static ReadAheadClosePolicy ToReadAheadClosePolicy( Int32 inputValue) { return (ReadAheadClosePolicy)inputValue; } /// /// Converts a WMQ read ahead close policy to the equivalent /// XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReadAheadClosePolicy( ReadAheadClosePolicy inputValue) { return (Int32)inputValue; } #endregion #region Message Selection (WMQ) /// /// Converts a WMQ message selection key. /// /// Input value. /// Converted value. public static MessageSelection ToMessageSelection(Int32 inputValue) { return (MessageSelection)inputValue; } /// /// Converts a WMQ message selection to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSMessageSelection(MessageSelection inputValue) { return (Int32)inputValue; } #endregion #region Receive Conversion (WMQ) /// /// Converts a WMQ receive conversion key. /// /// Input value. /// Converted value. public static ReceiveConversion ToReceiveConversion(Int32 inputValue) { return (ReceiveConversion)inputValue; } /// /// Converts a WMQ receive conversion to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSReceiveConversion(ReceiveConversion inputValue) { return (Int32)inputValue; } #endregion #region Share Socket Allowed (WMQ) /// /// Converts a WMQ yes/no key to the equivalent boolean. /// /// Input value. /// Converted value. public static bool ToShareSocketAllowed(Int32 inputValue) { switch(inputValue) { case XMSC.WMQ_SHARE_CONV_ALLOWED_YES: return true; case XMSC.WMQ_SHARE_CONV_ALLOWED_NO : return false; default: ThrowCantConvertValueException(inputValue, "ShareSocketAllowed"); return false; } } /// /// Converts a WMQ boolean to the equivalent XMS yes/no value. /// /// Input value. /// Converted value. public static Int32 ToXMSShareSocketAllowed(bool inputValue) { return inputValue ? XMSC.WMQ_SHARE_CONV_ALLOWED_YES : XMSC.WMQ_SHARE_CONV_ALLOWED_NO; } #endregion #region Target Client (WMQ) /// /// Converts a WMQ target client key. /// /// Input value. /// Converted value. public static TargetClient ToTargetClient(Int32 inputValue) { return (TargetClient)inputValue; } /// /// Converts a WMQ target client to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSTargetClient(TargetClient inputValue) { return (Int32)inputValue; } #endregion #region Wildcard Format (WMQ) /// /// Converts a WMQ wildcard format key. /// /// Input value. /// Converted value. public static WildcardFormat ToWildcardFormat(Int32 inputValue) { return (WildcardFormat)inputValue; } /// /// Converts a WMQ wildcard format to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSWildcardFormat(WildcardFormat inputValue) { return (Int32)inputValue; } #endregion #region Connection Protocol (WPM) /// /// Converts a WPM connection protocol key. /// /// Input value. /// Converted value. public static WPMConnectionProtocol ToWPMConnectionProtocol( Int32 inputValue) { return (WPMConnectionProtocol)inputValue; } /// /// Converts a WPM connection protocol to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSWPMConnectionProtocol( WPMConnectionProtocol inputValue) { return (Int32)inputValue; } #endregion #region Connection Proximity (WPM) /// /// Converts a WPM connection proximity key. /// /// Input value. /// Converted value. public static ConnectionProximity ToConnectionProximity( Int32 inputValue) { return (ConnectionProximity)inputValue; } /// /// Converts a WPM connection proximity to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSConnectionProximity( ConnectionProximity inputValue) { return (Int32)inputValue; } #endregion #region Mapping (WPM) /// /// Converts a WPM mapping key. /// /// Input value. /// Converted value. public static Mapping ToMapping(Int32 inputValue) { return (Mapping)inputValue; } /// /// Converts a WPM mapping to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSMapping(Mapping inputValue) { return (Int32)inputValue; } #endregion #region Target Significance (WPM) /// /// Converts a WPM target significance key. /// /// Input value. /// Converted value. public static TargetSignificance ToTargetSignificance( Int32 inputValue) { return (TargetSignificance)inputValue; } /// /// Converts a WPM target significance to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSTargetSignificance( TargetSignificance inputValue) { return (Int32)inputValue; } #endregion #region Target Type (WPM) /// /// Converts a WPM target type key. /// /// Input value. /// Converted value. public static TargetType ToTargetType(Int32 inputValue) { return (TargetType)inputValue; } /// /// Converts a WPM target type to the equivalent XMS value. /// /// Input value. /// Converted value. public static Int32 ToXMSTargetType(TargetType inputValue) { return (Int32)inputValue; } #endregion #endregion #region IBM XMS to Apache NMS enumerations conversion /// /// Converts an IBM XMS destination type /// to the equivalent NMS value. /// /// XMS destination type. /// Whether the destination is temporary. /// /// NMS destination type. public static DestinationType ToDestinationType( IBM.XMS.DestinationType xmsDestinationType, bool isTemporary) { switch(xmsDestinationType) { case IBM.XMS.DestinationType.Queue: return(isTemporary ? DestinationType.TemporaryQueue : DestinationType.Queue); case IBM.XMS.DestinationType.Topic: return(isTemporary ? DestinationType.TemporaryTopic : DestinationType.Queue); default: ThrowCantConvertValueException( xmsDestinationType.ToString(), "ToDestinationType"); return DestinationType.Queue; } } /// /// Converts an IBM XMS acknowledgement mode /// to the equivalent NMS value. /// /// XMS acknowledgement mode. /// NMS acknowledgement mode. public static Apache.NMS.AcknowledgementMode ToAcknowledgementMode( IBM.XMS.AcknowledgeMode acknowledgeMode) { Apache.NMS.AcknowledgementMode acknowledge = Apache.NMS.AcknowledgementMode.AutoAcknowledge; switch(acknowledgeMode) { case IBM.XMS.AcknowledgeMode.AutoAcknowledge: acknowledge = Apache.NMS.AcknowledgementMode.AutoAcknowledge; break; case IBM.XMS.AcknowledgeMode.ClientAcknowledge: acknowledge = Apache.NMS.AcknowledgementMode.ClientAcknowledge; break; case IBM.XMS.AcknowledgeMode.DupsOkAcknowledge: acknowledge = Apache.NMS.AcknowledgementMode.DupsOkAcknowledge; break; case IBM.XMS.AcknowledgeMode.SessionTransacted: acknowledge = Apache.NMS.AcknowledgementMode.Transactional; break; } return acknowledge; } /// /// Converts an IBM XMS delivery mode /// to the equivalent NMS value. /// /// XMS delivery mode. /// NMS delivery mode. public static MsgDeliveryMode ToNMSMsgDeliveryMode( IBM.XMS.DeliveryMode deliveryMode) { if(deliveryMode == IBM.XMS.DeliveryMode.Persistent) { return MsgDeliveryMode.Persistent; } if(deliveryMode == IBM.XMS.DeliveryMode.NonPersistent) { return MsgDeliveryMode.NonPersistent; } // Hard cast it to the enumeration. return (MsgDeliveryMode) deliveryMode; } #endregion #region Apache NMS to IBM XMS enumerations conversion /// /// Converts an NMS acknowledgement mode /// to the equivalent IBM XMS value. /// /// NMS acknowledgement mode. /// IBM XMS acknowledgement mode. public static IBM.XMS.AcknowledgeMode ToAcknowledgeMode( Apache.NMS.AcknowledgementMode acknowledge) { IBM.XMS.AcknowledgeMode acknowledgeMode = (IBM.XMS.AcknowledgeMode)0; switch(acknowledge) { case Apache.NMS.AcknowledgementMode.AutoAcknowledge: acknowledgeMode = IBM.XMS.AcknowledgeMode.AutoAcknowledge; break; case Apache.NMS.AcknowledgementMode.ClientAcknowledge: acknowledgeMode = IBM.XMS.AcknowledgeMode.ClientAcknowledge; break; case Apache.NMS.AcknowledgementMode.DupsOkAcknowledge: acknowledgeMode = IBM.XMS.AcknowledgeMode.DupsOkAcknowledge; break; case Apache.NMS.AcknowledgementMode.Transactional: acknowledgeMode = IBM.XMS.AcknowledgeMode.SessionTransacted; break; } return acknowledgeMode; } /// /// Converts an NMS delivery mode /// to the equivalent IBM XMS value. /// /// NMS delivery mode. /// IBM XMS delivery mode. public static IBM.XMS.DeliveryMode ToJMSDeliveryMode( MsgDeliveryMode deliveryMode) { if(deliveryMode == MsgDeliveryMode.Persistent) { return IBM.XMS.DeliveryMode.Persistent; } if(deliveryMode == MsgDeliveryMode.NonPersistent) { return IBM.XMS.DeliveryMode.NonPersistent; } // Hard cast it to the enumeration. return (IBM.XMS.DeliveryMode) deliveryMode; } #endregion #region Enumerable adapter private class EnumerableAdapter : IEnumerable { private readonly IEnumerator enumerator; public EnumerableAdapter(IEnumerator _enumerator) { this.enumerator = _enumerator; } public IEnumerator GetEnumerator() { return this.enumerator; } } public static IEnumerable ToEnumerable(IEnumerator enumerator) { return new EnumerableAdapter(enumerator); } #endregion } }