qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject svn commit: r1344841 - in /qpid/branches/address-refactor2/qpid: cpp/bindings/ cpp/bindings/qpid/java/ java/client-api/src/main/java/org/apache/qpid/messaging/cpp/ java/lib/
Date Thu, 31 May 2012 18:11:15 GMT
Author: rajith
Date: Thu May 31 18:11:14 2012
New Revision: 1344841

URL: http://svn.apache.org/viewvc?rev=1344841&view=rev
Log:
QPID-4027 Changed the typemaps to provide a java.util.Map based on the
wrapped c++ Variant::Map. Maps returned to the java code are read only.
Need to add code to translate a java.util.Map into a Variant::Map

Added:
    qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp
      - copied, changed from r1343748, qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.cpp
    qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h
      - copied, changed from r1343748, qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.h
Removed:
    qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.cpp
    qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.h
Modified:
    qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/java.i
    qpid/branches/address-refactor2/qpid/cpp/bindings/swig_java_typemaps.i
    qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/CppTest.java
    qpid/branches/address-refactor2/qpid/java/lib/qpid_cpp_jni.jar

Copied: qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp
(from r1343748, qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.cpp)
URL: http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp?p2=qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp&p1=qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.cpp&r1=1343748&r2=1344841&rev=1344841&view=diff
==============================================================================
--- qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.cpp (original)
+++ qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp Thu
May 31 18:11:14 2012
@@ -7,9 +7,9 @@
  * 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
@@ -24,69 +24,92 @@
 
 #include <string>
 
-jmap::jmap(JNIEnv*& jniEnv, qpid::types::Variant::Map*& map): env(jniEnv), varMap(map)
+using namespace qpid::types;
+
+VaraintMapWrapper::VaraintMapWrapper(): env(0), varMap(new Variant::Map())
+
+VaraintMapWrapper::VaraintMapWrapper(JNIEnv*& jniEnv, Variant::Map*& map): env(jniEnv),
varMap(map)
 {
 }
 
