Calling the method of a class in a plug-in
Both Java and JavaScript event handlers have access to all the public methods of any class that resides in an Eclipse plug-in. The plug-in can be one of the core Eclipse plug-ins, a plug-in supplied by a third party, or one of your own creations. As long as the plug-in is available to the BIRT report at run time, a BIRT script has access to all the public methods of all the classes within that plug‑in.
Listing 37‑30 shows how to call a method of a Java class that resides in an Eclipse plug‑in.
Listing 37‑30 Using JavaScript to access a method of a Java class in an Eclipse plug‑in
importPackage( );
mybundle = Platform.getBundle( "" );
validateClass = mybundle.loadClass( "" );
validateInstance = validateClass.newInstance( );
var password = validateInstance.getPass( loginID );
In the example, the first statement makes the Eclipse core package, org.eclipse.core.runtime, available to the JavaScript code. This package contains two classes, Platform and Bundle, which the rest of the script requires.
The Platform class contains a static method, getBundle( ), that returns a Bundle object. The sole argument to getBundle( ) is the name of the plug-in that contains the target class.
The Bundle class contains a loadClass( ) method that returns a java.lang.Class object. The only argument to loadClass( ) is a fully qualified class name, which in this case is
The java.lang.Class class represents the target class and contains a newInstance( ) method that returns an instance of the class. newInstance( ) creates the instance using the default constructor, which has no arguments. The final statement in the example calls the target method of the newly instantiated object of the target class.
Listing 37‑31 shows the Java equivalent of Listing 37‑30.
Listing 37‑31 Using Java to access a method of a Java class in an Eclipse plug‑in
#import org.eclipse.core.runtime.Bundle;
#import org.eclipse.core.runtime.Platform;
Bundle mybundle = Platform.getBundle( "" );
java.lang.Class validateClass = mybundle.loadClass( "" );
Validate validateInstance = validateClass.newInstance( );
String password = validateInstance.getPass( loginID );