From 7613e7c400e33482eefe7ea430a92eee5d4ffebf Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Thu, 7 Jun 2012 17:35:20 +0000 Subject: QPID-4027 Handles the empty and null map case. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1347732 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/bindings/swig_java_helper.i | 9 +++++++++ qpid/cpp/bindings/swig_java_typemaps.i | 21 ++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/qpid/cpp/bindings/swig_java_helper.i b/qpid/cpp/bindings/swig_java_helper.i index a5bd8d1b9d..a42f02b480 100644 --- a/qpid/cpp/bindings/swig_java_helper.i +++ b/qpid/cpp/bindings/swig_java_helper.i @@ -27,6 +27,7 @@ %pragma(java) moduleimports=%{ import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -63,6 +64,9 @@ import java.util.Set; static long getVariantMap(final Map m) { + //optimizing for the null & empty map case. + if (m == null || m.size() == 0) { return 0; } + WriteOnlyVariantMapWrapper map = new WriteOnlyVariantMapWrapper(); for (String key: m.keySet()) { @@ -73,6 +77,11 @@ import java.util.Set; static Map getJavaMap(final ReadOnlyVariantMapWrapper map) { + if (map == null) + { + return Collections.emptyMap(); + } + return new Map() { @Override diff --git a/qpid/cpp/bindings/swig_java_typemaps.i b/qpid/cpp/bindings/swig_java_typemaps.i index 07b89cffa3..f6282c5aaa 100644 --- a/qpid/cpp/bindings/swig_java_typemaps.i +++ b/qpid/cpp/bindings/swig_java_typemaps.i @@ -90,8 +90,16 @@ /* -- qpid::types::Variant::Map& -- */ %typemap(in) (qpid::types::Variant::Map&){ - WriteOnlyVariantMapWrapper* mapper = *(WriteOnlyVariantMapWrapper **)&$input; - $1 = new qpid::types::Variant::Map((mapper->getVariantMap())); + + if ($input == 0) // empty or null map case. + { + $1 = new qpid::types::Variant::Map(); + } + else + { + WriteOnlyVariantMapWrapper* mapper = *(WriteOnlyVariantMapWrapper **)&$input; + $1 = new qpid::types::Variant::Map((mapper->getVariantMap())); + } } %typemap(javain) (qpid::types::Variant::Map&) "$module.getVariantMap($javainput)" @@ -101,7 +109,14 @@ } %typemap(out) qpid::types::Variant::Map& { - *(ReadOnlyVariantMapWrapper **)&jresult = new ReadOnlyVariantMapWrapper(jenv,*$1); + if ($1->size() == 0) + { + jresult = 0; + } + else + { + *(ReadOnlyVariantMapWrapper **)&jresult = new ReadOnlyVariantMapWrapper(jenv,*$1); + } } %typemap(javaout) qpid::types::Variant::Map& { -- cgit v1.2.1