-jmap::jobject get(const std::string key) const
+VaraintMapWrapper::jobject get(const std::string key) const
 {
    jobject result;
-        qpid::types::Variant v = varMap[key];
+        Varient::Map::iterator iter = varMap->find(key);
+        if (iter == varMap->end()){
+            return NULL;
+        }
+
+        Variant v = iter->first();
+
         try {
             switch (v->getType()) {
-            case qpid::types::VAR_VOID: {
+            case VAR_VOID: {
                 result = NULL;
                 break;
             }
-            case qpid::types::VAR_BOOL : {
+            case VAR_BOOL : {
                 result = v->asBool() ? JNI_TRUE : JNI_FALSE;
                 break;
             }
-            case qpid::types::VAR_UINT8 :
-            case qpid::types::VAR_UINT16 :
-            case qpid::types::VAR_UINT32 : {
+            case VAR_UINT8 :
+            case VAR_UINT16 :
+            case VAR_UINT32 : {
                 result = (jnit) v->asUint32();
                 break;
             }
-            case qpid::types::VAR_UINT64 : {
+            case VAR_UINT64 : {
                 result = (jlong) v->asUint64();
                 break;
             }
-            case qpid::types::VAR_INT8 : 
-            case qpid::types::VAR_INT16 :
-            case qpid::types::VAR_INT32 : {
+            case VAR_INT8 :
+            case VAR_INT16 :
+            case VAR_INT32 : {
                 result = (jnit) v->asUint32();
                 break;
             }
-            case qpid::types::VAR_INT64 : {
+            case VAR_INT64 : {
                 result = (jlong) v->asUint64();
                 break;
             }
-            case qpid::types::VAR_FLOAT : {
+            case VAR_FLOAT : {
                 result = (jfloat) v->asFloat();
                 break;
             }
-            case qpid::types::VAR_DOUBLE : {
+            case VAR_DOUBLE : {
                 result = (jdouble) v->asDouble();
                 break;
             }
-            case qpid::types::VAR_STRING : {
+            case VAR_STRING : {
                 const std::string val(v->asString());
                 result = env->NewStringUTF(val.data());
                 break;
             }
             }
-        } catch (qpid::types::Exception& ex) {
+        } catch (Exception& ex) {
             result = NULL;  // need to throw exception
         }
 
         return result;
 }
 
-jmap::void put (const jstring key, jobject object)
+VaraintMapWrapper::jboolean containsKey (const jstring key) const
 {
+   return (jboolean)true;
+}
 
+VaraintMapWrapper::jboolean containsValue (const jobject value) const
+{
+   return (jboolean)true;
 }
 
+VaraintMapWrapper::jboolean isEmpty() const
+{
+   return (jboolean)true;
+}
 
+/*   jstring[] keys() const;
+    jobject[] values() const;
+    jinit size() const;
+*/
 

Copied: qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h (from
r1343748, qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.h)
URL: http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h?p2=qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h&p1=qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.h&r1=1343748&r2=1344841&rev=1344841&view=diff
==============================================================================
--- qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/jmap.h (original)
+++ qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h Thu May
31 18:11:14 2012
@@ -7,9 +7,9 @@
  * 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
@@ -24,12 +24,21 @@
 
 #include <string>
 
-class jmap {
+/**
+ * Only primitives types are supported as values.
+ */
+class VaraintMapWrapper {
 
   public:
-    jmap(JNIEnv*& jniEnv, qpid::types::Variant::Map*& map); 
+    VaraintMapWrapper();
+    VaraintMapWrapper(JNIEnv*& jniEnv, qpid::types::Variant::Map*& map);
     jobject get(const std::string key) const;
-    void put (const jstring key, jobject object); 
+    jboolean containsKey (const jstring key) const;
+    jboolean containsValue (const jobject value) const;
+    jboolean isEmpty() const;
+    jobjectArray keys() const;
+    jobjectArray values() const;
+    jint size() const;
 
   private:
     qpid::types::Variant::Map varMap;

Modified: qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/java.i
URL: http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/java.i?rev=1344841&r1=1344840&r2=1344841&view=diff
==============================================================================
--- qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/java.i (original)
+++ qpid/branches/address-refactor2/qpid/cpp/bindings/qpid/java/java.i Thu May 31 18:11:14
2012
@@ -18,15 +18,14 @@
  */
 
 %{
-#include "jmap.h"
-#include <qpid/sys/IntegerTypes.h>
+#include "VaraintMapWrapper.h"
 %}
 
 %module cqpid
 %include "std_string.i"
 %include "../../swig_java_typemaps.i"
 
-%include "jmap.h"
+%include "VaraintMapWrapper.h"
 
 %include "../qpid.i"
 

Modified: qpid/branches/address-refactor2/qpid/cpp/bindings/swig_java_typemaps.i
URL: http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/cpp/bindings/swig_java_typemaps.i?rev=1344841&r1=1344840&r2=1344841&view=diff
==============================================================================
--- qpid/branches/address-refactor2/qpid/cpp/bindings/swig_java_typemaps.i (original)
+++ qpid/branches/address-refactor2/qpid/cpp/bindings/swig_java_typemaps.i Thu May 31 18:11:14
2012
@@ -17,6 +17,152 @@
  * under the License.
  */
 
+/* Module code used by some of the wrapper classes */
+
+%pragma(java) moduleimports=%{
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+%}
+
+%pragma(java) modulecode=%{
+  /** Checks if the buffer passed is a direct buffer
+   *  This method could also convert a non direct buffer into a direct buffer.
+   *  However the extra copying deafeats the purpose of the binding.
+   */
+  static protected java.nio.ByteBuffer isBufferDirect(java.nio.ByteBuffer buff)
+  {
+        if (buff.isDirect())
+        {
+            return buff;
+        }
+        else
+        {
+          throw new RuntimeException("The ByteBuffer passed is not allocated direct");
+        }
+  }
+
+  /** We don't support setting maps into C++ atm, but adding here to get around swig **/
+  static VaraintMapWrapper getVariantMap(final Map<String,Object> map)
+  {
+      return new VaraintMapWrapper();
+  }
+
+  static Map<String, Object> getJavaMap(final VaraintMapWrapper map)
+  {
+        return new Map<String, Object>()
+        {
+            @Override
+            public int size()
+            {
+                return map.size();
+            }
+
+            @Override
+            public boolean isEmpty()
+            {
+                return map.isEmpty();
+            }
+
+            @Override
+            public boolean containsKey(Object key)
+            {
+                return map.containsKey((String)key);
+            }
+
+            @Override
+            public boolean containsValue(Object value)
+            {
+                return map.containsValue(value);
+            }
+
+            @Override
+            public Object get(Object key)
+            {
+                return map.get((String)key);
+            }
+
+            @Override
+            public Object put(String key, Object value)
+            {
+                throw new UnsupportedOperationException("This map is read-only");
+            }
+
+            @Override
+            public Object remove(Object key)
+            {
+                throw new UnsupportedOperationException("This map is read-only");
+            }
+
+            @Override
+            public void putAll(Map<? extends String, ? extends Object> m)
+            {
+                throw new UnsupportedOperationException("This map is read-only");
+            }
+
+            @Override
+            public void clear()
+            {
+                throw new UnsupportedOperationException("This map is read-only");
+            }
+
+            @Override
+            public Set<String> keySet()
+            {
+                Set<String> keys = new HashSet<String>();
+                for (String key:(String[])map.keys())
+                {
+                    keys.add(key);
+                }
+
+                return keys;
+            }
+
+            @Override
+            public Collection<Object> values()
+            {
+                return Arrays.asList(map.values());
+            }
+
+            @Override
+            public Set<Entry<String, Object>> entrySet()
+            {
+                Set<Entry<String, Object>> entries = new HashSet<Entry<String,
Object>>();
+                for (final String key: keySet())
+                {
+                    final Object value = map.get(key);
+                    entries.add(new Entry<String, Object>()
+                    {
+                        @Override
+                        public String getKey()
+                        {
+                            return key;
+                        }
+
+                        @Override
+                        public Object getValue()
+                        {
+                            return value;
+                        }
+
+                        @Override
+                        public Object setValue(Object value)
+                        {
+                            throw new UnsupportedOperationException("This set is read-only");
+                        }
+
+                    });
+                }
+                return entries;
+            }
+
+        };
+  }
+%}
+
+
 /* These 3 typemaps tell SWIG what JNI and Java types to use */
 %typemap(jni) qpid::messaging::Message::BYTE_BUFFER "jobject"
 %typemap(jtype) qpid::messaging::Message::BYTE_BUFFER "java.nio.ByteBuffer"
@@ -30,25 +176,8 @@
 
 %typemap(javain) (qpid::messaging::Message::BYTE_BUFFER) "$module.isBufferDirect($javainput)"
 
-%pragma(java) modulecode=%{
-  /** Checks if the buffer passed is a direct buffer 
-   *  This method could also convert a non direct buffer into a direct buffer.
-   *  However the extra copying deafeats the purpose of the binding.
-   */
-  static protected java.nio.ByteBuffer isBufferDirect(java.nio.ByteBuffer buff) {
-    if (buff.isDirect())
-    {
-        return buff;  
-    }
-    else
-    {
-      throw new RuntimeException("The ByteBuffer passed is not allocated direct");
-    }
-  }
-%}
-
 %typemap(out) qpid::messaging::Message::BYTE_BUFFER {
-  jresult = jenv->NewDirectByteBuffer($1.getStart(), $1.getSize()); 
+  jresult = jenv->NewDirectByteBuffer($1.getStart(), $1.getSize());
 }
 
 %typemap(javaout) qpid::messaging::Message::BYTE_BUFFER {
@@ -56,30 +185,75 @@
 }
 
 %typemap(jni) qpid::types::Variant::Map& "jobject"
-%typemap(jtype) qpid::types::Variant::Map& "jmap"
-%typemap(jstype) qpid::types::Variant::Map& "jmap"
+%typemap(jtype) qpid::types::Variant::Map& "VaraintMapWrapper"
+%typemap(jstype) qpid::types::Variant::Map& "java.util.Map"
 
 %typemap(out) qpid::types::Variant::Map& {
-  *(jmap **)&jresult = new jmap(jenv,$1);
+  *(VaraintMapWrapper **)&jresult = new VaraintMapWrapper(jenv,$1);
 }
 
 %typemap(javaout) qpid::types::Variant::Map& {
-    return $jnicall;
+    return $module.getJavaMap($jnicall);
 }
 
 %typemap(in) (qpid::types::Variant::Map&){
-  $1 = NULL;
+  $1 = new qpid::types::Variant::Map();
 }
 
-%pragma(java) modulecode=%{
-  /** temp hack to get the code compiling.
-   *  We are currently not using any of the methods
-   *  That require us to set a map.
-   */
-  static protected jmap convertToJMap(Object map) {
-    return null;
-  }
-%}
+%typemap(javain) (qpid::types::Variant::Map&) "$module.getVariantMap($javainput)"
+
+%typemap(in) uint8_t {
+    $1 = (uint8_t)$input;
+}
+
+%typemap(out) uint8_t {
+    $result = (jbyte)$1;
+}
+
+%typemap(javaout) uint8_t {
+    return $jnicall;
+}
+
+%typemap(javain) uint8_t "$javainput"
+
+
+%typemap(in) uint32_t {
+    $1 = (uint32_t)$input;
+}
+
+%typemap(out) uint32_t {
+    $result = (jint)$1;
+}
+
+%typemap(javaout) uint32_t {
+    return $jnicall;
+}
+
+%typemap(javain) uint32_t "$javainput"
+
+%typemap(in) uint64_t {
+    $1 = (uint64_t)$input;
+}
+
+%typemap(out) uint64_t {
+    $result = (jlong)$1;
+}
+
+%typemap(javaout) uint64_t {
+    return $jnicall;
+}
+
+%typemap(javain) uint64_t "$javainput"
 
-%typemap(javain) (qpid::types::Variant::Map&) "$module.convertToJMap($javainput)"
+%typemap(jni) uint8_t "jbyte"
+%typemap(jtype) uint8_t "byte"
+%typemap(jstype) uint8_t "byte"
+
+%typemap(jni) uint32_t "jint"
+%typemap(jtype) uint32_t "int"
+%typemap(jstype) uint32_t "int"
+
+%typemap(jni) uint64_t "jlong"
+%typemap(jtype) uint64_t "long"
+%typemap(jstype) uint64_t "long"
 

Modified: qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/CppTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/CppTest.java?rev=1344841&r1=1344840&r2=1344841&view=diff
==============================================================================
--- qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/CppTest.java
(original)
+++ qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/CppTest.java
Thu May 31 18:11:14 2012
@@ -9,7 +9,6 @@ import org.apache.qpid.messaging.Sender;
 
 public class CppTest
 {
-
     public static void main(String[] args)
     {
         System.out.println(System.getProperty("sys.path"));

Modified: qpid/branches/address-refactor2/qpid/java/lib/qpid_cpp_jni.jar
URL: http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/lib/qpid_cpp_jni.jar?rev=1344841&r1=1344840&r2=1344841&view=diff
==============================================================================
Files qpid/branches/address-refactor2/qpid/java/lib/qpid_cpp_jni.jar (original) and qpid/branches/address-refactor2/qpid/java/lib/qpid_cpp_jni.jar
Thu May 31 18:11:14 2012 differ



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message