Author: jgomes
Date: Tue Aug 26 17:16:05 2008
New Revision: 689294

URL: http://svn.apache.org/viewvc?rev=689294&view=rev
Log:
Refactor properties to set extension header properties automatically.
Fixes [AMQNET-108]. (See https://issues.apache.org/activemq/browse/AMQNET-108)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/WireFormatInfo.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/MessagePropertyHelper.cs

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config?rev=689294&r1=689293&r2=689294&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config 
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config 
Tue Aug 26 17:16:05 2008
@@ -16,7 +16,7 @@
 * limitations under the License.
 -->
 <configuration>
-       <defaultURI value="activemq:tcp://jgomesv1:61616">
+       <defaultURI value="activemq:tcp://devgvapp1:61616">
                <factoryParams/>
                <userName value="guest"/>
                <passWord value="guest"/>

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs?rev=689294&r1=689293&r2=689294&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
 Tue Aug 26 17:16:05 2008
@@ -27,83 +27,83 @@
 namespace Apache.NMS.ActiveMQ.Commands
 {
        public class ActiveMQMessage : Message, IMessage, MarshallAware
-    {
-        public const byte ID_ActiveMQMessage = 23;
-        
-        protected static MessagePropertyHelper propertyHelper = new 
MessagePropertyHelper();
-        
-        private PrimitiveMap properties;
-        
-        public event AcknowledgeHandler Acknowledger;
-
-        public static ActiveMQMessage Transform(IMessage message)
-        {
-            return (ActiveMQMessage) message;
-        }
-        
-        // TODO generate Equals method
-        // TODO generate GetHashCode method
-        
-        
-        public override byte GetDataStructureType()
-        {
-            return ID_ActiveMQMessage;
-        }
-        
-        public void Acknowledge()
-        {
-            if(null == Acknowledger)
+       {
+               public const byte ID_ActiveMQMessage = 23;
+
+               private MessagePropertyHelper propertyHelper;
+               private PrimitiveMap properties;
+
+               public event AcknowledgeHandler Acknowledger;
+
+               public static ActiveMQMessage Transform(IMessage message)
+               {
+                       return (ActiveMQMessage) message;
+               }
+
+               // TODO generate Equals method
+               // TODO generate GetHashCode method
+
+
+               public override byte GetDataStructureType()
+               {
+                       return ID_ActiveMQMessage;
+               }
+
+               public void Acknowledge()
+               {
+                       if(null == Acknowledger)
                        {
-                throw new NMSException("No Acknowledger has been associated 
with this message: " + this);
+                               throw new NMSException("No Acknowledger has 
been associated with this message: " + this);
                        }
-            else
+                       else
                        {
-                Acknowledger(this);
-            }
+                               Acknowledger(this);
+                       }
                }
 
                #region Properties
 
                public IPrimitiveMap Properties
-        {
-            get
+               {
+                       get
                        {
-                if(null == properties)
-                {
-                    properties = PrimitiveMap.Unmarshal(MarshalledProperties);
-                }
-
-                return properties;
-            }
-        }
-        
-        public IDestination FromDestination
-        {
-            get { return Destination; }
-            set { this.Destination = ActiveMQDestination.Transform(value); }
-        }
-                               
-        /// <summary>
-        /// The correlation ID used to correlate messages with conversations 
or long running business processes
-        /// </summary>
-        public string NMSCorrelationID
-        {
-            get { return CorrelationId; }
-            set { CorrelationId = value; }
-        }
-        
-        /// <summary>
-        /// The destination of the message
-        /// </summary>
-        public IDestination NMSDestination
-        {
-            get { return Destination; }
-        }
+                               if(null == properties)
+                               {
+                                       properties = 
PrimitiveMap.Unmarshal(MarshalledProperties);
+                                       propertyHelper = new 
MessagePropertyHelper(this, properties);
+                               }
+
+                               return propertyHelper;
+                       }
+               }
+
+               public IDestination FromDestination
+               {
+                       get { return Destination; }
+                       set { this.Destination = 
ActiveMQDestination.Transform(value); }
+               }
+
+               /// <summary>
+               /// The correlation ID used to correlate messages with 
conversations or long running business processes
+               /// </summary>
+               public string NMSCorrelationID
+               {
+                       get { return CorrelationId; }
+                       set { CorrelationId = value; }
+               }
+
+               /// <summary>
+               /// The destination of the message
+               /// </summary>
+               public IDestination NMSDestination
+               {
+                       get { return Destination; }
+               }
 
                private long expirationBaseTime = 0;
                /// <summary>
-        /// The time in milliseconds that this message should expire in
-        /// </summary>
+               /// The time in milliseconds that this message should expire in
+               /// </summary>
                public TimeSpan NMSTimeToLive
                {
                        get
@@ -127,64 +127,64 @@
                }
 
                /// <summary>
-        /// The message ID which is set by the provider
-        /// </summary>
-        public string NMSMessageId
-        {
-            get { return BaseDataStreamMarshaller.ToString(MessageId); }
-        }
-        
-        /// <summary>
-        /// Whether or not this message is persistent
-        /// </summary>
-        public bool NMSPersistent
-        {
-            get { return Persistent; }
-            set { Persistent = value; }
-        }
-        
-        /// <summary>
-        /// The Priority on this message
-        /// </summary>
-        public byte NMSPriority
-        {
-            get { return Priority; }
-            set { Priority = value; }
-        }
-        
-        /// <summary>
-        /// Returns true if this message has been redelivered to this or 
another consumer before being acknowledged successfully.
-        /// </summary>
-        public bool NMSRedelivered
-        {
-            get { return (RedeliveryCounter > 0); }
-        }
-        
-        /// <summary>
-        /// The destination that the consumer of this message should send 
replies to
-        /// </summary>
-        public IDestination NMSReplyTo
-        {
-            get { return ReplyTo; }
-            set { ReplyTo = ActiveMQDestination.Transform(value); }
-        }
-        
-        /// <summary>
-        /// The timestamp the broker added to the message
-        /// </summary>
-        public DateTime NMSTimestamp
-        {
-            get { return DateUtils.ToDateTime(Timestamp); }
-            set { Timestamp = DateUtils.ToJavaTimeUtc(value); }
-        }
-        
-        /// <summary>
-        /// The type name of this message
-        /// </summary>
-        public string NMSType
-        {
-            get { return Type; }
-            set { Type = value; }
+               /// The message ID which is set by the provider
+               /// </summary>
+               public string NMSMessageId
+               {
+                       get { return 
BaseDataStreamMarshaller.ToString(MessageId); }
+               }
+
+               /// <summary>
+               /// Whether or not this message is persistent
+               /// </summary>
+               public bool NMSPersistent
+               {
+                       get { return Persistent; }
+                       set { Persistent = value; }
+               }
+
+               /// <summary>
+               /// The Priority on this message
+               /// </summary>
+               public byte NMSPriority
+               {
+                       get { return Priority; }
+                       set { Priority = value; }
+               }
+
+               /// <summary>
+               /// Returns true if this message has been redelivered to this 
or another consumer before being acknowledged successfully.
+               /// </summary>
+               public bool NMSRedelivered
+               {
+                       get { return (RedeliveryCounter > 0); }
+               }
+
+               /// <summary>
+               /// The destination that the consumer of this message should 
send replies to
+               /// </summary>
+               public IDestination NMSReplyTo
+               {
+                       get { return ReplyTo; }
+                       set { ReplyTo = ActiveMQDestination.Transform(value); }
+               }
+
+               /// <summary>
+               /// The timestamp the broker added to the message
+               /// </summary>
+               public DateTime NMSTimestamp
+               {
+                       get { return DateUtils.ToDateTime(Timestamp); }
+                       set { Timestamp = DateUtils.ToJavaTimeUtc(value); }
+               }
+
+               /// <summary>
+               /// The type name of this message
+               /// </summary>
+               public string NMSType
+               {
+                       get { return Type; }
+                       set { Type = value; }
                }
 
                #endregion
@@ -192,78 +192,78 @@
                #region NMS Extension headers
 
                /// <summary>
-        /// Returns the number of times this message has been redelivered to 
other consumers without being acknowledged successfully.
-        /// </summary>
-        public int NMSXDeliveryCount
-        {
-            get { return RedeliveryCounter + 1; }
-        }
-        
-        /// <summary>
-        /// The Message Group ID used to group messages together to the same 
consumer for the same group ID value
-        /// </summary>
-        public string NMSXGroupID
-        {
-            get { return GroupID; }
-            set { GroupID = value; }
-        }
-        /// <summary>
-        /// The Message Group Sequence counter to indicate the position in a 
group
-        /// </summary>
-        public int NMSXGroupSeq
-        {
-            get { return GroupSequence; }
-            set { GroupSequence = value; }
-        }
-        
-        /// <summary>
-        /// Returns the ID of the producers transaction
-        /// </summary>
-        public string NMSXProducerTXID
-        {
-            get
-                       {
-                TransactionId txnId = OriginalTransactionId;
-                if(null == txnId)
-                {
-                    txnId = TransactionId;
-                }
-
-                if(null != txnId)
-                {
-                    return BaseDataStreamMarshaller.ToString(txnId);
-                }
+               /// Returns the number of times this message has been 
redelivered to other consumers without being acknowledged successfully.
+               /// </summary>
+               public int NMSXDeliveryCount
+               {
+                       get { return RedeliveryCounter + 1; }
+               }
+
+               /// <summary>
+               /// The Message Group ID used to group messages together to the 
same consumer for the same group ID value
+               /// </summary>
+               public string NMSXGroupID
+               {
+                       get { return GroupID; }
+                       set { GroupID = value; }
+               }
+               /// <summary>
+               /// The Message Group Sequence counter to indicate the position 
in a group
+               /// </summary>
+               public int NMSXGroupSeq
+               {
+                       get { return GroupSequence; }
+                       set { GroupSequence = value; }
+               }
+
+               /// <summary>
+               /// Returns the ID of the producers transaction
+               /// </summary>
+               public string NMSXProducerTXID
+               {
+                       get
+                       {
+                               TransactionId txnId = OriginalTransactionId;
+                               if(null == txnId)
+                               {
+                                       txnId = TransactionId;
+                               }
 
-                return null;
-            }
+                               if(null != txnId)
+                               {
+                                       return 
BaseDataStreamMarshaller.ToString(txnId);
+                               }
+
+                               return null;
+                       }
                }
 
                #endregion
 
                public object GetObjectProperty(string name)
-        {
-            return propertyHelper.GetObjectProperty(this, name);
-        }
-        
-        public void SetObjectProperty(string name, object value)
-        {
-            propertyHelper.SetObjectProperty(this, name, value);
-        }
-        
-        // MarshallAware interface
-        public override bool IsMarshallAware()
-        {
-            return true;
-        }
-        
-        public override void BeforeMarshall(OpenWireFormat wireFormat)
-        {
-            MarshalledProperties = null;
-            if (properties != null)
-            {
-                MarshalledProperties = properties.Marshal();
-            }
-        }
-    }
+               {
+                       return Properties[name];
+               }
+
+               public void SetObjectProperty(string name, object value)
+               {
+                       Properties[name] = value;
+               }
+
+               // MarshallAware interface
+               public override bool IsMarshallAware()
+               {
+                       return true;
+               }
+
+               public override void BeforeMarshall(OpenWireFormat wireFormat)
+               {
+                       MarshalledProperties = null;
+                       if (properties != null)
+                       {
+                               MarshalledProperties = properties.Marshal();
+                       }
+               }
+       }
 }
 

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/WireFormatInfo.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/WireFormatInfo.cs?rev=689294&r1=689293&r2=689294&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/WireFormatInfo.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/WireFormatInfo.cs
 Tue Aug 26 17:16:05 2008
@@ -42,7 +42,6 @@
         int version;
         byte[] marshalledProperties;
         
-        protected static MessagePropertyHelper propertyHelper = new 
MessagePropertyHelper();
         private PrimitiveMap properties;
         
         public override string ToString() {

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/MessagePropertyHelper.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/MessagePropertyHelper.cs?rev=689294&r1=689293&r2=689294&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/MessagePropertyHelper.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/MessagePropertyHelper.cs
 Tue Aug 26 17:16:05 2008
@@ -1,3 +1,5 @@
+using System;
+using System.Reflection;
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -15,39 +17,216 @@
  * limitations under the License.
 */
 using Apache.NMS.ActiveMQ.Commands;
-using System.Collections;
 
 namespace Apache.NMS.ActiveMQ.OpenWire
 {
-    public delegate object PropertyGetter(ActiveMQMessage message);
-    public delegate void PropertySetter(ActiveMQMessage message, object value);
-    
-    public class MessagePropertyHelper
-    {
-        private IDictionary setters = new Hashtable();
-        private IDictionary getters = new Hashtable();
-        
-        public MessagePropertyHelper()
-        {
-            // TODO find all of the NMS properties via introspection
-        }
-        
-        
-        public object GetObjectProperty(ActiveMQMessage message, string name) {
-            object getter = getters[name];
-            if (getter != null) {
-            }
-            return message.Properties[name];
-        }
-        
-        public void SetObjectProperty(ActiveMQMessage message, string name, 
object value) {
-            PropertySetter setter = (PropertySetter) setters[name];
-            if (setter != null) {
-                setter(message, value);
-            }
-            else {
-                message.Properties[name] = value;
-            }
-        }
-    }
+       // Set NMS properties via introspection
+       public class MessagePropertyHelper : IPrimitiveMap
+       {
+               private static BindingFlags publicBinding = BindingFlags.Public 
| BindingFlags.Instance;
+               private ActiveMQMessage message;
+               private IPrimitiveMap properties;
+               private Type messageType;
+
+               public MessagePropertyHelper(ActiveMQMessage _message, 
IPrimitiveMap _properties)
+               {
+                       this.message = _message;
+                       this.properties = _properties;
+                       this.messageType = _message.GetType();
+               }
+
+               protected object GetObjectProperty(string name)
+               {
+                       PropertyInfo propertyInfo = 
this.messageType.GetProperty(name, publicBinding);
+
+                       if(null != propertyInfo && propertyInfo.CanRead)
+                       {
+                               return propertyInfo.GetValue(this.message, 
null);
+                       }
+                       else
+                       {
+                               FieldInfo fieldInfo = 
this.messageType.GetField(name, publicBinding);
+
+                               if(null != fieldInfo)
+                               {
+                                       return fieldInfo.GetValue(this.message);
+                               }
+                       }
+
+                       return this.properties[name];
+               }
+
+               protected void SetObjectProperty(string name, object value)
+               {
+                       PropertyInfo propertyInfo = 
this.messageType.GetProperty(name, publicBinding);
+
+                       if(null != propertyInfo && propertyInfo.CanWrite)
+                       {
+                               propertyInfo.SetValue(this.message, value, 
null);
+                       }
+                       else
+                       {
+                               FieldInfo fieldInfo = 
this.messageType.GetField(name, publicBinding);
+
+                               if(null != fieldInfo && !fieldInfo.IsLiteral && 
!fieldInfo.IsInitOnly)
+                               {
+                                       fieldInfo.SetValue(this.message, value);
+                               }
+                               else
+                               {
+                                       this.properties[name] = value;
+                               }
+                       }
+               }
+
+               #region IPrimitiveMap Members
+
+               public void Clear()
+               {
+                       this.properties.Clear();
+               }
+
+               public bool Contains(object key)
+               {
+                       return this.properties.Contains(key);
+               }
+
+               public void Remove(object key)
+               {
+                       this.properties.Remove(key);
+               }
+
+               public int Count
+               {
+                       get { return this.properties.Count; }
+               }
+
+               public System.Collections.ICollection Keys
+               {
+                       get { return this.properties.Keys; }
+               }
+
+               public System.Collections.ICollection Values
+               {
+                       get { return this.properties.Values; }
+               }
+
+               public object this[string key]
+               {
+                       get { return GetObjectProperty(key); }
+                       set { SetObjectProperty(key, value); }
+               }
+
+               public string GetString(string key)
+               {
+                       return (string) GetObjectProperty(key);
+               }
+
+               public void SetString(string key, string value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public bool GetBool(string key)
+               {
+                       return (bool) GetObjectProperty(key);
+               }
+
+               public void SetBool(string key, bool value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public byte GetByte(string key)
+               {
+                       return (byte) GetObjectProperty(key);
+               }
+
+               public void SetByte(string key, byte value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public char GetChar(string key)
+               {
+                       return (char) GetObjectProperty(key);
+               }
+
+               public void SetChar(string key, char value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public short GetShort(string key)
+               {
+                       return (short) GetObjectProperty(key);
+               }
+
+               public void SetShort(string key, short value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public int GetInt(string key)
+               {
+                       return (int) GetObjectProperty(key);
+               }
+
+               public void SetInt(string key, int value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public long GetLong(string key)
+               {
+                       return (long) GetObjectProperty(key);
+               }
+
+               public void SetLong(string key, long value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public float GetFloat(string key)
+               {
+                       return (float) GetObjectProperty(key);
+               }
+
+               public void SetFloat(string key, float value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public double GetDouble(string key)
+               {
+                       return (double) GetObjectProperty(key);
+               }
+
+               public void SetDouble(string key, double value)
+               {
+                       SetObjectProperty(key, value);
+               }
+
+               public System.Collections.IList GetList(string key)
+               {
+                       return (System.Collections.IList) 
GetObjectProperty(key);
+               }
+
+               public void SetList(string key, System.Collections.IList list)
+               {
+                       SetObjectProperty(key, list);
+               }
+
+               public System.Collections.IDictionary GetDictionary(string key)
+               {
+                       return (System.Collections.IDictionary) 
GetObjectProperty(key);
+               }
+
+               public void SetDictionary(string key, 
System.Collections.IDictionary dictionary)
+               {
+                       SetObjectProperty(key, dictionary);
+               }
+
+               #endregion
+       }
 }


Reply via email to