Jess Interactions Functions

List of functions for interacting with Java code.


8.27. (call (<external-address> | <string-expression>) <string-expression> <call-arguments>+)

Package:
ReflectFunctions
Arguments:
an external address or String, a String, and any number of additional arguments
Returns:
(Varies)
Description:
Calls a Java method on the given object, or a static method of the class named by the first argument. The second argument is the name of the method, and subsequent arguments are passed to the method. Arguments are promoted and overloaded methods selected precisely as for new. The return value is converted to a suitable Jess value before being returned. Array return values are converted to multifields.

The functor call may be omitted if the method being called is non-static and the object is represented by a simple variable. The following two method calls are equivalent:

        
        ;; These are legal and equivalent
        (call ?vector addElement (new java.lang.String "Foo"))
        (?vector addElement (new java.lang.String "Foo"))
call may not be omitted if the object comes from the return value of another function call:
        ;; This is illegal
        ((new java.lang.Vector 10) addElement (new java.lang.String "Foo"))

8.33. (context)

Package:
ReflectFunctions
Arguments:
None
Returns:
External address
Description:
Returns the execution context (a jess.Context object) it is called in. This provides a way for deffunctions to get a handle to this useful class.

8.37. (defclass <tag> <Java class name> [extends <tag>])

Package:
ReflectFunctions
Arguments:
Two or four atoms, as noted above
Returns:
The second argument
Description:
Defines a deftemplate with the given tag, with slots based on the Java Beans properties found in the named class. If the optional extends clause is included, the second tag will become the parent template of the new template. The common slots in the two templates will be in the same order, at the beginning of the new template. Rules defined to match instances of the parent template will also match instances of the new child template.

8.38. (definstance <tag> <Java object> [static | dynamic] )

Package:
ReflectFunctions
Arguments:
An atom, a Java object, and (optionally) one of the atoms static or dynamic.
Returns:
The fact-id of the new shadow fact.
Description:
Creates a "shadow fact" representing the given Java object, according to the named deftemplate (which should have come from defclass.) If the atom static is not supplied as the optional third argument, a PropertyChangeListener is installed in the given object, so that Jess can keep the shadow fact updated if the object's properties change.

Note that it is an error for a given Java object to be installed in more than one definstance at a time. The second and subsequent definstance calls for a given object will return a fact-id with value -1.

8.62. (get <external-address> <string-expression>)

Package:
ReflectFunctions
Arguments:
An external address and a string.
Returns:
(Varies)
Description:
Retrieves the value of a Java Bean's property. The first argument is the object and the second argument is the name of the property. The return value is converted to a suitable Jess value exactly as for call.

8.63. (get-member (<external-address> | <string-expression>) <string-expression>)

Package:
reflect,ReflectFunctions
Arguments:
An external address or a string, and a string.
Returns:
(Varies)
Description:
Retrieves the value of a Java object's data member. The first argument is the object (or the name of a class, for a static member) and the second argument is the name of the field. The return value is converted to a suitable Jess value exactly as for call.

8.70. (import <atom>)

Package:
ReflectFunctions
Arguments:
One atom
Returns:
TRUE
Description:
Works like the Java import statement. You can import either a whole package using
     (import java.io.*)
or a single class using
     (import java.awt.Button)
After that, all functions that can accept a Java class name (new, defclass, call, etc) will refer to the import list to try to find the class that goes with a specific name. Note that java.lang.* is now implicitly imported.

8.81. (load-function <class-name>)

Package:
MiscFunctions
Arguments:
One string or atom representing the name of a Java class
Returns:
Boolean
Description:
The argument must be the fully-qualified name of a Java class that implements the Userfunction interface. The class is loaded in to Jess and added to the engine, thus making the corresponding command available. See Extending Jess with Java for more information.

8.82. (load-package <class-name>)

Package:
MiscFunctions
Arguments:
One string or atom, the name of a Java class
Returns:
Boolean
Description:
The argument must be the fully-qualified name of a Java class that implements the Userpackage interface. The class is loaded in to Jess and added to the engine, thus making the corresponding package of commands available. See Extending Jess with Java for more information.

8.96. (new <string-expression> <new-arguments>+)

Package:
ReflectFunctions
Arguments:
A string and one or more arguments
Returns:
Boolean
Description:
Creates a new Java object and returns an EXTERNAL_ADDRESS value containing it. The first argument is the fully-qualified class name: java.util.Vector, for example. The second and later arguments are constructor arguments. The constructor will be chosen from among all constuctors for the named class based on a first-best fit algorithm. Built-in Jess types are converted as necessary to match available constructors. See the text for more details.

8.125. (set <external-address> <string-expression> <expression>)

Package:
ReflectFunctions
Arguments:
An external address, a string, and an expression
Returns:
The last argument
Description:
Sets a Java Bean's property to the given value. The first argument is the Bean object; the second argument is the name of the property. The third value is the new value for the property; the same conversions are applied as for new and call.

8.127. (set-member (<external-address> | <string-expression>) <string> <expression>+)

Package:
ReflectFunctions
Arguments:
An external address or a string, a string, and one or more expressions
Returns:
The last argument
Description:
Sets a Java object's member variable to the given value. The first argument is the object (or the name of the class, in the case of a static member variable). The second argument is the name of the variable. The third value is the new value for the variable; the same conversions are applied as for new and call.

8.151. (throw <java-object>)

Package:
Intrinsics
Arguments:
A Java object that must inherit from java.lang.Throwable
Returns:
Does not return
Description:
Throws the given exception object. If the object is a JessException, throws it directly. If the object is some other type of exception, it is wrapped in a JessException before throwing. The object's stack trace is filled in such that the exception will appear to have been created by the throw function.

8.153. (try <expression>* [catch <expression>*] [finally <expression>*])

Package:
Intrinsics
Arguments:
One or more expressions, followed optionally by the atom catch followed by zero or more expressions, followed optionally by the atom finally followed by zero or more expressions. Either the catch, or the finally, or both must be included.
Returns:
(Varies)
Description:
This command works something like Java try with a few simplifications. The biggest difference is that the catch clause can specify neither a type of exception nor a variable to receive the exception object. All exceptions occurring in a try block are routed to the single catch block. The variable ?ERROR is made to point to the exception object as an EXTERNAL_ADDRESS. For example:
    (try
      (open NoSuchFile.txt r)
     catch
      (printout t (call ?ERROR toString) crlf))
prints
   Rete Exception in routine _open::call.
     Message: I/O Exception java.io.FileNotFoundException: NoSuchFile.txt.

An empty catch block is fine. It just signifies ignoring possible errors.

The code in the finally block, if present, is executed after all try and/or catch code has executed, immediately before the try function returns.

8.155. (undefinstance (<java-object> | * ))

Package:
ReflectFunctions
Arguments:
A Javaobject, or the atom *
Returns:
TRUE
Description:
If the object currently has a shadow fact, it is removed from the knowledge base. Furthermore, if the object has a PropertyChangeListener installed, this is removed as well. If the argument is "*" this is done for all definstances.