Proxy Generated Java Classes

With release 1.0.10 the Prolog interpreter can generate Java classes from modules. The module must be either a Prolog text loaded from a text source or a dynamic module. A directive allows preparing a module as a Java class. During the preparation step the set of interfaces is collected from the re-exported auto loaded Java classes.

The Java class will be a Java proxy class with an invocation handler. This invocation handler will dispatch method calls to the module. Currently the invocation handler assumes that each method is mapped either to a predicate or an evaluable function which is deterministically called. This might improve in the future. The mapping is done by unpacking the actual Java parameters into Prolog terms, building an appropriate goal, calling the goal via an interactor and packing the result.

When building an appropriate goal, the formal parameter types are ignored. Thus overloaded methods are mapped to the same predicate or evaluable functions. The methods need not have an Interpreter and/or CallOut formal parameter type. The invocation handler will automatically determine the current interpreter form the current thread and use this interpreter to obtain the interactor.

Table 3: Generated Prolog Names
Knowledge Base Class Member Prolog Name

Method Method <Method Name>
Evaluable Function

Function Method <Method Name>

The only information from the method signature that is used is the fact whether the method is static or not and the fact whether the method is a function or not. Non-static methods will have an additional first parameter the goal for the current Java proxy class instance. Function methods will have an additional last Prolog variable parameter in the goal for the result of the method invocation.

Since we use the Java bundled Proxy facility the handler will only deal with methods from the given set of interfaces that the module has re-exported. This might improve in the future. The Java proxy class will exist parallel to the proxy marked module. As a result the members of the module can be still invoked by the (:)/2 Prolog operator. The invocation handler only comes into play when a Java proxy class instance is invoked.