Previous TopicNext Topic


Calling a method of a class that resides in a plugin

Java and JavaScript event handlers both have access to all the public methods of any class that resides within an Eclipse plugin. The plugin can be one of the core Eclipse plugins, a plugin supplied by a third party, or one of your own creations. As long as the plugin is available to the BIRT report at runtime, a BIRT script has access to all the public methods of all the classes within that plugin.

The following JavaScript code snippet illustrates how to call a method of a Java class that resides in an Eclipse plugin:

importPackage(Packages.org.eclipse.core.runtime);    
mybundle = Platform.getBundle("org.eclipse.myCorp.security"); 
validateClass = mybundle.loadClass( 
"org.eclipse.myCorp.security.Validate"); 
validateInstance = validateClass.newInstance(); 
var password = validateInstance.getPass(loginID); 

In the preceding snippet, the first statement makes the Eclipse core package, org.eclipse.core.runtime, available to the JavaScript program. This package contains two classes, Platform and Bundle, that are necessary to the rest of the program.

The Platform class contains a static method, getBundle( ), that returns a Bundle object. The sole argument to getBundle( ) is the name of the plugin that contains the target class.

The Bundle class contains a loadClass( ) method that returns a java.lang.Class object. The sole argument to loadClass( ) is a fully qualified class name, in this case org.eclipse.myCorp.security.Validate.

The java.lang.Class class represents the target class and contains a newInstance( ) method that returns an instance of the class. The newInstance( ) method 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.

The Java equivalent of the previous JavaScript example is:

#import org.eclipse.core.runtime.Bundle;  
#import org.eclipse.core.runtime.Platform; 
#import org.eclipse.myCorp.security.Validate; 
Bundle mybundle = Platform.getBundle( 
"org.eclipse.myCorp.security" ); 
java.lang.Class validateClass = mybundle.loadClass( 
"org.eclipse.myCorp.security.Validate" ); 
Validate validateInstance = validateClass.newInstance(); 
String password = validateInstance.getPass(loginID); 

(c) Copyright Actuate Corporation 2006

Previous TopicNext Topic