*not part of the build*
fix for 86789 git-svn-id: svn://10.0.0.236/trunk@97937 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
@@ -27,20 +27,20 @@ import java.lang.ref.*;
|
||||
|
||||
class ProxyKey {
|
||||
ProxyKey(long _oid, IID _iid) {
|
||||
oid = new Long(_oid);
|
||||
iid = _iid;
|
||||
oid = new Long(_oid);
|
||||
iid = _iid;
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof ProxyKey)) {
|
||||
return false;
|
||||
}
|
||||
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
|
||||
if (! (obj instanceof ProxyKey)) {
|
||||
return false;
|
||||
}
|
||||
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
|
||||
}
|
||||
public int hashCode() {
|
||||
return oid.hashCode();
|
||||
return oid.hashCode();
|
||||
}
|
||||
public String toString() {
|
||||
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
|
||||
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
|
||||
}
|
||||
Long oid;
|
||||
IID iid;
|
||||
@@ -51,34 +51,34 @@ public class ProxyFactory {
|
||||
Debug.log("--[java] ProxyFactory.getInterface "+iid);
|
||||
return InterfaceRegistry.getInterface(iid);
|
||||
}
|
||||
|
||||
|
||||
public static Object getProxy(long oid, IID iid, long orb) {
|
||||
try {
|
||||
Debug.log("--[java] ProxyFactory.getProxy "+iid);
|
||||
ProxyKey key = new ProxyKey(oid, iid);
|
||||
Object obj = null;
|
||||
Object result = null;
|
||||
if (proxies != null) {
|
||||
obj = proxies.get(key);
|
||||
if (obj != null
|
||||
&& (obj instanceof Reference)) {
|
||||
result = ((Reference)obj).get();
|
||||
Debug.log("--[java] ProxyFactory.getProxy "+iid);
|
||||
ProxyKey key = new ProxyKey(oid, iid);
|
||||
Object obj = null;
|
||||
Object result = null;
|
||||
if (proxies != null) {
|
||||
obj = proxies.get(key);
|
||||
if (obj != null
|
||||
&& (obj instanceof Reference)) {
|
||||
result = ((Reference)obj).get();
|
||||
}
|
||||
} else {
|
||||
proxies = new Hashtable();
|
||||
}
|
||||
} else {
|
||||
proxies = new Hashtable();
|
||||
}
|
||||
if (result == null) {
|
||||
Class inter = getInterface(iid);
|
||||
if (inter == null) {
|
||||
Debug.log("--[java] ProxyFactory.getProxy we did not find interface for iid="+iid+"returing null");
|
||||
return null;
|
||||
if (result == null) {
|
||||
Class inter = getInterface(iid);
|
||||
if (inter == null) {
|
||||
Debug.log("--[java] ProxyFactory.getProxy we did not find interface for iid="+iid+"returing null");
|
||||
return null;
|
||||
}
|
||||
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
|
||||
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
|
||||
proxies.put(new WeakReference(result), key);
|
||||
}
|
||||
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
|
||||
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
|
||||
proxies.put(new WeakReference(result), key);
|
||||
}
|
||||
Debug.log("--[java] ProxyFactory.getProxy we got proxy "+result);
|
||||
return result;
|
||||
Debug.log("--[java] ProxyFactory.getProxy we got proxy "+result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Debug.log("--[java] ProxyFactory.getProxy we got exception "+e);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@ import java.lang.reflect.*;
|
||||
|
||||
class ProxyHandler implements InvocationHandler {
|
||||
ProxyHandler(long _oid, IID _iid, long _orb) {
|
||||
oid = _oid;
|
||||
iid = _iid;
|
||||
orb = _orb;
|
||||
oid = _oid;
|
||||
iid = _iid;
|
||||
orb = _orb;
|
||||
Utilities.callMethod(oid, null, iid, orb, null); //it is hack method = null means addref
|
||||
}
|
||||
public Object invoke(Object proxy,
|
||||
Method method,
|
||||
@@ -39,6 +40,7 @@ class ProxyHandler implements InvocationHandler {
|
||||
} else if (str.equals("clone")) {
|
||||
throw new java.lang.CloneNotSupportedException();
|
||||
} else if (str.equals("finalize")) {
|
||||
Utilities.callMethod(oid, method, iid, orb, args);
|
||||
finalize();
|
||||
} else if (str.equals("equals")) {
|
||||
if (args[0] instanceof ProxyHandler) {
|
||||
@@ -64,3 +66,5 @@ class ProxyHandler implements InvocationHandler {
|
||||
private long orb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +74,14 @@ public class Utilities {
|
||||
|
||||
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
|
||||
Debug.log("--[java]Utilities.callMethod "+method);
|
||||
int mid = InterfaceRegistry.getIndexByMethod(method, iid);
|
||||
int mid;
|
||||
if (method == null) {
|
||||
mid = 1; //it is hack method = null means addref
|
||||
} else if ("finalize".equals(method.getName())) {
|
||||
mid = 2;
|
||||
} else {
|
||||
mid = InterfaceRegistry.getIndexByMethod(method, iid);
|
||||
}
|
||||
if (mid < 0) {
|
||||
Debug.log("--[java]Utilities.callMethod we do not have implementation for "+method);
|
||||
return null;
|
||||
|
||||
@@ -34,7 +34,7 @@ jclass bcJavaStub::objectClass = NULL;
|
||||
jclass bcJavaStub::utilitiesClass = NULL;
|
||||
jmethodID bcJavaStub::callMethodByIndexMID = NULL;
|
||||
|
||||
bcJavaStub::bcJavaStub(jobject obj) {
|
||||
bcJavaStub::bcJavaStub(jobject obj) : orb(NULL) {
|
||||
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
|
||||
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStub::bcJavaStub \n"));
|
||||
if (!obj) {
|
||||
@@ -43,11 +43,24 @@ bcJavaStub::bcJavaStub(jobject obj) {
|
||||
}
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
object = env->NewGlobalRef(obj);
|
||||
refCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
bcJavaStub::~bcJavaStub() {
|
||||
bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object);
|
||||
if (orb != NULL) {
|
||||
orb->UnregisterStub(oid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void bcJavaStub::SetORB(bcIORB *_orb) {
|
||||
orb = _orb;
|
||||
}
|
||||
|
||||
void bcJavaStub::SetOID(bcOID _oid) {
|
||||
oid = _oid;
|
||||
}
|
||||
|
||||
void bcJavaStub::Dispatch(bcICall *call) {
|
||||
@@ -57,6 +70,20 @@ void bcJavaStub::Dispatch(bcICall *call) {
|
||||
bcIID iid; bcOID oid; bcMID mid;
|
||||
jobjectArray args;
|
||||
call->GetParams(&iid, &oid, &mid);
|
||||
|
||||
if (mid == 1) { //AddRef
|
||||
refCounter++;
|
||||
return;
|
||||
} else if (mid == 2) { //Release
|
||||
refCounter--;
|
||||
printf("-java mid==2\n");
|
||||
if (refCounter <= 0) {
|
||||
printf("-java delete\n");
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
|
||||
|
||||
@@ -31,8 +31,13 @@ class bcJavaStub : public bcIStub {
|
||||
bcJavaStub(jobject obj);
|
||||
virtual ~bcJavaStub();
|
||||
virtual void Dispatch(bcICall *call) ;
|
||||
virtual void SetORB(bcIORB *orb);
|
||||
virtual void SetOID(bcOID oid);
|
||||
private:
|
||||
bcIORB *orb;
|
||||
bcOID oid;
|
||||
jobject object;
|
||||
PRUint32 refCounter;
|
||||
static jclass objectClass;
|
||||
static jclass utilitiesClass;
|
||||
static jmethodID callMethodByIndexMID;
|
||||
|
||||
@@ -52,8 +52,15 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
|
||||
str = env->GetStringUTFChars(jiid,NULL);
|
||||
iid.Parse(str);
|
||||
env->ReleaseStringUTFChars(jiid,str);
|
||||
if (mid == 2) {
|
||||
INVOKE_RELEASE(&oid,&iid,orb);
|
||||
return NULL;
|
||||
} else if (mid == 1) {
|
||||
INVOKE_ADDREF(&oid,&iid,orb);
|
||||
return NULL;
|
||||
}
|
||||
bcICall *call = orb->CreateCall(&iid, &oid, mid);
|
||||
|
||||
|
||||
/*****/
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
|
||||
Reference in New Issue
Block a user