Interface MethodRegistry
-
- All Known Implementing Classes:
BasicMethodRegistry
public interface MethodRegistryKeep a registry of methods. The Java methods (either class or object method) can be called from interpreted script. The problem is that Java methods can be overloaded and BASIC functions can not. To overcome this issue the BASIC program has to declare a function name for each method it wants to call. For example:
method sin from java.lang.Math is (double) use as sinus
Here the method
sinis to be used from the java packagejava.lang.Mathand the alias issinus. Theuse as sinuspart is optional. If this is missing then the name of the method will be used as the name of the BASIC function and no alias is used. If this part is defined then the alias will be used as the name of the function.If there are two methods of the same name, with different signature, you have to define different aliases for the different methods.
You can use the same alias for different methods in different packages. This can be done because the class name or alias for the class name or the variable holding the Java object reference stands in front of the method name/alias when the registered method is called. This distinguishes the different methods of different class even if the aliases or the method names are the same.
Also note that you can also use aliases for Class names defined in the statement
The registry keeps track of theuse.- name of the method,
- the alias,
- the class and
- the signature.
Thus whenever there is a function call in BASIC to call a Java method in a certain class this registry will know which signature to use for the certain alias.
Aliases can be global or class specific. When an alias is defined for a single method then the alias can be used without the class specification. This appears in the BASIC code as a simple function call. When a method is registered in the MethodRegistry it is registered in the normal registry as well as in the global registry. When registering a method in the global registry the implementation checks if there is already a method registered with that alias. If there is then the alias is not global, can not be used without an object or class reference and it is removed from the global registry.- Author:
- Peter Verhas date June 28, 2012
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.reflect.MethodgetJavaMethod(java.lang.Class<?> klass, java.lang.String alias)Get the method for a given alias used to name a method in a specific Java class.voidregisterJavaMethod(java.lang.String alias, java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>[] argumentTypes)Register a java method.
-
-
-
Method Detail
-
getJavaMethod
java.lang.reflect.Method getJavaMethod(java.lang.Class<?> klass, java.lang.String alias)Get the method for a given alias used to name a method in a specific Java class.- Parameters:
klass- the class where the method is. If this parameter isnullthen the class will be fetched from the global registry of methods.alias- the alias with which the method was registered for a specific signature.- Returns:
- the located method that match the name and the signature what was registered.
-
registerJavaMethod
void registerJavaMethod(java.lang.String alias, java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>[] argumentTypes) throws BasicRuntimeExceptionRegister a java method.- Parameters:
alias- the alias of the method. This is the name how the BASIC program will refer to the method. Although the BASIC source code makes it optional to provide an alias it is not optional here. It may be same as the string contained in the parametermethodNamebut it should be passed here and should not benullklass- the class in which the method is implemented.methodName- the Java name of the method.argumentTypes- the argument classes that form the signature of the method together with the name and class of the method.- Throws:
BasicRuntimeException- is thrown if the registration of the alias is not unique in the actual interpreter. You can not register a name for a method and then later the same alias for a different method.
-
-