| Did you know ... | Search Documentation: |
| jpl.pl -- A Java interface for SWI Prolog 7.x |
The library(jpl) provides a bidirectional interface to a Java Virtual Machine.
jpl_new(+X, +Params, -V) is det'java.lang.String''[I' or 'Ljava.lang.String;'class(_,_) or array(_), e.g. class([java,util],['Date'])If X is an object (non-array) type or descriptor and Params is a list of values or references, then V is the result of an invocation of that type's most specifically-typed constructor to whose respective formal parameters the actual Params are assignable (and assigned).
If X is an array type or descriptor and Params is a list of values or references, each of which is (independently) assignable to the array element type, then V is a new array of as many elements as Params has members, initialised with the respective members of Params.
If X is an array type or descriptor and Params is a non-negative integer N, then V is a new array of that type, with N elements, each initialised to Java's appropriate default value for the type.
If V is literally {Term} then we attempt to convert a
new org.jpl7.Term instance to
a corresponding term; this is of little obvious use here, but is
consistent with jpl_call/4 and jpl_get/3.
jpl_new_1(+Tx, +Params, -Vx)[private]
Tx can be a class(_,_) or array(_) type.
Params must be a proper list of constructor parameters.
At exit, Vx is bound to a JPL reference to a new, initialised instance of Tx
jpl_new_array(+ElementType, +Length, -NewArray) is det[private]
jpl_call(+X, +MethodName:atom, +Params:list(datum), -Result:datum) is det<jref>(1552320) (for static or instance methods)'java.util.Date' (for static methods only)'Ljava.util.Date;' (for static methods only)class([java,util],['Date']) (for static methods only)MethodName should be a method name (as an atom) (may involve dynamic overload resolution based on inferred types of params)
Params should be a proper list (perhaps empty) of suitable actual parameters for the named method.
The class or object may have several methods with the given name; JPL will resolve (per call) to the most appropriate method based on the quantity and inferred types of Params. This resolution mimics the corresponding static resolution performed by Java compilers.
Finally, an attempt will be made to unify Result with the method's returned value,
or with @(void) (the compound term with name @ and argument void) if it has none.
jpl_call_instance(+ObjectType, +Object, +MethodName, +Params, +ActualParamTypes, +Arity, -Result)[private]
jpl_call_static(+ClassType, +ClassObject, +MethodName, +Params, +ActualParamTypes, +Arity, -Result)[private]
jpl_call_instance_method(+Type, +ClassObject, +MethodID, +FormalParamTypes, +Params, -Result)[private]
jpl_call_static_method(+Type, +ClassObject, +MethodID, +FormalParamTypes, +Params, -Result)[private]
jpl_get(+X, +Fspec, -V:datum) is detFspec can be
Finally, an attempt will be made to unify V with the retrieved value or object reference.
Examples
jpl_get('java.awt.Cursor', 'NE_RESIZE_CURSOR', Q).
Q = 7.
jpl_new(array(class([java,lang],['String'])), [for,while,do,if,then,else,try,catch,finally], A),
jpl_get(A, 3-5, B).
B = [if, then, else].
jpl_get_static(+Type:type, +ClassObject:jref, +FieldName:atom, -Value:datum) is det[private]
jpl_get_instance(+Type, +Type, +Object, +FieldSpecifier, -Value) is det[private]
jpl_get_array_element(+ElementType:type, +Array:jref, +Index, -Vc) is det[private]
jpl_get_array_elements(+ElementType, +Array, +N, +M, -Vs)[private]Vs will always be unbound on entry
jpl_get_object_array_elements(+Array, +LoIndex, +HiIndex, -Vcs) is det[private]length(Array); HiIndex is an integer, LoIndex-1 =< HiIndex <
length(Array); at call, Vcs will be unbound; at exit, Vcs will be a
list of (references to) the array's elements [LoIndex..HiIndex]
inclusive
jpl_get_primitive_array_elements(+ElementType, +Array, +LoIndex, +HiIndex, -Vcs) is det[private]
jpl_set(+X, +Fspec, +V) is detX can be
class(_,_) or array(_) type (for static fields)Fspec can be
V must be a suitable value or object.
jpl_set_instance(+Type, +Type, +ObjectReference, +FieldName, +Value) is det[private]FieldName should name a public, non-final (static or non-static) field of this object, but could be anything, and is validated here;
Value should be assignable to the named field, but could be anything, and is validated here
jpl_set_static(+Type, +ClassObj, +FieldName, +Value) is det[private]NB this does not yet handle shadowed fields correctly.
jpl_set_array(+ElementType, +Array, +Offset, +DatumQty, +Datums) is det[private]error(type_error(acyclic,_),context(jpl_datum_to_type/2,_))
jpl_set_array_1(+Values, +Type, +BufferIndex, +BufferPointer) is det[private]NB this could be done more efficiently (?) within foreign code...
jpl_set_instance_field(+Type, +Obj, +FieldID, +V) is det[private]
jpl_set_static_field(+Type, +ClassObj, +FieldID, +V)[private]
jpl_get_default_jvm_opts(-Opts:list(atom)) is det['-Xrs']
jpl_set_default_jvm_opts(+Opts:list(atom)) is det
jpl_get_actual_jvm_opts(-Opts:list(atom)) is semidetFails silently if a JVM has not yet been started, and can thus be used to test for this.
jpl_classname_type_cache(-Classname:className, -Type:type)[private]NB may denote a class which cannot be found.
jpl_class_tag_type_cache(-Class:jref, -Type:jpl_type)[private]java.lang.Class
which denotes Type.
We index on Class (a jref) so as to keep these objects around even after an atom garbage collection (if needed once, they are likely to be needed again)
(Is it possble to have different Ref for the same ClassType, which happens once several ClassLoaders become involved?) (Most likely)
jpl_assert(+Fact:term)[private]From the SWI-Prolog manual:
"In SWI-Prolog, querying dynamic predicates has the same performance as static ones. The manipulation predicates are fast."
And:
"By default, a predicate declared dynamic (see dynamic/1) is shared by all threads. Each thread may assert, retract and run the dynamic predicate. Synchronisation inside Prolog guarantees the consistency of the predicate. Updates are logical: visible clauses are not affected by assert/retract after a query started on the predicate. In many cases primitives from section 10.4 should be used to ensure that application invariants on the predicate are maintained.
jpl_tidy_iref_type_cache(+Iref) is det[private]
Called from jpl.c's jni_free_iref() via jni_tidy_iref_type_cache()
jpl_fergus_is_the_greatest(+Xs:list(T), -GreatestX:T)[private]
jpl_z3s_to_most_specific_z3(+Zs, -Z)[private]z3(I,MID,Tfps).
Z is the single most specific element of Zs, i.e. that than which no other z3/3 has a more specialised signature (fails if there is more than one such).
jpl_z5s_to_most_specific_z5(+Zs, -Z)[private]z5(I,Mods,MID,Tr,Tfps)
Z is the single most specific element of Zs, i.e. that than which no other z5/5 has a more specialised signature (fails if there is more than one such)
jpl_pl_lib_version(-Version)It should exactly match the version identifiers of JPL's C (jpl.c) and Java (jpl.jar) components.
Example
?- jpl_pl_lib_version(V). V = '7.6.1'.
jpl_pl_lib_version(-Major, -Minor, -Patch, -Status)[private]Example
?- jpl:jpl_pl_lib_version(Major, Minor, Patch, Status). Major = 7, Minor = 4, Patch = 0, Status = alpha.
jpl_c_lib_version(-Version)It should exactly match the version identifiers of JPL's Prolog (jpl.pl) and Java (jpl.jar) components.
Example
?- jpl_c_lib_version(V). V = '7.4.0-alpha'.
jpl_java_lib_version(-Version)[private]Example
?- jpl:jpl_java_lib_version(V). V = '7.4.0-alpha'.
jpl_java_lib_version(V)[private]
jpl_pl_lib_path(-Path:atom)[private]
jpl_c_lib_path(-Path:atom)[private]
jpl_java_lib_path(-Path:atom)[private]
jCallBooleanMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rbool:boolean)[private]
jCallByteMethod(+Obj:jref, +MethodID:methodId, +Types, +Params:list(datum), -Rbyte:byte)[private]
jCallCharMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rchar:char)[private]
jCallDoubleMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rdouble:double)[private]
jCallFloatMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rfloat:float)[private]
jCallIntMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rint:int)[private]
jCallLongMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rlong:long)[private]
jCallObjectMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Robj:jref)[private]
jCallShortMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rshort:short)[private]
jCallStaticBooleanMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rbool:boolean)[private]
jCallStaticByteMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rbyte:byte)[private]
jCallStaticCharMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rchar:char)[private]
jCallStaticDoubleMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rdouble:double)[private]
jCallStaticFloatMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rfloat:float)[private]
jCallStaticIntMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rint:int)[private]
jCallStaticLongMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rlong:long)[private]
jCallStaticObjectMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Robj:jref)[private]
jCallStaticShortMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Rshort:short)[private]
jCallStaticVoidMethod(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum))[private]
jCallVoidMethod(+Obj:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum))[private]
jFindClass(+ClassName:findclassname, -Class:jref)[private]
jGetArrayLength(+Array:jref, -Size:int)[private]
jGetBooleanArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:boolean_buf)[private]
jGetBooleanField(+Obj:jref, +FieldID:fieldId, -Rbool:boolean)[private]
jGetByteArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:byte_buf)[private]
jGetByteField(+Obj:jref, +FieldID:fieldId, -Rbyte:byte)[private]
jGetCharArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:char_buf)[private]
jGetCharField(+Obj:jref, +FieldID:fieldId, -Rchar:char)[private]
jGetDoubleArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:double_buf)[private]
jGetDoubleField(+Obj:jref, +FieldID:fieldId, -Rdouble:double)[private]
jGetFieldID(+Class:jref, +Name:fieldName, +Type:type, -FieldID:fieldId)[private]
jGetFloatArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:float_buf)[private]
jGetFloatField(+Obj:jref, +FieldID:fieldId, -Rfloat:float)[private]
jGetIntArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:int_buf)[private]
jGetIntField(+Obj:jref, +FieldID:fieldId, -Rint:int)[private]
jGetLongArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:long_buf)[private]
jGetLongField(+Obj:jref, +FieldID:fieldId, -Rlong:long)[private]
jGetMethodID(+Class:jref, +Name:atom, +Type:type, -MethodID:methodId)[private]
jGetObjectArrayElement(+Array:jref, +Index:int, -Obj:jref)[private]
jGetObjectClass(+Object:jref, -Class:jref)[private]
jGetObjectField(+Obj:jref, +FieldID:fieldId, -RObj:jref)[private]
jGetShortArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:short_buf)[private]
jGetShortField(+Obj:jref, +FieldID:fieldId, -Rshort:short)[private]
jGetStaticBooleanField(+Class:jref, +FieldID:fieldId, -Rbool:boolean)[private]
jGetStaticByteField(+Class:jref, +FieldID:fieldId, -Rbyte:byte)[private]
jGetStaticCharField(+Class:jref, +FieldID:fieldId, -Rchar:char)[private]
jGetStaticDoubleField(+Class:jref, +FieldID:fieldId, -Rdouble:double)[private]
jGetStaticFieldID(+Class:jref, +Name:fieldName, +Type:type, -FieldID:fieldId)[private]
jGetStaticFloatField(+Class:jref, +FieldID:fieldId, -Rfloat:float)[private]
jGetStaticIntField(+Class:jref, +FieldID:fieldId, -Rint:int)[private]
jGetStaticLongField(+Class:jref, +FieldID:fieldId, -Rlong:long)[private]
jGetStaticMethodID(+Class:jref, +Name:methodName, +Type:type, -MethodID:methodId)[private]
jGetStaticObjectField(+Class:jref, +FieldID:fieldId, -RObj:jref)[private]
jGetStaticShortField(+Class:jref, +FieldID:fieldId, -Rshort:short)[private]
jGetSuperclass(+Class1:jref, -Class2:jref)[private]
jIsAssignableFrom(+Class1:jref, +Class2:jref)[private]
jNewBooleanArray(+Length:int, -Array:jref)[private]
jNewByteArray(+Length:int, -Array:jref)[private]
jNewCharArray(+Length:int, -Array:jref)[private]
jNewDoubleArray(+Length:int, -Array:jref)[private]
jNewFloatArray(+Length:int, -Array:jref)[private]
jNewIntArray(+Length:int, -Array:jref)[private]
jNewLongArray(+Length:int, -Array:jref)[private]
jNewObject(+Class:jref, +MethodID:methodId, +Types:list(type), +Params:list(datum), -Obj:jref)[private]
jNewObjectArray(+Len:int, +Class:jref, +InitVal:jref, -Array:jref)[private]
jNewShortArray(+Length:int, -Array:jref)[private]
jSetBooleanArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:boolean_buf)[private]
jSetBooleanField(+Obj:jref, +FieldID:fieldId, +Rbool:boolean)[private]
jSetByteArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:byte_buf)[private]
jSetByteField(+Obj:jref, +FieldID:fieldId, +Rbyte:byte)[private]
jSetCharArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:char_buf)[private]
jSetCharField(+Obj:jref, +FieldID:fieldId, +Rchar:char)[private]
jSetDoubleArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:double_buf)[private]
jSetDoubleField(+Obj:jref, +FieldID:fieldId, +Rdouble:double)[private]
jSetFloatArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:float_buf)[private]
jSetFloatField(+Obj:jref, +FieldID:fieldId, +Rfloat:float)[private]
jSetIntArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:int_buf)[private]
jSetIntField(+Obj:jref, +FieldID:fieldId, +Rint:int)[private]
jSetLongArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:long_buf)[private]
jSetLongField(+Obj:jref, +FieldID:fieldId, +Rlong:long)[private]
jSetObjectArrayElement(+Array:jref, +Index:int, +Obj:jref)[private]
jSetObjectField(+Obj:jref, +FieldID:fieldId, +RObj:jref)[private]
jSetShortArrayRegion(+Array:jref, +Start:int, +Len:int, +Buf:short_buf)[private]
jSetShortField(+Obj:jref, +FieldID:fieldId, +Rshort:short)[private]
jSetStaticBooleanField(+Class:jref, +FieldID:fieldId, +Rbool:boolean)[private]
jSetStaticByteField(+Class:jref, +FieldID:fieldId, +Rbyte:byte)[private]
jSetStaticCharField(+Class:jref, +FieldID:fieldId, +Rchar:char)[private]
jSetStaticDoubleField(+Class:jref, +FieldID:fieldId, +Rdouble:double)[private]
jSetStaticFloatField(+Class:jref, +FieldID:fieldId, +Rfloat:float)[private]
jSetStaticIntField(+Class:jref, +FieldID:fieldId, +Rint:int)[private]
jSetStaticLongField(+Class:jref, +FieldID:fieldId, +Rlong)[private]
jSetStaticObjectField(+Class:jref, +FieldID:fieldId, +Robj:jref)[private]
jSetStaticShortField(+Class:jref, +FieldID:fieldId, +Rshort:short)[private]
jni_params_put(+Params:list(datum), +Types:list(type), -ParamBuf:paramBuf)[private]
jni_params_put_1(+Params:list(datum), +N:integer, +JPLTypes:list(type), +ParamBuf:paramBuf)[private]Types are their (JPL) types (e.g. 'boolean').
N is the arg and buffer index (0+) at which the head of Params is to be stashed.
The old form used a static buffer and hence was non-reentrant; the new form uses a dynamically allocated buffer (which oughta be freed after use).
NB if the (user-provided) actual params were to be unsuitable for conversion to the method-required types, this would fail silently (without freeing the buffer); it's not clear whether the overloaded-method-resolution ensures that all args are convertible
jni_type_to_xput_code(+JspType, -JniXputCode)[private]NB the codes could be compiled into jni_method_spec_cache etc. instead of, or as well as, types (for - small - efficiency gain)
jpl_class_to_constructor_array(+Class:jref, -MethodArray:jref)[private]
jpl_class_to_constructors(+Class:jref, -Methods:list(jref))[private]
jpl_class_to_field_array(+Class:jref, -FieldArray:jref)[private]
jpl_class_to_fields(+Class:jref, -Fields:list(jref))[private]
jpl_class_to_method_array(+Class:jref, -MethodArray:jref)[private]
jpl_class_to_methods(+Class:jref, -Methods:list(jref))[private]NB do this in Java (ditto for fields)?
jpl_constructor_to_modifiers(+Method, -Modifiers)[private]
jpl_constructor_to_name(+Method:jref, -Name:atom)[private]
jpl_constructor_to_parameter_types(+Method:jref, -ParameterTypes:list(type))[private]
jpl_constructor_to_return_type(+Method:jref, -Type:type)[private]
jpl_field_spec(+Type:type, -Index:integer, -Name:atom, -Modifiers, -MID:mId, -FieldType:type)[private]
jpl_field_to_modifiers(+Field:jref, -Modifiers:ordset(modifier))[private]
jpl_field_to_name(+Field:jref, -Name:atom)[private]
jpl_field_to_type(+Field:jref, -Type:type)[private]
jpl_method_spec(+Type:type, -Index:integer, -Name:atom, -Arity:integer, -Modifiers:ordset(modifier), -MID:methodId, -ReturnType:type, -ParameterTypes:list(type))[private]
jpl_method_spec_1(+Class:jref, +CacheIndexType:partialType, +Constructors:list(method), +Methods:list(method))[private]array(byte) then CacheIndexType is array(_) else it is that type.
jpl_method_to_modifiers(+Method:jref, -ModifierSet:ordset(modifier))[private]
jpl_method_to_modifiers_1(+Method:jref, +ConstructorClass:jref, -ModifierSet:ordset(modifier))[private]
jpl_method_to_name(+Method:jref, -Name:atom)[private]
jpl_member_to_name_1(+Member:jref, +CM:jref, -Name:atom)[private]
jpl_method_to_parameter_types(+Method:jref, -Types:list(type))[private]
jpl_method_to_parameter_types_1(+XM:jref, +Cxm:jref, -Tfps:list(type))[private]
jpl_method_to_return_type(+Method:jref, -Type:type)[private]
jpl_modifier_int_to_modifiers(+Int:integer, -ModifierSet:ordset(modifier))[private]
jpl_cache_type_of_ref(+Type:type, +Ref:jref)[private]Ref must be a proper JPL reference (not void)
Type is memoed (if policy so dictates) as the type of the referenced object (unless it's null) by iref (so as not to disable atom-based GC)
NB obsolete lemmas must be watched-out-for and removed
jpl_class_to_ancestor_classes(+Class:jref, -AncestorClasses:list(jref))[private]
jpl_class_to_classname(+Class:jref, -ClassName:entityName)
ClassName is its canonical (?) source-syntax (dotted) name,
e.g. 'java.util.Date'
NB not used outside jni_junk and jpl_test (is this (still) true?)
NB oughta use the available caches (but their indexing doesn't suit)
TODO This shouldn't exist as we have jpl_class_to_entityname/2 ???
The implementation actually just calls Class.getName() to get
the entity name (dotted name)
jpl_class_to_entityname(+Class:jref, -EntityName:atom)[private]Class.getName().
This predicate actually calls Class.getName() on the class corresponding to Class.
jpl_class_to_type(+Class:jref, -Type:jpl_type)java.lang.Class.
The Type is the (Prolog Universe) JPL type term denoting the same type as does
the instance of Class.
NB should ensure that, if not found in cache, then cache is updated.
Intriguingly, getParameterTypes returns class objects (undocumented AFAIK) with names 'boolean', 'byte' etc. and even 'void' (?!)
jpl_entityname_to_class(+EntityName:atom, -Class:jref)[private]Class is a (canonical) reference to the corresponding class object.
NB uses caches where the class is already encountered.
jpl_classname_to_class(+EntityName:atom, -Class:jref)Class is a (canonical) reference to the corresponding class object.
NB uses caches where the class has already been mapped once before.
jpl_entityname_to_type(+EntityName:atom, -Type:jpl_type)java.lang.Class.getName().
Type is the JPL type (a ground term) denoting the same Java type as EntityName does.
The Java type in question may be a reference type (class, abstract class, interface), and array type or a primitive, including "void".
Examples:
int int integer class([],[integer]) void void char char double double [D array(double) [[I array(array(int)) java.lang.String class([java,lang],['String']) [Ljava.lang.String; array(class([java,lang],['String'])) [[Ljava.lang.String; array(array(class([java, lang], ['String']))) [[[Ljava.util.Calendar; array(array(array(class([java,util],['Calendar'])))) foo.bar.Bling$Blong class([foo,bar],['Bling','Blong'])
NB uses caches where the class has already been mapped once before.
jpl_type_to_entityname(+Type:jpl_type, -EntityName:atom)
jpl_classname_to_type(+EntityName:atom, -Type:jpl_type)Use jpl_entityname_to_type/2 in preference.
jpl_type_to_classname(+Type:jpl_type, -EntityName:atom)Use jpl_type_to_entityname/2 in preference.
jpl_datum_to_type(+Datum:datum, -Type:type)Type is the unique most specialised type of which Datum denotes an instance;
NB 3 is an instance of byte, char, short, int and long, of which byte and char are the joint, overlapping most specialised types, so this relates 3 to the pseudo subtype 'char_byte';
jpl_datums_to_types(+Datums:list(datum), -Types:list(type))[private]
jpl_ground_is_type(+X:jpl_type)[private]A (more complete) alternative would be to try to transfrom the X into its entityname and see whether that works.
jpl_object_array_to_list(+Array:jref, -Values:list(datum))[private]
jpl_object_array_to_list_1(+A, +I, +N, -Xs)[private]
jpl_object_to_class(+Object:jref, -Class:jref)Class is a (canonical) reference to the (canonical) class object which represents the class of Object
NB what's the point of caching the type if we don't look there first?
jpl_object_to_type(+Object:jref, -Type:type)Type is the JPL type of that object.
jpl_primitive_buffer_to_array(+Type, +Xc, +Bp, +I, +Size, -Vcs)[private]Vcs will be unbound on entry, and on exit will be a list of Size of them, starting at index I (the buffer is indexed from zero)
jpl_primitive_type(-Type:atom) is nondetvoid is not included.
?- setof(Type, jpl_primitive_type(Type), Types). Types = [boolean, byte, char, double, float, int, long, short].
jpl_primitive_type_default_value(-Type:type, -Value:datum)[private]
jpl_primitive_type_term_to_value(+Type, +Term, -Val)[private]Val is the instance of Type which it represents (often the same thing).
NB currently used only by jpl_new_1 when creating an "instance" of a primitive type (which may be misguided completism - you can't do that in Java)
jpl_primitive_type_term_to_value_1(+Type, +RawValue, -WidenedValue)[private]NB this oughta be done in foreign code.
jpl_ref_to_type(+Ref:jref, -Type:type)Type is its type.
jpl_tag_to_type(+Tag:tag, -Type:type)[private]Type is its type (either from the cache or by reflection). OBSOLETE
jpl_type_fits_type(+TypeX:type, +TypeY:type) is semidet[private]This succeeds iff TypeX is assignable to TypeY.
jpl_type_fits_type_1(+T1:type, +T2:type)[private]
jpl_type_fits_type_direct_xtra(-PseudoType:type, -ConcreteType:type)[private]char_int, char_short and char_byte
jpl_type_fits_type_xprim(-Tp, -T) is nondet[private]
jpl_type_to_ancestor_types(+T:type, -Tas:list(type))[private]
jpl_type_to_canonical_type(+Type:type, -CanonicalType:type)[private]CanonicalType will be equivalent and canonical.
Example
?- jpl:jpl_type_to_canonical_type(class([],[byte]), T). T = byte.
jpl_type_to_class(+Type:jpl_type, -Class:jref)Incomplete types are now never cached (or otherwise passed around).
jFindClass throws an exception if FCN can't be found.
jpl_type_to_java_field_descriptor(+Type:jpl_type, -Descriptor:atom)[private]
TODO: I'd cache this, but I'd prefer more efficient indexing on types (hashed?)
jpl_type_to_java_method_descriptor(+Type:jpl_type, -Descriptor:atom)[private]
TODO: Caching might be nice (but is it worth it?)
jpl_type_to_java_findclass_descriptor(+Type:jpl_type, -Descriptor:atom)[private]
jpl_type_to_super_type(+Type:type, -SuperType:type)[private]SuperType is the (at most one) type which it directly implements (if it's a class).
If Type denotes a class, this works only if that class can be found.
jpl_type_to_preferred_concrete_type(+Type:type, -ConcreteType:type)[private]char_int or array(char_byte)
ConcreteType is the preferred concrete (Java-instantiable) type.
Example
?- jpl_type_to_preferred_concrete_type(array(char_byte), T). T = array(byte).
NB introduced 16/Apr/2005 to fix bug whereby jpl_list_to_array([1,2,3],A) failed
because the lists's inferred type of array(char_byte) is not Java-instantiable
jpl_types_fit_type(+Types:list(type), +Type:type)[private]Used in dynamic type check when attempting to e.g. assign list of values to array.
jpl_types_fit_types(+Types1:list(type), +Types2:list(type))[private]
jpl_value_to_type(+Value:datum, -Type:type)[private]
Type is its unique most specific type,
which may be one of the pseudo types char_byte, char_short or char_int.
jpl_value_to_type_1(+Value:datum, -Type:type) is semidet[private]Called solely by jpl_value_to_type/2, which commits to first solution.
NB some integer values are of JPL-peculiar uniquely most specific subtypes, i.e. char_byte, char_short, char_int but all are understood by JPL's internal utilities which call this proc.
NB we regard float as subtype of double.
NB objects and refs always have straightforward types.
jpl_is_class(@Term)java.lang.Class.
jpl_is_false(@Term)@(false), the JPL representation of the Java boolean value 'false'.
jpl_is_fieldID(-X)[private]NB JPL internal use only.
NB applications should not be messing with these.
NB a var arg may get bound.
jpl_is_methodID(-X)[private]NB JPL internal use only.
NB applications should not be messing with these.
NB a var arg may get bound.
jpl_is_null(@Term)@(null), the JPL representation of Java's 'null' reference.
jpl_is_object(@Term)NB this checks only syntax, not whether the object exists.
jpl_is_object_type(@Term)
jpl_is_ref(@Term)
jpl_is_true(@Term)@(true), the JPL representation of the Java
boolean value 'true'.
jpl_is_type(@Term)
jpl_is_void(@Term)@(void), the JPL representation of the pseudo
Java value 'void' (which is returned by jpl_call/4 when invoked on
void methods).
NB you can try passing 'void' back to Java, but it won't ever be interested.
jpl_false(-X:datum) is semidet@(false), the JPL representation of the Java boolean value
'false'.
jpl_null(-X:datum) is semidet@(null), the JPL representation of Java's 'null' reference.
jpl_true(-X:datum) is semidet@(true), the JPL representation of the Java boolean value
'true'.
jpl_void(-X:datum) is semidet@(void), the JPL representation of the pseudo Java value
'void'.
jpl_array_to_length(+Array:jref, -Length:integer)Length is the length of that array. This is a utility predicate, defined thus:
jpl_array_to_length(A, N) :-
( jpl_ref_to_type(A, array(_))
-> jGetArrayLength(A, N)
).
jpl_array_to_list(+Array:jref, -Elements:list(datum))Elements is a Prolog list of JPL representations of the array's elements (values or references, as appropriate). This is a utility predicate, defined thus:
jpl_array_to_list(A, Es) :-
jpl_array_to_length(A, Len),
( Len > 0
-> LoBound is 0,
HiBound is Len-1,
jpl_get(A, LoBound-HiBound, Es)
; Es = []
).
jpl_datums_to_array(+Datums:list(datum), -A:jref)NB this fails silently if
jpl_enumeration_element(+Enumeration:jref, -Element:datum)
jpl_enumeration_to_list(+Enumeration:jref, -Elements:list(datum))Enumeration interface.
Elements is a Prolog list of JPL references to the enumerated objects. This is a utility predicate, defined thus:
jpl_enumeration_to_list(Enumeration, Es) :-
( jpl_call(Enumeration, hasMoreElements, [], @(true))
-> jpl_call(Enumeration, nextElement, [], E),
Es = [E|Es1],
jpl_enumeration_to_list(Enumeration, Es1)
; Es = []
).
jpl_hashtable_pair(+HashTable:jref, -KeyValuePair:pair(datum,datum)) is nondetNB String is converted to atom but Integer is presumably returned as an object ref (i.e. as elsewhere, no auto unboxing);
NB this is anachronistic: the Map interface is preferred.
jpl_iterator_element(+Iterator:jref, -Element:datum)java.util.Iterator interface.
Element is the JPL representation of the next element in the iteration. This is a utility predicate, defined thus:
jpl_iterator_element(I, E) :-
( jpl_call(I, hasNext, [], @(true))
-> ( jpl_call(I, next, [], E)
; jpl_iterator_element(I, E)
)
).
jpl_list_to_array(+Datums:list(datum), -Array:jref)If Datums have a most specific common supertype, then Array is a JPL reference to a new Java array, whose base type is that common supertype, and whose respective elements are the Java values or objects represented by Datums.
jpl_terms_to_array(+Terms:list(term), -Array:jref) is semidet
Array is a JPL reference to a new Java array of org.jpl7.Term,
whose elements represent the respective members of the list.
jpl_array_to_terms(+JRef:jref, -Terms:list(term))
jpl_map_element(+Map:jref, -KeyValue:pair(datum,datum)) is nondetjava.util.Map interface
This generates each Key-Value pair from the Map, e.g.
?- jpl_call('java.lang.System', getProperties, [], Map), jpl_map_element(Map, E).
Map = @<jref>(0x20b5c38),
E = 'java.runtime.name'-'Java(TM) SE Runtime Environment' ;
Map = @<jref>(0x20b5c38),
E = 'sun.boot.library.path'-'C:\\Program Files\\Java\\jre7\\bin'
etc.
This is a utility predicate, defined thus:
jpl_map_element(Map, K-V) :-
jpl_call(Map, entrySet, [], ES),
jpl_set_element(ES, E),
jpl_call(E, getKey, [], K),
jpl_call(E, getValue, [], V).
jpl_set_element(+Set:jref, -Element:datum) is nondetjava.util.Set interface.
On backtracking, Element is bound to a JPL representation of each element of Set. This is a utility predicate, defined thus:
jpl_set_element(S, E) :-
jpl_call(S, iterator, [], I),
jpl_iterator_element(I, E).
jpl_servlet_byref(+Config, +Request, +Response)
jpl_servlet_byval(+MultiMap, -ContentType:atom, -Body:atom)
is_pair(?T:term)[private]
to_atom(+Term, -Atom)[private]
jpl_pl_syntax(-Syntax:atom)
add_search_path(+Var, +Value) is det[private]
check_java_environment[private]execv() yourself, but
this doesn't work if we want to load Java on demand or if Prolog
itself is embedded in another application.
So, after reading lots of pages on the web, I decided checking the environment and producing a sensible error message is the best we can do.
Please not that Java2 doesn't require $CLASSPATH to be set, so we do not check for that.
check_shared_object(+Lib, -File, -EnvVar, -AbsFile) is semidet[private]
library_search_path(-Dirs:list, -EnvVar) is det[private]
add_jpl_to_classpath[private]CLASSPATH to facilitate callbacks. If jpl.jar is
already in CLASSPATH, do nothing. Note that this may result in the
user picking up a different version of jpl.jar. We'll assume the
user is right in this case.
libjpl(-Spec) is det[private]loadLibrary()
call used by jpl.jar adds the lib* prefix.
In Windows we should not use foreign(jpl) as this eventually
calls LoadLibrary() with an absolute path, disabling the Windows DLL
search process for the dependent jvm.dll and possibly other Java
dll dependencies.
add_jpl_to_ldpath(+JPL) is det[private]
add_java_to_ldpath is det[private]LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on MacOS) only
once.
extend_dll_search_path(+Dir)[private]
extend_java_library_path(+OsDir)[private]-Djava.library.path init
options.
java_dirs// is det[private]
java_home(-Home) is semidet[private]