Common logic to create and cache adapter class on demand is moved to the new method getAdapterClass
git-svn-id: svn://10.0.0.236/trunk@148372 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
6679f3936f
commit
f6f9a54c3a
@ -21,6 +21,7 @@
|
||||
* Contributor(s):
|
||||
* Patrick Beard
|
||||
* Norris Boyd
|
||||
* Igor Bukanov
|
||||
* Mike McCabe
|
||||
* Matthias Radestock
|
||||
* Andi Vajda
|
||||
@ -123,24 +124,8 @@ public final class JavaAdapter
|
||||
System.arraycopy(intfs, 0, interfaces, 0, interfaceCount);
|
||||
Scriptable obj = ScriptRuntime.toObject(cx, scope, args[N - 1]);
|
||||
|
||||
GlobalScope global = GlobalScope.get(scope);
|
||||
Hashtable generated = global.javaAdapterGeneratedClasses;
|
||||
|
||||
ObjToIntMap names = getObjectFunctionNames(obj);
|
||||
JavaAdapterSignature sig;
|
||||
sig = new JavaAdapterSignature(superClass, interfaces, names);
|
||||
Class adapterClass = (Class) generated.get(sig);
|
||||
if (adapterClass == null) {
|
||||
String adapterName;
|
||||
synchronized (generated) {
|
||||
adapterName = "adapter" + global.javaAdapterSerial++;
|
||||
}
|
||||
byte[] code = createAdapterCode(names, adapterName,
|
||||
superClass, interfaces, null);
|
||||
|
||||
adapterClass = loadAdapterClass(cx, adapterName, code);
|
||||
generated.put(sig, adapterClass);
|
||||
}
|
||||
Class adapterClass = getAdapterClass(scope, superClass, interfaces,
|
||||
obj);
|
||||
|
||||
Class[] ctorParms = { ScriptRuntime.ScriptableClass };
|
||||
Object[] ctorArgs = { obj };
|
||||
@ -160,28 +145,8 @@ public final class JavaAdapter
|
||||
Scriptable obj, Scriptable self)
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
GlobalScope global = GlobalScope.get(scope);
|
||||
Hashtable generated = global.javaAdapterGeneratedClasses;
|
||||
|
||||
ObjToIntMap names = getObjectFunctionNames(obj);
|
||||
JavaAdapterSignature sig;
|
||||
sig = new JavaAdapterSignature(superClass, interfaces, names);
|
||||
Class adapterClass = (Class) generated.get(sig);
|
||||
if (adapterClass == null) {
|
||||
String adapterName;
|
||||
synchronized (generated) {
|
||||
adapterName = "adapter" + global.javaAdapterSerial++;
|
||||
}
|
||||
byte[] code = createAdapterCode(names, adapterName,
|
||||
superClass, interfaces, null);
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
adapterClass = loadAdapterClass(cx, adapterName, code);
|
||||
generated.put(sig, adapterClass);
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
Class adapterClass = getAdapterClass(scope, superClass, interfaces,
|
||||
obj);
|
||||
|
||||
try {
|
||||
Class[] ctorParms = {
|
||||
@ -221,6 +186,30 @@ public final class JavaAdapter
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Class getAdapterClass(Scriptable scope, Class superClass,
|
||||
Class[] interfaces, Scriptable obj)
|
||||
{
|
||||
GlobalScope global = GlobalScope.get(scope);
|
||||
Hashtable generated = global.javaAdapterGeneratedClasses;
|
||||
|
||||
ObjToIntMap names = getObjectFunctionNames(obj);
|
||||
JavaAdapterSignature sig;
|
||||
sig = new JavaAdapterSignature(superClass, interfaces, names);
|
||||
Class adapterClass = (Class) generated.get(sig);
|
||||
if (adapterClass == null) {
|
||||
String adapterName;
|
||||
synchronized (generated) {
|
||||
adapterName = "adapter" + global.javaAdapterSerial++;
|
||||
}
|
||||
byte[] code = createAdapterCode(names, adapterName,
|
||||
superClass, interfaces, null);
|
||||
|
||||
adapterClass = loadAdapterClass(adapterName, code);
|
||||
generated.put(sig, adapterClass);
|
||||
}
|
||||
return adapterClass;
|
||||
}
|
||||
|
||||
public static byte[] createAdapterCode(ObjToIntMap functionNames,
|
||||
String adapterName,
|
||||
Class superClass,
|
||||
@ -340,9 +329,9 @@ public final class JavaAdapter
|
||||
return cfw.toByteArray();
|
||||
}
|
||||
|
||||
private static Class loadAdapterClass(Context cx, String className,
|
||||
byte[] classBytes)
|
||||
private static Class loadAdapterClass(String className, byte[] classBytes)
|
||||
{
|
||||
Context cx = Context.getContext();
|
||||
ClassLoader parentLoader = cx.getApplicationClassLoader();
|
||||
GeneratedClassLoader loader;
|
||||
SecurityController sc = cx.getSecurityController();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user