All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface Iava.Scriptable

public interface Scriptable
The interface Scriptable is implemented by classes to integrate Iava scripting. When a scriptable object is created within a Iava script, the interpreter automatically "hooks up" the scriptable object with the interpreter's IavaRuntime. This runtime in turn can be used by the scriptable object to access methods and variables declared by a script and to share its protected/private fields with a script. Since Iava cannot declare classes or anonymous classes, there are two possible implementation patterns. The first is shown below:
 public class IavaEventListener implements ActionListener, Scriptable {
	private IavaRuntime runtime=null;
	private String actionPerformed=null;
	public IavaEventListener(String actionMethodName) {
		actionPerformed=actionMethodName;
	}
	public void hookUp(IavaRuntime rt) {
		if (!hookedUp()) // protect from re-assigning
			runtime=rt;
	}
	public boolean hookedUp() {
		return (runtime!=null);
	}
	public void actionPerformed(ActionEvent e) {
		if (hookedUp())
			runtime.callIavaMethod(actionPerformed,new Object[]{e});
	}
 }
 

In a Iava script, this class is used as follows:
 public void buttonActionPerformed(ActionEvent e) {
	... // do some event handling here
 }
 
... Button b=new Button("My Button"); b.addActionListener(new IavaEventListener("buttonActionPerformed")); ...
The second implementation pattern uses IavaMethod objects instead of method names:
 public class IavaEventListener implements ActionListener, Scriptable {
 	
private IavaRuntime runtime=null; private String methodName=null; private IavaMethod actionPerformed=null;
public IavaEventListener(String actionMethodName) { methodName=actionMethodName; }
public void hookUp(IavaRuntime rt) { if (!hookedUp()) // protect from re-assigning runtime=rt; IavaMethod[] methods=runtime.getDeclaredMethods(); for (int i=0;i public boolean hookedUp() { return (runtime!=null && actionPerformed!=null); }
public void actionPerformed(ActionEvent e) { if (hookedUp()) actionPerformed.execute(runtime,new Object[]{e}); }
}

In a Iava script, this class is used as above.

See Also:
IavaRuntime

Method Index

 o hookedUp()
Returns true if the scriptable is in possession of a valid reference to a IavaRuntime object.
 o hookUp(IavaRuntime)
Provides a scriptable with a IavaRuntime object.

Methods

 o hookUp
 public abstract void hookUp(IavaRuntime rt)
Provides a scriptable with a IavaRuntime object. When a scriptable is constructed within a Iava script this method is called by the Iava interpreter directly after invoking the constuctor. This method is never called by objects other than the Iava interpreter.

 o hookedUp
 public abstract boolean hookedUp()
Returns true if the scriptable is in possession of a valid reference to a IavaRuntime object.


All Packages  Class Hierarchy  This Package  Previous  Next  Index