A src/nsIPluglet.idl
M classes/org/mozilla/pluglet/Registry.java M dist/build.xml M examples/simple/src/main/java/simple/SimplePluglet.java M examples/simple/src/main/web/index.html M mozilla/Makefile.in M mozilla/nppluglet.cpp M mozilla/nppluglet.h M mozilla/nsScriptablePeer.cpp M netbeans/nbproject/build-impl.xml M netbeans/nbproject/genfiles.properties M netbeans/nbproject/project.properties M netbeans/nbproject/project.xml M src/Makefile.in M src/Pluglet.cpp M src/Pluglet.h M src/PlugletEngine.cpp M src/PlugletFactory.cpp M src/Registry.cpp M src/Registry.h R mozilla/nsIPluglet.idl - At this point, I can call from JavaScript and locate an arbitratily named method on the Pluglet instance that conforms to the signature of returning String, and taking 0 or more Strings as arguments. git-svn-id: svn://10.0.0.236/trunk@242001 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package org.mozilla.pluglet;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class Registry {
|
||||
@@ -46,5 +47,66 @@ public class Registry {
|
||||
table.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static String findMatchingPlugletMethod(Pluglet pluglet,
|
||||
String methodName, int numStringArgs) {
|
||||
String result = null;
|
||||
Class plugletClass = pluglet.getClass();
|
||||
Method [] methods = plugletClass.getMethods();
|
||||
boolean foundMatch = false;
|
||||
Method matchingMethod = null;
|
||||
// For each of the methods on the Pluglet
|
||||
for (Method cur : methods) {
|
||||
if (foundMatch) {
|
||||
break;
|
||||
}
|
||||
// See if the name of the method matches the name we
|
||||
// are looking for.
|
||||
if (cur.getName().equals(methodName)) {
|
||||
// If so, does it return String?
|
||||
if (String.class == cur.getReturnType()) {
|
||||
// If so, do the number of arguments match?
|
||||
Class [] paramTypes = cur.getParameterTypes();
|
||||
if (numStringArgs == paramTypes.length) {
|
||||
foundMatch = true;
|
||||
matchingMethod = cur;
|
||||
// If so, are all the arguments of type String?
|
||||
for (Class curClass : paramTypes) {
|
||||
if (String.class != curClass) {
|
||||
// If not, this method is not a match.
|
||||
foundMatch = false;
|
||||
matchingMethod = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// No, the number of arguments do not match, not a match
|
||||
else {
|
||||
foundMatch = false;
|
||||
}
|
||||
}
|
||||
// No, it does not return String, not a match.
|
||||
else {
|
||||
foundMatch = false;
|
||||
}
|
||||
}
|
||||
// No, the name does not match, not a match
|
||||
else {
|
||||
foundMatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundMatch) {
|
||||
StringBuilder signature = new StringBuilder();
|
||||
signature.append('(');
|
||||
for (int i = 0; i < numStringArgs; i++) {
|
||||
signature.append("Ljava/lang/String;");
|
||||
}
|
||||
signature.append(")Ljava/lang/String;");
|
||||
result = signature.toString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user