activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r898879 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk: ./ src/main/csharp/ src/main/csharp/Commands/ src/main/csharp/Protocol/
Date Wed, 13 Jan 2010 18:54:02 GMT
Author: tabish
Date: Wed Jan 13 18:54:01 2010
New Revision: 898879

URL: http://svn.apache.org/viewvc?rev=898879&view=rev
Log:
Adds the ability to create and send a MapMessage over stomp using the ActiveMQ jms-map-xml
format.  Support for receive is not yet implemented.

Added:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/IPrimitiveMapMarshaler.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
  (with props)
Modified:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs?rev=898879&r1=898878&r2=898879&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs
Wed Jan 13 18:54:01 2010
@@ -17,6 +17,7 @@
 
 using System;
 using System.IO;
+using Apache.NMS;
 using Apache.NMS.Util;
 using Apache.NMS.Stomp.Protocol;
 
@@ -84,22 +85,16 @@
 
         public override void BeforeMarshall(StompWireFormat wireFormat)
         {
+            base.BeforeMarshall(wireFormat);
+
             if(body == null)
             {
-                Content = null;
+                this.Content = null;
             }
             else
             {
-                MemoryStream buffer = new MemoryStream();
-                this.body.Marshal(buffer);
-                buffer.Close();
-
-                this.Content = buffer.ToArray();
+                this.Content = wireFormat.MapMarshaler.Marshal(body);
             }
-
-            Tracer.Debug("BeforeMarshalling, content is: " + Content);
-
-            base.BeforeMarshall(wireFormat);
         }
     }
 }

Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/IPrimitiveMapMarshaler.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/IPrimitiveMapMarshaler.cs?rev=898879&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/IPrimitiveMapMarshaler.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/IPrimitiveMapMarshaler.cs
Wed Jan 13 18:54:01 2010
@@ -0,0 +1,58 @@
+// /*
+//  * 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.Stomp.Protocol
+{
+    /// <summary>
+    /// Interface for a utility class used to marshal an IPrimitiveMap instance
+    /// to/from an String.
+    /// </summary>
+    public interface IPrimitiveMapMarshaler
+    {
+        /// <summary>
+        /// Marshals an instance of an IPrimitiveMap to an String object.
+        /// </summary>
+        /// <param name="map">
+        /// A <see cref="IPrimitiveMap"/>
+        /// </param>
+        /// <returns>
+        /// A <see cref="System.Byte[]"/>
+        /// </returns>
+        byte[] Marshal(IPrimitiveMap map);
+
+        /// <summary>
+        /// Un-marshals an IPrimitiveMap instance from a String object.
+        /// </summary>
+        /// <param name="mapContent">
+        /// A <see cref="System.Byte[]"/>
+        /// </param>
+        /// <returns>
+        /// A <see cref="IPrimitiveMap"/>
+        /// </returns>
+        IPrimitiveMap Unmarshal(byte[] mapContent);
+
+        /// <summary>
+        /// Retreives the Name of this Marshaler.
+        /// </summary>
+        string Name { get; }
+
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/IPrimitiveMapMarshaler.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs?rev=898879&r1=898878&r2=898879&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
Wed Jan 13 18:54:01 2010
@@ -30,19 +30,20 @@
     public class StompWireFormat : IWireFormat
     {
         private Encoding encoder = new UTF8Encoding();
+        private IPrimitiveMapMarshaler mapMarshaler = new XmlPrimitiveMapMarshaler();
         private ITransport transport;
 
         public StompWireFormat()
         {
         }
 
-        public ITransport Transport 
+        public ITransport Transport
         {
             get { return transport; }
             set { transport = value; }
         }
 
-        public int Version 
+        public int Version
         {
             get { return 1; }
         }
@@ -53,6 +54,12 @@
             set { this.encoder = value; }
         }
 
+        public IPrimitiveMapMarshaler MapMarshaler
+        {
+            get { return this.mapMarshaler; }
+            set { this.mapMarshaler = value; }
+        }
+
         public void Marshal(Object o, BinaryWriter dataOut)
         {
             Tracer.Debug("StompWireFormat - Marshaling: " + o);
@@ -331,6 +338,10 @@
 
                 frame.SetProperty("transformation", "jms-byte");
             }
+            else if(command is MapMessage)
+            {
+                frame.SetProperty("transformation", this.mapMarshaler.Name);
+            }
 			
             // Marshal all properties to the Frame.
             IPrimitiveMap map = command.Properties;

Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs?rev=898879&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
Wed Jan 13 18:54:01 2010
@@ -0,0 +1,162 @@
+// /*
+//  * 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 System.Xml;
+using System.Collections;
+using Apache.NMS.Util;
+
+namespace Apache.NMS.Stomp.Protocol
+{
+    /// <summary>
+    /// Reads / Writes an IPrimitveMap as XML.
+    /// </summary>
+    public class XmlPrimitiveMapMarshaler : IPrimitiveMapMarshaler
+    {
+        private Encoding encoder = new UTF8Encoding();
+
+        public XmlPrimitiveMapMarshaler() : base()
+        {
+        }
+
+        public XmlPrimitiveMapMarshaler(Encoding encoder) : base()
+        {
+            this.encoder = encoder;
+        }
+
+        public string Name
+        {
+            get{ return "jms-map-xml"; }
+        }
+
+        public byte[] Marshal(IPrimitiveMap map)
+        {
+            StringBuilder builder = new StringBuilder();
+
+            XmlWriterSettings settings = new XmlWriterSettings();
+
+            settings.OmitXmlDeclaration = true;
+            settings.Encoding = this.encoder;
+            settings.NewLineHandling = NewLineHandling.None;
+
+            XmlWriter writer = XmlWriter.Create(builder, settings);
+
+            writer.WriteStartElement("map");
+
+            foreach(String entry in map.Keys)
+            {
+                writer.WriteStartElement("entry");
+
+                // Encode the Key <string>key</string>
+                writer.WriteElementString("string", entry);
+
+                Object value = map[entry];
+
+                // Encode the Value <${type}>value</${type}>
+                MarshalPrimitive(writer, value);
+
+                writer.WriteEndElement();
+            }
+
+            writer.WriteEndElement();
+            writer.Close();
+
+            Console.WriteLine("XML Map = " + builder.ToString());
+
+            return this.encoder.GetBytes(builder.ToString());
+        }
+
+        public IPrimitiveMap Unmarshal(byte[] mapContent)
+        {
+            string content = this.encoder.GetString(mapContent);
+
+            PrimitiveMap result = new PrimitiveMap();
+
+            if(content == null || content == "")
+            {
+                return result;
+            }
+
+            return result;
+        }
+
+        private void MarshalPrimitive(XmlWriter writer, Object value)
+        {
+            if(value == null)
+            {
+                Console.WriteLine("Null Map Value");
+                throw new NullReferenceException("PrimitiveMap values should not be Null");
+            }
+            else if(value is bool)
+            {
+                writer.WriteElementString("boolean", value.ToString().ToLower());
+            }
+            else if(value is byte)
+            {
+                writer.WriteElementString("byte", value.ToString());
+            }
+            else if(value is short)
+            {
+                writer.WriteElementString("short", value.ToString());
+            }
+            else if(value is int)
+            {
+                writer.WriteElementString("int", value.ToString());
+            }
+            else if(value is long)
+            {
+                writer.WriteElementString("long", value.ToString());
+            }
+            else if(value is float)
+            {
+                writer.WriteElementString("float", value.ToString());
+            }
+            else if(value is double)
+            {
+                writer.WriteElementString("double", value.ToString());
+            }
+            else if(value is byte[])
+            {
+                writer.WriteElementString("byte-array", Convert.ToBase64String((byte[]) value));
+            }
+            else if(value is string)
+            {
+                writer.WriteElementString("string", (string) value);
+            }
+            else if(value is IDictionary)
+            {
+                Console.WriteLine("Can't Marshal a Dictionary");
+
+                throw new NotSupportedException("Can't marshal nested Maps in Stomp");
+            }
+            else if(value is IList)
+            {
+                Console.WriteLine("Can't Marshal a List");
+
+                throw new NotSupportedException("Can't marshal nested Maps in Stomp");
+            }
+            else
+            {
+                Console.WriteLine("Can't Marshal a something other than a Primitive Value.");
+
+                throw new Exception("Object is not a primitive: " + value);
+            }
+        }
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs?rev=898879&r1=898878&r2=898879&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs Wed Jan 13
18:54:01 2010
@@ -519,7 +519,8 @@
 
         public IMapMessage CreateMapMessage()
         {
-            throw new NotSupportedException("No Object Message in Stomp");
+            MapMessage answer = new MapMessage();
+            return ConfigureMessage(answer) as IMapMessage;
         }
 
         public IBytesMessage CreateBytesMessage()

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj?rev=898879&r1=898878&r2=898879&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj Wed Jan 13 18:54:01
2010
@@ -111,6 +111,8 @@
     <Compile Include="src\main\csharp\Commands\ConnectionError.cs" />
     <Compile Include="src\main\csharp\Commands\RemoveSubscriptionInfo.cs" />
     <Compile Include="src\main\csharp\Protocol\StompFrame.cs" />
+    <Compile Include="src\main\csharp\Protocol\IPrimitiveMapMarshaler.cs" />
+    <Compile Include="src\main\csharp\Protocol\XmlPrimitiveMapMarshaler.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="keyfile\NMSKey.snk" />



Mime
View raw message