Author: chug
Date: Wed Jan 15 23:58:54 2014
New Revision: 1558619

URL: http://svn.apache.org/r1558619
Log:
QPID-5481: Messaging API Update - 1513536 Message constructor and content 
getters added

The .NET Binding already had the bytes constructor and the getContentBytes 
methods.
This patch adds getContentObject/setContentObject interfaces.

Modified:
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp?rev=1558619&r1=1558618&r2=1558619&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp Wed Jan 15 
23:58:54 2014
@@ -404,6 +404,32 @@ namespace Messaging {
         }
     }
 
+    
+    void Message::SetContentObject(System::Object ^ managedObject)
+    {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
+        System::Exception ^ newException = nullptr;
+
+        try
+        {
+            ::qpid::types::Variant nativeObjValue;
+            TypeTranslator::ManagedToNativeObject(managedObject, 
nativeObjValue);
+            nativeObjPtr->setContentObject(nativeObjValue);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
+            String ^ errmsg = gcnew String(error.what());
+            newException    = gcnew QpidException(errmsg);
+        }
+
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
+    }
+
 
     System::String ^ Message::GetContent()
     {
@@ -539,6 +565,31 @@ namespace Messaging {
     }
 
 
+    void Message::GetContentObject(System::Object ^ managedObject)
+    {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
+        System::Exception ^ newException = nullptr;
+
+        try
+        {
+            ::qpid::types::Variant nativeObject = 
nativeObjPtr->getContentObject();
+
+            managedObject = 
TypeTranslator::NativeToManagedObject(nativeObject);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
+            String ^ errmsg = gcnew String(error.what());
+            newException    = gcnew QpidException(errmsg);
+        }
+
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
+    }
+    
     System::String ^ 
Message::MapAsString(System::Collections::Generic::Dictionary<
         System::String^, System::Object^> ^ dict)
     {

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h?rev=1558619&r1=1558618&r2=1558619&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h Wed Jan 15 23:58:54 
2014
@@ -413,7 +413,7 @@ namespace Messaging {
 
         void SetContent(cli::array<System::Byte> ^ bytes, int offset, int 
size);
 
-        //TODO:: void setContent(Bytes{} bytes, offset, length);
+        void SetContentObject(System::Object ^ managedObject);
 
         // get content as string
         System::String ^ GetContent();
@@ -430,6 +430,9 @@ namespace Messaging {
         // get content as bytes
         void GetContent(cli::array<System::Byte> ^ arr);
 
+        // get content as object
+        void GetContentObject(System::Object ^ object);
+
         //
         // ContentSize
         //

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp?rev=1558619&r1=1558618&r2=1558619&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp Wed Jan 15 
23:58:54 2014
@@ -266,97 +266,11 @@ namespace Messaging {
     {
         // For each object in the message map,
         //  create a .NET object and add it to the dictionary.
-        for (::qpid::types::Variant::Map::const_iterator i = qpidMap.begin(); 
i != qpidMap.end(); ++i) {
-            // Get the name
+        for (::qpid::types::Variant::Map::const_iterator i = qpidMap.begin(); 
i != qpidMap.end(); ++i)
+        {
             System::String ^ elementName = gcnew String(i->first.c_str());
-
-            ::qpid::types::Variant     variant = i->second;
-            ::qpid::types::VariantType vType   = variant.getType();
-
-            switch (vType)
-            {
-            case ::qpid::types::VAR_VOID:
-                dict[elementName] = nullptr;
-                break;
-
-            case ::qpid::types::VAR_BOOL:
-                dict[elementName] = variant.asBool();
-                break;
-
-            case ::qpid::types::VAR_UINT8:
-                dict[elementName] = variant.asUint8();
-                break;
-
-            case ::qpid::types::VAR_UINT16:
-                dict[elementName] = variant.asUint16();
-                break;
-
-            case ::qpid::types::VAR_UINT32:
-                dict[elementName] = variant.asUint32();
-                break;
-
-            case ::qpid::types::VAR_UINT64:
-                dict[elementName] = variant.asUint64();
-                break;
-
-            case ::qpid::types::VAR_INT8:
-                dict[elementName] = variant.asInt8();
-                break;
-
-            case ::qpid::types::VAR_INT16:
-                dict[elementName] = variant.asInt16();
-                break;
-
-            case ::qpid::types::VAR_INT32:
-                dict[elementName] = variant.asInt32();
-                break;
-
-            case ::qpid::types::VAR_INT64:
-                dict[elementName] = variant.asInt64();
-                break;
-
-            case ::qpid::types::VAR_FLOAT:
-                dict[elementName] = variant.asFloat();
-                break;
-
-            case ::qpid::types::VAR_DOUBLE:
-                dict[elementName] = variant.asDouble();
-                break;
-
-            case ::qpid::types::VAR_STRING:
-                {
-                    System::String ^ elementValue = gcnew 
System::String(variant.asString().c_str());
-                    dict[elementName] = elementValue;
-                    break;
-                }
-            case ::qpid::types::VAR_MAP:
-                {
-                    QpidMap ^ newDict = gcnew QpidMap();
-
-                    NativeToManaged(variant.asMap(), newDict);
-
-                    dict[elementName] = newDict;
-                    break;
-                }
-
-            case ::qpid::types::VAR_LIST:
-                {
-                    QpidList ^ newList = gcnew QpidList();
-
-                    NativeToManaged(variant.asList(), newList);
-
-                    dict[elementName] = newList;
-                    break;
-                }
-
-            case ::qpid::types::VAR_UUID:
-                {
-                    System::String ^ elementValue = gcnew 
System::String(variant.asUuid().str().c_str());
-                    System::Guid ^ newGuid = System::Guid(elementValue);
-                    dict[elementName] = newGuid;
-                }
-                break;
-            }
+            ::qpid::types::Variant variant = i->second;
+            dict[elementName] = NativeToManagedObject(variant);
         }
     }
 
@@ -370,92 +284,137 @@ namespace Messaging {
         for (::qpid::types::Variant::List::const_iterator i = 
qpidList.begin(); i != qpidList.end(); ++i)
         {
             ::qpid::types::Variant     variant = *i;
-            ::qpid::types::VariantType vType   = variant.getType();
+            (*managedList).Add( NativeToManagedObject(variant) );
+        }
+    }
+
 
-            switch (vType)
+    System::Object ^ TypeTranslator::NativeToManagedObject(
+        ::qpid::types::Variant & nativeObject)
+    {
+        //  create a .NET object and return it
+        ::qpid::types::VariantType vType   = nativeObject.getType();
+        System::Object ^ managedObject = nullptr;
+
+        switch (vType)
+        {
+        case ::qpid::types::VAR_VOID:
             {
-            case ::qpid::types::VAR_VOID:
-                (*managedList).Add(nullptr);
                 break;
+            }
 
-            case ::qpid::types::VAR_BOOL:
-                (*managedList).Add(variant.asBool());
+        case ::qpid::types::VAR_BOOL:
+            {
+                bool result = nativeObject.asBool();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_UINT8:
-                (*managedList).Add(variant.asUint8());
+        case ::qpid::types::VAR_UINT8:
+            {
+                byte result = nativeObject.asUint8();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_UINT16:
-                (*managedList).Add(variant.asUint16());
+        case ::qpid::types::VAR_UINT16:
+            {
+                unsigned short result = nativeObject.asUint16();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_UINT32:
-                (*managedList).Add(variant.asUint32());
+        case ::qpid::types::VAR_UINT32:
+            {
+                unsigned long result = nativeObject.asUint32();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_UINT64:
-                (*managedList).Add(variant.asUint64());
+        case ::qpid::types::VAR_UINT64:
+            {
+                unsigned __int64 result = nativeObject.asUint64();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_INT8:
-                (*managedList).Add(variant.asInt8());
+        case ::qpid::types::VAR_INT8:
+            {
+                System::SByte result = nativeObject.asInt8();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_INT16:
-                (*managedList).Add(variant.asInt16());
+        case ::qpid::types::VAR_INT16:
+            {
+                short result = nativeObject.asInt16();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_INT32:
-                (*managedList).Add(variant.asInt32());
+        case ::qpid::types::VAR_INT32:
+            {
+                long result = nativeObject.asInt32();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_INT64:
-                (*managedList).Add(variant.asInt64());
+        case ::qpid::types::VAR_INT64:
+            {
+                __int64 result = nativeObject.asInt64();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_FLOAT:
-                (*managedList).Add(variant.asFloat());
+        case ::qpid::types::VAR_FLOAT:
+            {
+                float result = nativeObject.asFloat();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_DOUBLE:
-                (*managedList).Add(variant.asDouble());
+        case ::qpid::types::VAR_DOUBLE:
+            {
+                double result = nativeObject.asDouble();
+                managedObject = result;
                 break;
+            }
 
-            case ::qpid::types::VAR_STRING:
-                {
-                    System::String ^ elementValue = gcnew 
System::String(variant.asString().c_str());
-                    (*managedList).Add(elementValue);
-                    break;
-                }
-            case ::qpid::types::VAR_MAP:
-                {
-                    QpidMap ^ newDict = gcnew QpidMap();
-
-                    NativeToManaged(variant.asMap(), newDict);
+        case ::qpid::types::VAR_STRING:
+            {
+                System::String ^ elementValue = gcnew 
System::String(nativeObject.asString().c_str());
+                managedObject = elementValue;
+                break;
+            }
+        case ::qpid::types::VAR_MAP:
+            {
+                QpidMap ^ newDict = gcnew QpidMap();
 
-                    (*managedList).Add(newDict);
-                    break;
-                }
+                NativeToManaged(nativeObject.asMap(), newDict);
 
-            case ::qpid::types::VAR_LIST:
-                {
-                    QpidList ^ newList = gcnew QpidList();
+                managedObject = newDict;
+                break;
+            }
 
-                    NativeToManaged(variant.asList(), newList);
+        case ::qpid::types::VAR_LIST:
+            {
+                QpidList ^ newList = gcnew QpidList();
 
-                    (*managedList).Add(newList);
-                    break;
-                }
+                NativeToManaged(nativeObject.asList(), newList);
 
-            case ::qpid::types::VAR_UUID:
-                {
-                    System::String ^ elementValue = gcnew 
System::String(variant.asUuid().str().c_str());
-                    System::Guid ^ newGuid = System::Guid(elementValue);
-                    (*managedList).Add(newGuid);
-                }
+                managedObject = newList;
                 break;
             }
+
+        case ::qpid::types::VAR_UUID:
+            {
+                System::String ^ elementValue = gcnew 
System::String(nativeObject.asUuid().str().c_str());
+                System::Guid ^ newGuid = System::Guid(elementValue);
+                managedObject = newGuid;
+            }
+            break;
         }
+
+        return managedObject;
     }
 }}}}

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h?rev=1558619&r1=1558618&r2=1558619&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h Wed Jan 15 
23:58:54 2014
@@ -72,5 +72,10 @@ namespace Messaging {
         static void NativeToManaged(
             ::qpid::types::Variant::List & qpidList,
             QpidList ^ managedList);
+
+        // The given object is a qpid Variant
+        // Return it as a managed System::Object
+        static System::Object ^ NativeToManagedObject(
+            ::qpid::types::Variant & nativeObject);
     };
 }}}}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to