summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/java/eval.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-03-10 09:34:20 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-03-10 09:34:20 +0000
commit5a390791d3049d415d98507be8b8ed29f523ecf0 (patch)
treede4c8725fde31872e999c1b56eba31c4abba6590 /sca-cpp/trunk/modules/java/eval.hpp
parent39a1a1829a496c6f0bfdb3439e9958b8734461c4 (diff)
Minor cleanup, renamed mcache to memcache, added a uuid util function to get consistent and unique uuids across languages.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@921270 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/java/eval.hpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/sca-cpp/trunk/modules/java/eval.hpp b/sca-cpp/trunk/modules/java/eval.hpp
index 7da1f20a38..a1cf6ae576 100644
--- a/sca-cpp/trunk/modules/java/eval.hpp
+++ b/sca-cpp/trunk/modules/java/eval.hpp
@@ -26,6 +26,7 @@
* Java component implementation evaluation logic.
*/
#include <jni.h>
+#include <apr_uuid.h>
#include "list.hpp"
#include "value.hpp"
@@ -46,6 +47,7 @@ namespace java {
* Represent a Java VM runtime.
*/
jobject JNICALL nativeInvoke(JNIEnv *env, jobject self, jobject proxy, jobject method, jobjectArray args);
+jobject JNICALL nativeUUID(JNIEnv *env);
class JavaRuntime {
public:
@@ -133,13 +135,21 @@ public:
iterableIsNil = env->GetStaticMethodID(iterableUtilClass, "isNil", "(Ljava/lang/Object;)Z");
iterableCar = env->GetStaticMethodID(iterableUtilClass, "car", "(Ljava/lang/Object;)Ljava/lang/Object;");
iterableCdr = env->GetStaticMethodID(iterableUtilClass, "cdr", "(Ljava/lang/Object;)Ljava/lang/Iterable;");
+ uuidClass = env->FindClass("org/apache/tuscany/UUIDUtil");
// Register our native invocation handler function
- JNINativeMethod nm;
- nm.name = const_cast<char*>("invoke");
- nm.signature = const_cast<char*>("(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
- nm.fnPtr = (void*)nativeInvoke;
- env->RegisterNatives(invokerClass, &nm, 1);
+ JNINativeMethod invokenm;
+ invokenm.name = const_cast<char*>("invoke");
+ invokenm.signature = const_cast<char*>("(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
+ invokenm.fnPtr = (void*)nativeInvoke;
+ env->RegisterNatives(invokerClass, &invokenm, 1);
+
+ // Register our native UUID function
+ JNINativeMethod uuidnm;
+ uuidnm.name = const_cast<char*>("uuid");
+ uuidnm.signature = const_cast<char*>("()Ljava/lang/String;");
+ uuidnm.fnPtr = (void*)nativeUUID;
+ env->RegisterNatives(uuidClass, &uuidnm, 1);
}
JavaVM* jvm;
@@ -173,6 +183,7 @@ public:
jmethodID iterableCar;
jmethodID iterableCdr;
jmethodID iterableIsNil;
+ jclass uuidClass;
};
/**
@@ -247,8 +258,8 @@ public:
};
/**
- * Invocation handler invoke method, dispatches to the lambda function wrapped
- * in the invocation handler.
+ * Native implementation of the InvocationHandler.invoke Java method.
+ * Dispatches the call to the lambda function wrapped in the invocation handler.
*/
jobject JNICALL nativeInvoke(JNIEnv* env, jobject self, unused jobject proxy, jobject method, jobjectArray args) {
@@ -277,6 +288,19 @@ jobject JNICALL nativeInvoke(JNIEnv* env, jobject self, unused jobject proxy, jo
}
/**
+ * Native implementation of IterableUtil.uuid. We are providing a native implementation
+ * of this function as java.util.UUID seems to behave differently with different JDKs.
+ */
+jobject JNICALL nativeUUID(JNIEnv* env) {
+ apr_uuid_t uuid;
+ apr_uuid_get(&uuid);
+ char buf[APR_UUID_FORMATTED_LENGTH];
+ apr_uuid_format(buf, &uuid);
+ string s(buf, APR_UUID_FORMATTED_LENGTH);
+ return env->NewStringUTF(c_str(s));
+}
+
+/**
* Convert a lambda function to Java proxy.
*/
const jobject mkJavaLambda(const JavaRuntime& jr, unused const value& iface, const lambda<value(const list<value>&)>& l) {