зеркало из https://github.com/mozilla/pjs.git
Merge duplicate code.
Original committer: pedemont%us.ibm.com Original revision: 1.19 Original date: 2005/01/20 22:07:26
This commit is contained in:
Родитель
7ee9abdeeb
Коммит
66b42dfb0e
|
@ -669,39 +669,16 @@ FinalizeParams(JNIEnv *env, const jobject aParam,
|
||||||
if (aParamInfo.IsOut() && aParam) { // 'inout' & 'out'
|
if (aParamInfo.IsOut() && aParam) { // 'inout' & 'out'
|
||||||
jobject java_obj = nsnull;
|
jobject java_obj = nsnull;
|
||||||
if (xpcom_obj) {
|
if (xpcom_obj) {
|
||||||
// Find matching Java object for given xpcom object
|
nsID iid;
|
||||||
java_obj = gBindings->GetJavaObject(env, xpcom_obj);
|
rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo,
|
||||||
|
aMethodIndex, aDispatchParams, PR_TRUE, iid);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
break;
|
||||||
|
|
||||||
// If no matching Java object exists, create one
|
// Get matching Java object for given xpcom object
|
||||||
if (java_obj == nsnull) {
|
rv = gBindings->GetJavaObject(env, xpcom_obj, iid, PR_TRUE, &java_obj);
|
||||||
// wrap xpcom instance
|
if (NS_FAILED(rv))
|
||||||
nsID iid;
|
break;
|
||||||
JavaXPCOMInstance* inst;
|
|
||||||
rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo,
|
|
||||||
aMethodIndex, aDispatchParams,
|
|
||||||
PR_TRUE, iid);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
nsISupports* variant;
|
|
||||||
variant = NS_REINTERPRET_CAST(nsISupports*, xpcom_obj);
|
|
||||||
rv = CreateJavaXPCOMInstance(variant, &iid, &inst);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
break;
|
|
||||||
NS_RELEASE(variant); // JavaXPCOMInstance has owning ref
|
|
||||||
|
|
||||||
// create java stub
|
|
||||||
char* iface_name;
|
|
||||||
rv = inst->InterfaceInfo()->GetName(&iface_name);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
break;
|
|
||||||
java_obj = CreateJavaWrapper(env, iface_name);
|
|
||||||
|
|
||||||
if (java_obj) {
|
|
||||||
// Associate XPCOM object w/ Java stub
|
|
||||||
gBindings->AddBinding(env, java_obj, inst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// put new Java object into output array
|
// put new Java object into output array
|
||||||
|
@ -889,33 +866,18 @@ SetRetval(JNIEnv *env, const nsXPTParamInfo &aParamInfo,
|
||||||
case nsXPTType::T_INTERFACE_IS:
|
case nsXPTType::T_INTERFACE_IS:
|
||||||
{
|
{
|
||||||
if (aVariant.val.p) {
|
if (aVariant.val.p) {
|
||||||
jobject java_obj = gBindings->GetJavaObject(env, aVariant.val.p);
|
nsID iid;
|
||||||
|
rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo, aMethodIndex,
|
||||||
|
aDispatchParams, PR_TRUE, iid);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
break;
|
||||||
|
|
||||||
if (java_obj == nsnull) {
|
// Get matching Java object for given xpcom object
|
||||||
nsID iid;
|
jobject java_obj;
|
||||||
JavaXPCOMInstance* inst;
|
rv = gBindings->GetJavaObject(env, aVariant.val.p, iid, PR_TRUE,
|
||||||
rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo,
|
&java_obj);
|
||||||
aMethodIndex, aDispatchParams, PR_TRUE, iid);
|
if (NS_FAILED(rv))
|
||||||
if (NS_FAILED(rv))
|
break;
|
||||||
return rv;
|
|
||||||
|
|
||||||
nsISupports* variant;
|
|
||||||
variant = NS_REINTERPRET_CAST(nsISupports*, aVariant.val.p);
|
|
||||||
rv = CreateJavaXPCOMInstance(variant, &iid, &inst);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
break;
|
|
||||||
NS_RELEASE(variant); // JavaXPCOMInstance has owning ref
|
|
||||||
|
|
||||||
// create java stub
|
|
||||||
char* iface_name;
|
|
||||||
rv = inst->InterfaceInfo()->GetName(&iface_name);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
break;
|
|
||||||
java_obj = CreateJavaWrapper(env, iface_name);
|
|
||||||
|
|
||||||
if (java_obj)
|
|
||||||
gBindings->AddBinding(env, java_obj, inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If returned object is an nsJavaXPTCStub, release it.
|
// If returned object is an nsJavaXPTCStub, release it.
|
||||||
nsISupports* xpcom_obj = NS_STATIC_CAST(nsISupports*, aVariant.val.p);
|
nsISupports* xpcom_obj = NS_STATIC_CAST(nsISupports*, aVariant.val.p);
|
||||||
|
@ -1132,27 +1094,67 @@ CallXPCOMMethod(JNIEnv *env, jclass that, jobject aJavaObject,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
jobject
|
nsresult
|
||||||
CreateJavaWrapper(JNIEnv* env, const char* aClassName)
|
CreateJavaProxy(JNIEnv* env, nsISupports* aXPCOMObject, const nsIID& aIID,
|
||||||
|
jobject* aResult)
|
||||||
{
|
{
|
||||||
jobject java_stub = nsnull;
|
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||||
|
if (!aResult)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
// Create stub class name
|
jobject java_obj = nsnull;
|
||||||
nsCAutoString class_name("org/mozilla/xpcom/stubs/");
|
|
||||||
class_name.AppendASCII(aClassName);
|
|
||||||
class_name.AppendLiteral("_Stub");
|
|
||||||
|
|
||||||
// Create Java stub for XPCOM object
|
nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();
|
||||||
jclass clazz;
|
NS_ASSERTION(iim != nsnull, "Failed to get InterfaceInfoManager");
|
||||||
clazz = env->FindClass(class_name.get());
|
if (!iim)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
if (clazz) {
|
// Get interface info for class
|
||||||
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
|
nsCOMPtr<nsIInterfaceInfo> info;
|
||||||
if (constructor) {
|
nsresult rv = iim->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||||
java_stub = env->NewObject(clazz, constructor);
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
// Wrap XPCOM object
|
||||||
|
JavaXPCOMInstance* inst = new JavaXPCOMInstance(aXPCOMObject, info);
|
||||||
|
if (!inst)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
// Get interface name
|
||||||
|
char* iface_name;
|
||||||
|
rv = info->GetName(&iface_name);
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
// Create proxy class name
|
||||||
|
nsCAutoString class_name("org/mozilla/xpcom/stubs/");
|
||||||
|
class_name.AppendASCII(iface_name);
|
||||||
|
class_name.AppendLiteral("_Stub");
|
||||||
|
nsMemory::Free(iface_name);
|
||||||
|
|
||||||
|
// Create java proxy object
|
||||||
|
jclass clazz;
|
||||||
|
clazz = env->FindClass(class_name.get());
|
||||||
|
if (clazz) {
|
||||||
|
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
|
||||||
|
if (constructor) {
|
||||||
|
java_obj = env->NewObject(clazz, constructor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (java_obj) {
|
||||||
|
// Associate XPCOM object with Java proxy
|
||||||
|
rv = gBindings->AddBinding(env, java_obj, inst);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
*aResult = java_obj;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return java_stub;
|
// If there was an error, clean up.
|
||||||
|
delete inst;
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,20 +103,6 @@ private:
|
||||||
nsCOMPtr<nsIInterfaceInfo> mIInfo;
|
nsCOMPtr<nsIInterfaceInfo> mIInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new JavaXPCOMInstance which holds the xpcom object and its
|
|
||||||
* interface info based on the given IID.
|
|
||||||
*
|
|
||||||
* @param aXPCOMObject xpcom object to wrap
|
|
||||||
* @param aIID interface IID for aXPCOMObject
|
|
||||||
* @param aResult pointer that will hold new JavaXPCOMInstance
|
|
||||||
*
|
|
||||||
* @return NS_ERROR_OUT_OF_MEMORY if out of memory;
|
|
||||||
* NS_ERROR_FAILURE for any other error condition
|
|
||||||
*/
|
|
||||||
nsresult CreateJavaXPCOMInstance(nsISupports* aXPCOMObject, const nsIID* aIID,
|
|
||||||
JavaXPCOMInstance** aResult);
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
* Java<->XPCOM binding stores
|
* Java<->XPCOM binding stores
|
||||||
|
@ -145,9 +131,10 @@ public:
|
||||||
// Given a Java object, returns the associated XPCOM object.
|
// Given a Java object, returns the associated XPCOM object.
|
||||||
void* GetXPCOMObject(JNIEnv* env, jobject aJavaObject);
|
void* GetXPCOMObject(JNIEnv* env, jobject aJavaObject);
|
||||||
|
|
||||||
// Given an XPCOM object, returns the associated Java Object.
|
// Given an XPCOM object, returns the associated Java Object. If a Java
|
||||||
jobject GetJavaObject(JNIEnv* env, void* aXPCOMObject);
|
// object doesn't exist, then create a Java proxy for the XPCOM object.
|
||||||
|
NS_IMETHOD GetJavaObject(JNIEnv* env, void* aXPCOMObject, const nsIID& aIID,
|
||||||
|
PRBool aDoReleaseObject, jobject* aResult);
|
||||||
private:
|
private:
|
||||||
PLDHashTable* mJAVAtoXPCOMBindings;
|
PLDHashTable* mJAVAtoXPCOMBindings;
|
||||||
PLDHashTable* mXPCOMtoJAVABindings;
|
PLDHashTable* mXPCOMtoJAVABindings;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче