Module proxy

This module provides predicates to automatically turn a Prolog text into a Java class. The Java class will be a Java proxy class generated for a set of interfaces. The set of interfaces is collected from the re-exported auto loaded Java classes of the given Prolog text. The Java proxy class is generated when an instance of the Java proxy class is requested by the predi-cate sys_new_instance/2:

:- module(mycomparator, []).
:- reexport(foreign(java/util/'Comparator')).

:- public new/1.
new(X) :- sys_new_instance(mycomparator, X). % define the constructor

:- override compare/4.
:- public compare/4.
compare(_, X, Y, R) :- ... % define the method

The predicate and evaluable functions of the Prolog text will be used for the execution of the methods on the Java proxy instance. Only methods that belong to the set of interfaces can be invoked directly from Java on the Java proxy instances. If the set of interfaces contains the Java interface InterfaceSlots the proxy instances should be created with the predicate sys_new_instance/3 instead of the predicate sys_new_instance/2.

?- sys_subclass_of(java/util/'Comparator', mycomparator).

?- mycomparator:new(X), sys_instance_of(X, java/util/'Comparator').
X = 0r709d5f9e

?- mycomparator:new(X), X::compare(7,7,Y).
X = 0r43dd69,
Y = 0

The re-export chain of Prolog modules and auto loaded Java classes defines a module tax-onomy. The module taxonomy can be tested by the predicate sys_assignable_from/2, which checks whether one module is derived from another module. Further Java Prolog proxy in-stances, instances directly created from within Java and Prolog callables can be tested with the predicate sys_instance_of/2.

The following proxy predicates are provided:

sys_new_instance(M, R):
The predicate succeeds for a stateless instance R of the Java proxy class for the Prolog module M.
sys_new_instance(M, S, R):
The predicate succeeds for a state-full instance R of size S of the Java proxy class for the Prolog module M.
sys_assignable_from(N, M):
The predicate succeeds when M is a subclass of N. N and M can be either class references or module names.
sys_instance_of(O, N):
The predicate succeeds when O is an instance of N. O can be a reference or term. N can be either a class reference or a module name.