You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/09/26 18:04:40 UTC
svn commit: r450099 - in /incubator/activemq/activemq-dotnet/trunk/src:
main/csharp/ main/csharp/ActiveMQ/OpenWire/ main/csharp/NMS/ test/csharp/
test/csharp/ActiveMQ/OpenWire/
Author: jstrachan
Date: Tue Sep 26 09:04:39 2006
New Revision: 450099
URL: http://svn.apache.org/viewvc?view=rev&rev=450099
Log:
added support for nested map and list structures (IList and IDictionary) for AMQ-864
Modified:
incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/OpenWire/PrimitiveMap.cs
incubator/activemq/activemq-dotnet/trunk/src/main/csharp/CommonAssemblyInfo.cs
incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IMessage.cs
incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IPrimitiveMap.cs
incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/OpenWire/PrimitiveMapTest.cs
incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs
Modified: incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/OpenWire/PrimitiveMap.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/OpenWire/PrimitiveMap.cs?view=diff&rev=450099&r1=450098&r2=450099
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/OpenWire/PrimitiveMap.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/OpenWire/PrimitiveMap.cs Tue Sep 26 09:04:39 2006
@@ -26,7 +26,7 @@
/// </summary>
public class PrimitiveMap : IPrimitiveMap
{
- public const byte NULL = 0;
+ public const byte NULL = 0;
public const byte BOOLEAN_TYPE = 1;
public const byte BYTE_TYPE = 2;
public const byte CHAR_TYPE = 3;
@@ -37,7 +37,10 @@
public const byte FLOAT_TYPE = 8;
public const byte STRING_TYPE = 9;
public const byte BYTE_ARRAY_TYPE = 10;
-
+ public const byte MAP_TYPE = 11;
+ public const byte LIST_TYPE = 12;
+ public const byte BIG_STRING_TYPE = 13;
+
private IDictionary dictionary = new Hashtable();
public void Clear()
@@ -195,9 +198,37 @@
{
SetValue(key, value);
}
-
-
-
+
+ public IList GetList(String key)
+ {
+ Object value = GetValue(key);
+ if (value != null && !(value is IList))
+ {
+ throw new NMSException("Property: " + key + " is not an IList but is: " + value);
+ }
+ return (IList) value;
+ }
+
+ public void SetList(String key, IList value)
+ {
+ SetValue(key, value);
+ }
+
+ public IDictionary GetDictionary(String key)
+ {
+ Object value = GetValue(key);
+ if (value != null && !(value is IDictionary))
+ {
+ throw new NMSException("Property: " + key + " is not an IDictionary but is: " + value);
+ }
+ return (IDictionary) value;
+ }
+
+ public void SetDictionary(String key, IDictionary value)
+ {
+ SetValue(key, value);
+ }
+
protected virtual void SetValue(String key, Object value)
{
@@ -220,7 +251,7 @@
protected virtual void CheckValidType(Object value)
{
- if (value != null)
+ if (value != null && !(value is IList) && !(value is IDictionary))
{
Type type = value.GetType();
if (! type.IsPrimitive && !type.IsValueType && !type.IsAssignableFrom(typeof(string)))
@@ -229,33 +260,33 @@
}
}
}
-
- /// <summary>
- /// Method ToString
- /// </summary>
- /// <returns>A string</returns>
- public override String ToString()
- {
- String s="{";
- bool first=true;
- foreach (DictionaryEntry entry in dictionary)
- {
- if( !first ) {
- s+=", ";
- }
- first=false;
- String name = (String) entry.Key;
- Object value = entry.Value;
- s+=name+"="+value;
- }
- s += "}";
- return s;
- }
-
-
-
-
- /// <summary>
+
+ /// <summary>
+ /// Method ToString
+ /// </summary>
+ /// <returns>A string</returns>
+ public override String ToString()
+ {
+ String s="{";
+ bool first=true;
+ foreach (DictionaryEntry entry in dictionary)
+ {
+ if( !first ) {
+ s+=", ";
+ }
+ first=false;
+ String name = (String) entry.Key;
+ Object value = entry.Value;
+ s+=name+"="+value;
+ }
+ s += "}";
+ return s;
+ }
+
+
+
+
+ /// <summary>
/// Unmarshalls the map from the given data or if the data is null just
/// return an empty map
/// </summary>
@@ -270,8 +301,8 @@
{
return MarshalPrimitiveMap(dictionary);
}
-
-
+
+
/// <summary>
/// Marshals the primitive type map to a byte array
/// </summary>
@@ -343,7 +374,27 @@
}
}
-
+
+ public static void MarshalPrimitiveList(IList list, BinaryWriter dataOut)
+ {
+ dataOut.Write((int) list.Count);
+ foreach (Object element in list)
+ {
+ MarshalPrimitive(dataOut, element);
+ }
+ }
+
+ public static IList UnmarshalPrimitiveList(BinaryReader dataIn)
+ {
+ int size = dataIn.ReadInt32();
+ IList answer = new ArrayList(size);
+ while (size-- > 0) {
+ answer.Add(UnmarshalPrimitive(dataIn));
+ }
+ return answer;
+ }
+
+
public static void MarshalPrimitive(BinaryWriter dataOut, Object value)
{
if (value == null)
@@ -399,8 +450,28 @@
}
else if (value is string)
{
- dataOut.Write(STRING_TYPE);
- dataOut.Write((string) value);
+ string s = (string) value;
+ // is the string big??
+ if (s.Length > 8191)
+ {
+ dataOut.Write(BIG_STRING_TYPE);
+ dataOut.Write(s);
+ }
+ else
+ {
+ dataOut.Write(STRING_TYPE);
+ dataOut.Write(s);
+ }
+ }
+ else if (value is IDictionary)
+ {
+ dataOut.Write(MAP_TYPE);
+ MarshalPrimitiveMap((IDictionary) value, dataOut);
+ }
+ else if (value is IList)
+ {
+ dataOut.Write(LIST_TYPE);
+ MarshalPrimitiveList((IList) value, dataOut);
}
else
{
@@ -411,7 +482,8 @@
public static Object UnmarshalPrimitive(BinaryReader dataIn)
{
Object value=null;
- switch (dataIn.ReadByte())
+ byte type = dataIn.ReadByte();
+ switch (type)
{
case BYTE_TYPE:
value = dataIn.ReadByte();
@@ -446,10 +518,23 @@
case STRING_TYPE:
value = dataIn.ReadString();
break;
+ case BIG_STRING_TYPE:
+ value = dataIn.ReadString();
+ break;
+ case MAP_TYPE:
+ value = UnmarshalPrimitiveMap(dataIn);
+ break;
+
+ case LIST_TYPE:
+ value = UnmarshalPrimitiveList(dataIn);
+ break;
+
+ default:
+ throw new Exception("Unsupported data type: " + type);
}
return value;
}
-
+
}
}
Modified: incubator/activemq/activemq-dotnet/trunk/src/main/csharp/CommonAssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/main/csharp/CommonAssemblyInfo.cs?view=diff&rev=450099&r1=450098&r2=450099
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/main/csharp/CommonAssemblyInfo.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/main/csharp/CommonAssemblyInfo.cs Tue Sep 26 09:04:39 2006
@@ -22,6 +22,6 @@
[assembly: AssemblyCopyrightAttribute("Copyright (C) 2005-2006 Apache Software Foundation")]
[assembly: AssemblyTrademarkAttribute("")]
[assembly: AssemblyCultureAttribute("")]
-[assembly: AssemblyVersionAttribute("4.0.2456.0")]
+[assembly: AssemblyVersionAttribute("4.0.2460.0")]
[assembly: AssemblyInformationalVersionAttribute("4.0")]
Modified: incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IMessage.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IMessage.cs?view=diff&rev=450099&r1=450098&r2=450099
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IMessage.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IMessage.cs Tue Sep 26 09:04:39 2006
@@ -16,10 +16,10 @@
*/
namespace NMS
{
- /// <summary>
- /// Represents a message either to be sent to a message broker or received from a message broker
- /// </summary>
- public interface IMessage
+ /// <summary>
+ /// Represents a message either to be sent to a message broker or received from a message broker
+ /// </summary>
+ public interface IMessage
{
/// <summary>
@@ -32,7 +32,7 @@
/// Provides access to the message properties (headers)
/// </summary>
IPrimitiveMap Properties
- {
+ {
get;
}
Modified: incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IPrimitiveMap.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IPrimitiveMap.cs?view=diff&rev=450099&r1=450098&r2=450099
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IPrimitiveMap.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/main/csharp/NMS/IPrimitiveMap.cs Tue Sep 26 09:04:39 2006
@@ -14,14 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+using System.Collections;
+
namespace NMS
{
- /// <summary>
- /// Represents a Map of primitive types where the keys are all string instances
- /// and the values are strings or numbers.
- /// </summary>
- public interface IPrimitiveMap
+ /// <summary>
+ /// Represents a Map of primitive types where the keys are all string instances
+ /// and the values are strings or numbers.
+ /// </summary>
+ public interface IPrimitiveMap
{
void Clear();
@@ -35,12 +37,12 @@
get;
}
- System.Collections.ICollection Keys
+ ICollection Keys
{
get;
}
- System.Collections.ICollection Values
+ ICollection Values
{
get;
}
@@ -77,6 +79,12 @@
double GetDouble(string key);
void SetDouble(string key, double value);
+
+ IList GetList(string key);
+ void SetList(string key, IList list);
+
+ IDictionary GetDictionary(string key);
+ void SetDictionary(string key, IDictionary dictionary);
}
}
Modified: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/OpenWire/PrimitiveMapTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/OpenWire/PrimitiveMapTest.cs?view=diff&rev=450099&r1=450098&r2=450099
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/OpenWire/PrimitiveMapTest.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/OpenWire/PrimitiveMapTest.cs Tue Sep 26 09:04:39 2006
@@ -16,6 +16,7 @@
*/
using NUnit.Framework;
using System;
+using System.Collections;
using System.IO;
using ActiveMQ.OpenWire;
@@ -25,38 +26,40 @@
public class PrimitiveMapTest
{
- bool a = true;
+ bool a = true;
byte b = 123;
char c = 'c';
short d = 0x1234;
int e = 0x12345678;
long f = 0x1234567812345678;
string g = "Hello World!";
- bool h = false;
+ bool h = false;
byte i = 0xFF;
short j = -0x1234;
int k = -0x12345678;
long l = -0x1234567812345678;
-
+ IList m = CreateList();
+ IDictionary n = CreateDictionary();
+
[Test]
public void TestNotMarshalled()
{
- PrimitiveMap map = CreatePrimitiveMap();
- AssertPrimitiveMap(map);
+ PrimitiveMap map = CreatePrimitiveMap();
+ AssertPrimitiveMap(map);
}
-
+
[Test]
public void TestMarshalled()
{
- PrimitiveMap map = CreatePrimitiveMap();
- Console.WriteLine("data: "+map);
- byte[] data = map.Marshal();
- map = PrimitiveMap.Unmarshal(data);
- Console.WriteLine("data: "+map);
- AssertPrimitiveMap(map);
+ PrimitiveMap map = CreatePrimitiveMap();
+ Console.WriteLine("data: "+map);
+ byte[] data = map.Marshal();
+ map = PrimitiveMap.Unmarshal(data);
+ Console.WriteLine("data: "+map);
+ AssertPrimitiveMap(map);
}
-
- protected PrimitiveMap CreatePrimitiveMap()
+
+ protected PrimitiveMap CreatePrimitiveMap()
{
PrimitiveMap map = new PrimitiveMap();
@@ -72,41 +75,70 @@
map["j"] = j;
map["k"] = k;
map["l"] = l;
-
+ map["m"] = m;
+ map["n"] = n;
+
return map;
}
-
- protected void AssertPrimitiveMap(PrimitiveMap map) {
- // use generic API to access entries
- Assert.AreEqual(a, map["a"], "generic map entry: a");
- Assert.AreEqual(b, map["b"], "generic map entry: b");
- Assert.AreEqual(c, map["c"], "generic map entry: c");
- Assert.AreEqual(d, map["d"], "generic map entry: d");
- Assert.AreEqual(e, map["e"], "generic map entry: e");
- Assert.AreEqual(f, map["f"], "generic map entry: f");
- Assert.AreEqual(g, map["g"], "generic map entry: g");
- Assert.AreEqual(h, map["h"], "generic map entry: h");
- Assert.AreEqual(i, map["i"], "generic map entry: i");
- Assert.AreEqual(j, map["j"], "generic map entry: j");
- Assert.AreEqual(k, map["k"], "generic map entry: k");
- Assert.AreEqual(l, map["l"], "generic map entry: l");
-
- // use type safe APIs
- Assert.AreEqual(a, map.GetBool("a"), "map entry: a");
- Assert.AreEqual(b, map.GetByte("b"), "map entry: b");
- Assert.AreEqual(c, map.GetChar("c"), "map entry: c");
- Assert.AreEqual(d, map.GetShort("d"), "map entry: d");
- Assert.AreEqual(e, map.GetInt("e"), "map entry: e");
- Assert.AreEqual(f, map.GetLong("f"), "map entry: f");
- Assert.AreEqual(g, map.GetString("g"), "map entry: g");
- Assert.AreEqual(h, map.GetBool("h"), "map entry: h");
- Assert.AreEqual(i, map.GetByte("i"), "map entry: i");
- Assert.AreEqual(j, map.GetShort("j"), "map entry: j");
- Assert.AreEqual(k, map.GetInt("k"), "map entry: k");
- Assert.AreEqual(l, map.GetLong("l"), "map entry: l");
- }
-
-
- }
+
+ protected void AssertPrimitiveMap(PrimitiveMap map) {
+ // use generic API to access entries
+ Assert.AreEqual(a, map["a"], "generic map entry: a");
+ Assert.AreEqual(b, map["b"], "generic map entry: b");
+ Assert.AreEqual(c, map["c"], "generic map entry: c");
+ Assert.AreEqual(d, map["d"], "generic map entry: d");
+ Assert.AreEqual(e, map["e"], "generic map entry: e");
+ Assert.AreEqual(f, map["f"], "generic map entry: f");
+ Assert.AreEqual(g, map["g"], "generic map entry: g");
+ Assert.AreEqual(h, map["h"], "generic map entry: h");
+ Assert.AreEqual(i, map["i"], "generic map entry: i");
+ Assert.AreEqual(j, map["j"], "generic map entry: j");
+ Assert.AreEqual(k, map["k"], "generic map entry: k");
+ Assert.AreEqual(l, map["l"], "generic map entry: l");
+ //Assert.AreEqual(m, map["m"], "generic map entry: m");
+ //Assert.AreEqual(n, map["n"], "generic map entry: n");
+
+ // use type safe APIs
+ Assert.AreEqual(a, map.GetBool("a"), "map entry: a");
+ Assert.AreEqual(b, map.GetByte("b"), "map entry: b");
+ Assert.AreEqual(c, map.GetChar("c"), "map entry: c");
+ Assert.AreEqual(d, map.GetShort("d"), "map entry: d");
+ Assert.AreEqual(e, map.GetInt("e"), "map entry: e");
+ Assert.AreEqual(f, map.GetLong("f"), "map entry: f");
+ Assert.AreEqual(g, map.GetString("g"), "map entry: g");
+ Assert.AreEqual(h, map.GetBool("h"), "map entry: h");
+ Assert.AreEqual(i, map.GetByte("i"), "map entry: i");
+ Assert.AreEqual(j, map.GetShort("j"), "map entry: j");
+ Assert.AreEqual(k, map.GetInt("k"), "map entry: k");
+ Assert.AreEqual(l, map.GetLong("l"), "map entry: l");
+ //Assert.AreEqual(m, map.GetList("m"), "map entry: m");
+ //Assert.AreEqual(n, map.GetDictionary("n"), "map entry: n");
+
+ IList list = map.GetList("m");
+ Assert.AreEqual(2, list.Count, "list size");
+
+ IDictionary dictionary = map.GetDictionary("n");
+ Assert.AreEqual(3, dictionary.Count, "dictionary size");
+ }
+
+
+ protected static IList CreateList()
+ {
+ ArrayList answer = new ArrayList();
+ answer.Add("Item1");
+ answer.Add("Item2");
+ return answer;
+ }
+
+ protected static IDictionary CreateDictionary()
+ {
+ Hashtable answer = new Hashtable();
+ answer.Add("Name", "James");
+ answer.Add("Location", "London");
+ answer.Add("Company", "LogicBlaze");
+ return answer;
+ }
+
+ }
}
Modified: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs?view=diff&rev=450099&r1=450098&r2=450099
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs Tue Sep 26 09:04:39 2006
@@ -22,6 +22,6 @@
[assembly: AssemblyCopyrightAttribute("Copyright (C) 2005-2006 Apache Software Foundation")]
[assembly: AssemblyTrademarkAttribute("")]
[assembly: AssemblyCultureAttribute("")]
-[assembly: AssemblyVersionAttribute("4.0.2456.0")]
+[assembly: AssemblyVersionAttribute("4.0.2460.0")]
[assembly: AssemblyInformationalVersionAttribute("4.0")]