alice.tuprolog.lib
Class JavaLibrary

java.lang.Object
  extended byalice.tuprolog.Library
      extended byalice.tuprolog.lib.JavaLibrary
All Implemented Interfaces:
java.io.Serializable

public class JavaLibrary
extends Library

This class represents a tuProlog library enabling the interaction with the Java environment from tuProlog. Works only with JDK 1.2 (because of setAccessible method) The most specific method algorithm used to find constructors / methods has been inspired by the article "What Is Interactive Scripting?", by Michael Travers Dr. Dobb's -- Software Tools for the Professional Programmer January 2000 CMP Media Inc., a United News and Media Company Library/Theory Dependency: BasicLibrary

See Also:
Serialized Form

Constructor Summary
JavaLibrary()
           
 
Method Summary
 boolean destroy_object_1(Term id)
          Destroy the link to a java object - called not directly, but from predicate java_object (as second choice, for backtracking)
 void dismiss()
          method invoked by prolog engine when library is going to be removed
 void dismissAll()
           
 java.lang.Object getRegisteredDynamicObject(Struct id)
          Gets a registered dynamic object (returns null if not presents)
 java.lang.Object getRegisteredObject(Struct id)
          Gets the reference to an object previously registered
 java.lang.String getTheory()
          library theory
 boolean java_array_get_primitive_3(Struct objId, Number index, Term what)
           
 boolean java_array_set_primitive_3(Struct objId, Number index, Term what)
           
 boolean java_call_3(Term objId, Struct method, Term idResult)
          Calls a method of a Java object
 boolean java_class_4(Struct classSource, Struct className, Struct classPathes, Term id)
          Creates of a java class
 boolean java_object_3(Term className, Struct arg, Term id)
          Creates of a java object - not backtrackable case
 void onSolveBegin(Term goal)
          method invoked when the engine is going to demonstrate a goal
 void onSolveEnd()
          method invoked when the engine has finished a demostration
 Struct register(java.lang.Object obj)
          Registers an object, with automatic creation of the identifier.
 boolean register(Struct id, java.lang.Object obj)
          Register an object with the specified id.
 Struct registerDynamic(java.lang.Object obj)
          Registers an object for the query life-time, with the automatic generation of the identifier.
 void registerDynamic(Struct id, java.lang.Object obj)
          Registers an object only for the running query life-time
 boolean unregister(Struct id)
          Unregisters an object, given its identifier
 boolean unregisterDynamic(Struct id)
          Unregister the object, only for dynamic case
 
Methods inherited from class alice.tuprolog.Library
getEngine, getFunctors, getLinkedMethod, getName, getOperatorSynonymMap, getPredicates
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaLibrary

public JavaLibrary()
Method Detail

getTheory

public java.lang.String getTheory()
library theory

Overrides:
getTheory in class Library

dismiss

public void dismiss()
Description copied from class: Library
method invoked by prolog engine when library is going to be removed

Overrides:
dismiss in class Library

dismissAll

public void dismissAll()

onSolveBegin

public void onSolveBegin(Term goal)
Description copied from class: Library
method invoked when the engine is going to demonstrate a goal

Overrides:
onSolveBegin in class Library

onSolveEnd

public void onSolveEnd()
Description copied from class: Library
method invoked when the engine has finished a demostration

Overrides:
onSolveEnd in class Library

java_object_3

public boolean java_object_3(Term className,
                             Struct arg,
                             Term id)
Creates of a java object - not backtrackable case


destroy_object_1

public boolean destroy_object_1(Term id)
Destroy the link to a java object - called not directly, but from predicate java_object (as second choice, for backtracking)


java_class_4

public boolean java_class_4(Struct classSource,
                            Struct className,
                            Struct classPathes,
                            Term id)
Creates of a java class


java_call_3

public boolean java_call_3(Term objId,
                           Struct method,
                           Term idResult)
Calls a method of a Java object


java_array_set_primitive_3

public boolean java_array_set_primitive_3(Struct objId,
                                          Number index,
                                          Term what)

java_array_get_primitive_3

public boolean java_array_get_primitive_3(Struct objId,
                                          Number index,
                                          Term what)

register

public boolean register(Struct id,
                        java.lang.Object obj)
                 throws InvalidObjectIdException
Register an object with the specified id. The life-time of the link to the object is engine life-time, available besides the individual query. The identifier must be a ground object.

Parameters:
id - object identifier
obj - the object
Returns:
true if the operation is successful
Throws:
InvalidObjectIdException - if the object id is not valid

register

public Struct register(java.lang.Object obj)
Registers an object, with automatic creation of the identifier. If the object is already registered, its identifier is returned

Parameters:
obj - object to be registered.
Returns:
fresh id

getRegisteredObject

public java.lang.Object getRegisteredObject(Struct id)
                                     throws InvalidObjectIdException
Gets the reference to an object previously registered

Parameters:
id - object id
Returns:
the object, if present
Throws:
InvalidObjectIdException

unregister

public boolean unregister(Struct id)
                   throws InvalidObjectIdException
Unregisters an object, given its identifier

Parameters:
id - object identifier
Returns:
true if the operation is successful
Throws:
InvalidObjectIdException - if the id is not valid (e.g. is not ground)

registerDynamic

public void registerDynamic(Struct id,
                            java.lang.Object obj)
Registers an object only for the running query life-time

Parameters:
id - object identifier
obj - object

registerDynamic

public Struct registerDynamic(java.lang.Object obj)
Registers an object for the query life-time, with the automatic generation of the identifier. If the object is already registered, its identifier is returned

Parameters:
obj - object to be registered
Returns:
identifier

getRegisteredDynamicObject

public java.lang.Object getRegisteredDynamicObject(Struct id)
                                            throws InvalidObjectIdException
Gets a registered dynamic object (returns null if not presents)

Throws:
InvalidObjectIdException

unregisterDynamic

public boolean unregisterDynamic(Struct id)
Unregister the object, only for dynamic case

Parameters:
id - object identifier
Returns:
true if the operation is successful


DEIS, Universita' di Bologna, Sede di Cesena