V:4.1.5/Karajan:Java Library
Files: java.k, java.xml
The Java library allows limited interfacing with Java classes and objects from Karajan.
Contents |
Java Elements
java:new
java:new(classname, *types, ...)
Instantiates a new Java object and returns it. Classname represents the fully qualified name of the class. The *types argument is a list of fully qualified class names used to search for a constructor. The arguments on the default channel are passed to the constructor after performing a conversion based on the *types argument. The *types argument is not always necessary, but should be used if Karajan cannot determine the types of the arguments that need to be passed to the constructor.
set(xnew("java.lang.Double", "1.0") /* The types argument is not necessary since * the string argument is automatically mapped * to java.lang.String */ )set(jnew("java.lang.Integer", types = ["int"], 1) /* The types argument is required since the numeric * type used by Karajan cannot be mapped automatically * to a specific Java numeric type. */ )
Primitive Java types are represented by their corresponding keywords: boolean, byte, char, int, long, float, and double.
java:invokeMethod
java:invokeMethod(method, *static, *classname, *object, *types, ...)
Invokes a method on a Java object or a static method on a Java class. The invocation is static if *static is set to true or *classname is present. Otherwise the value of *object is taken to be a Java object and the invocation is done on a virtual method of the object. Method indicates the name of the method. Unless the *types argument is present, Karajan will try to determine the method signature from the types of .... A method is searched for in the inheritance hierarchy of the object. If one is found, the method is invoked and, if its return value is not void the returned value is returned on the default channel. The format of the type argument is identical to the one for new.
java:executeMain
java:executeMain(class, ...)
Invokes static void main(String[] args) on a class. The qualified class name should be passed in the class argument. The arguments on the default channel are converted to strings and passed as the args to the main method.
java:getField
java:getField(field, *object, *classname)
Returns the value of a field from an object or class. The filed name is passed in field. If *object is present, the value of the instance field of the object is retrieved. If *classname is present, the class field (static field) of the specified class is retrieved. Arguments *object and *classname are mutually exclusive.
java:waitForEvent
java:waitForEvent(...)
WaitForEvent is a rather obscure and incomplete element. It waits for a Java event such as a button being pressed, or a window being closed. Each argument is a list composed by three elements:
- A return value which will be returned when the associated event occurs
- The type of the event to wait for. Currently the following types are supported:
java.awt.events.ActionEvent- Can be used to wait for a button being pressed (or any other actions that have a addActionListener(java.awt.events.ActionListener) method.
java.awt.events.WindowEvent- Can be used to listen for the windowClosing notification on a window.
- The source object to be used
When the event occurs, waitForEvent completes returning the return value specified as the first item in the list corresponding to the event that the list represents.
java:classOf
java:classOf(object)
Returns the Java class name of the specified object.
java:null
java:null()
Karajan has no explicit null value. However, it may be necessary that a null value be used when invoking Java methods. Null provides that.