** NOT PART OF TBOX BUILDS **
BlackConnect M2 check in. It should be possible to implement any scriptable interface in java. Also it should be possible to use any scriptable object from java. Fixed: 15498, 15500 git-svn-id: svn://10.0.0.236/trunk@78858 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
|
||||
|
||||
@@ -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
|
||||
@@ -23,33 +23,36 @@ package org.mozilla.xpcom;
|
||||
|
||||
public class IID {
|
||||
public IID(String iid) {
|
||||
this.iid = (iid == null) ? "" : iid;
|
||||
this.iid = (iid == null) ? "" : iid;
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof IID)) {
|
||||
return false;
|
||||
}
|
||||
boolean res = iid.equals(((IID)obj).iid);
|
||||
return res;
|
||||
if (! (obj instanceof IID)) {
|
||||
return false;
|
||||
}
|
||||
boolean res = iid.equals(((IID)obj).iid);
|
||||
return res;
|
||||
}
|
||||
public String toString() {
|
||||
return "org.mozilla.xpcom.IID@"+iid;
|
||||
return "org.mozilla.xpcom.IID@"+iid;
|
||||
}
|
||||
public int hashCode() {
|
||||
int h = iid.hashCode();
|
||||
return h;
|
||||
int h = iid.hashCode();
|
||||
return h;
|
||||
}
|
||||
public String getString() {
|
||||
return iid;
|
||||
return iid;
|
||||
}
|
||||
private String iid;
|
||||
public static Class TYPE;
|
||||
static {
|
||||
try {
|
||||
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
|
||||
} catch (Exception e) { //it could not happen
|
||||
TYPE = null;
|
||||
}
|
||||
try {
|
||||
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
|
||||
} catch (Exception e) { //it could not happen
|
||||
TYPE = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; 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
|
||||
@@ -50,7 +50,7 @@ public class ProxyClass { //nb it should not be public
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (methods[i].equals(method)) {
|
||||
if (method.equals(methods[i])) {
|
||||
result = i + offset;
|
||||
break;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class ProxyClass { //nb it should not be public
|
||||
}
|
||||
private IID iid;
|
||||
private Method[] methods;
|
||||
private final int offset = 3; //from xpcom
|
||||
private final int offset = 0; //from xpcom
|
||||
static Hashtable classes = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,45 +48,60 @@ class ProxyKey {
|
||||
|
||||
public class ProxyFactory {
|
||||
public static void registerInterfaceForIID(Class inter, IID iid) {
|
||||
System.out.println("--[java] ProxyFactory.registerInterfaceForIID "+iid);
|
||||
if (interfaces == null) {
|
||||
interfaces = new Hashtable();
|
||||
}
|
||||
interfaces.put(iid, inter); //nb who is gonna remove object from cache?
|
||||
System.out.println("--[java] ProxyFactory.registerInterfaceForIID "+iid);
|
||||
if (interfaces == null) {
|
||||
interfaces = new Hashtable();
|
||||
}
|
||||
interfaces.put(iid, inter); //nb who is gonna remove object from cache?
|
||||
}
|
||||
public static Class getInterface(IID iid) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface "+iid);
|
||||
Object obj = null;
|
||||
if (interfaces != null) {
|
||||
obj = interfaces.get(iid);
|
||||
if (obj == null) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface interface== null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!(obj instanceof Class)) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface !(obj instanceof Class"+obj);
|
||||
return null;
|
||||
}
|
||||
return (Class)obj;
|
||||
}
|
||||
|
||||
public static Object getProxy(long oid, IID iid, long orb) {
|
||||
System.out.println("--[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();
|
||||
}
|
||||
if (result == null) {
|
||||
if (interfaces != null) {
|
||||
obj = interfaces.get(iid);
|
||||
if (obj == null) {
|
||||
System.out.println("--[java] ProxyFactory.getProxy obj == null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!(obj instanceof Class)) {
|
||||
System.out.println("--[java] ProxyFactory.getProxy !(obj instanceof Class"+obj);
|
||||
return null;
|
||||
}
|
||||
Class inter = (Class) obj;
|
||||
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
|
||||
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
|
||||
proxies.put(new WeakReference(result), key);
|
||||
}
|
||||
System.out.println("--[java] ProxyFactory.getProxy end"+result);
|
||||
return result;
|
||||
try {
|
||||
System.out.println("--[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();
|
||||
}
|
||||
if (result == null) {
|
||||
Class inter = getInterface(iid);
|
||||
if (inter == null) {
|
||||
System.out.println("--[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);
|
||||
}
|
||||
System.out.println("--[java] ProxyFactory.getProxy we got proxy "+result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
System.out.println("--[java] ProxyFactory.getProxy we got exception "+e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected static Hashtable proxies = null;
|
||||
private static Hashtable interfaces = null;
|
||||
|
||||
@@ -32,10 +32,14 @@ class ProxyHandler implements InvocationHandler {
|
||||
public Object invoke(Object proxy,
|
||||
Method method,
|
||||
Object[] args) throws Throwable {
|
||||
return Utilities.callMethod(oid, method, iid, orb, args);
|
||||
|
||||
System.out.println("--[java]ProxyHandler.invoke "+method);
|
||||
if ("toString".equals(method.getName())) {
|
||||
return "ProxyObject@{oid = "+oid+" iid = "+iid+"}";
|
||||
}
|
||||
return Utilities.callMethod(oid, method, iid, orb, args);
|
||||
}
|
||||
private long oid;
|
||||
private IID iid;
|
||||
private long orb;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -24,26 +24,29 @@ package org.mozilla.xpcom;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
public class Utilities {
|
||||
|
||||
static Object callMethodByIndex(Object obj, IID iid, int mid, Object[] args) {
|
||||
System.out.println("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
System.out.println("--[java]callMethodByIndex args["+i+"] = "+args[i]);
|
||||
}
|
||||
Method method = getMethodByIndex(mid,iid);
|
||||
System.out.println("--callMethodByIndex method "+method);
|
||||
try {
|
||||
if (method != null) {
|
||||
method.invoke(obj,args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null; //nb for testing
|
||||
System.out.println("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
System.out.println("--[java]callMethodByIndex args["+i+"] = "+args[i]);
|
||||
}
|
||||
Method method = getMethodByIndex(mid,iid);
|
||||
System.out.println("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method);
|
||||
try {
|
||||
if (method != null) {
|
||||
method.invoke(obj,args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("--callMethodByIndex method finished"+method);
|
||||
return null; //nb for testing
|
||||
}
|
||||
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
|
||||
System.out.println("--[java]Utilities.callMethod "+method);
|
||||
int mid = getIndexByMethod(method, iid);
|
||||
if (mid <= 0) {
|
||||
System.out.println("--[java]Utilities.callMethod we do not have implementation for "+method);
|
||||
return null;
|
||||
}
|
||||
System.out.println("--[java]Utilities.callMethod "+mid);
|
||||
|
||||
Reference in New Issue
Block a user