Starting Java API extension points from scripting

You can start Java™ API extension points from existing scripting API code by passing parameters across the scripting environment and the Java API code. This passing allows the customer solutions that are already developed through Scripting APIs to take advantage of the new capabilities in Java API.

The following features are supported:
Argument passing
User's custom objects can be passed between IBM® Product Master scripts and Java API implementations.
Note: When it comes to Product Master entities, same set of objects that are used in the scripting are available for Java API code through the argument interfaces.
Seamless modification of Product Master entities
Since Scripting API code and Java API extension points can be mixed, it is possible to update the Product Master entities in scripting. You can get the same set of entities that are further updated through Java API code. This modification allows the updates on Product Master entities to be split across Scripting API code and Java API code. For example, an Item object can be modified partially in scripting API code and rest of the modifications can be done in an extension point implementation Java API class. The Java API class needs to have access to the same Item object through the argument interface.
Multiple invocations
Multiple invocations of compatible extension point Java code from the same Product Master script are supported.
Invocation of Java API extension points from scripting API is achieved through the introduction of a new scripting API runJavaApiExtensionPoint(). This script operation takes a Java API URL, which points to the extension point implementation to be started. Additionally, to facilitate a parameter passing across a Scripting environment and Java APIs, the argument interfaces of extension points provide following two extra methods, which can be used to read or set custom parameters:
  • Object getCustomParameter(String key);
  • void setCustomParameter(String key, Object userObject);

Basically, the users can set a custom variable in the script implementation through the setScriptContextValue() script operation and retrieve it in Java implementation through the getCustomParameter() method. Similarly, they can set a variable in the Java implementation through setCustomParameter() method and retrieve it in the script implementation through getScriptContextValue() script operation. Through this approach, you can mix the Product Master script and Java API implementations and be able to pass non Product Master objects between the two implementations.

Product Master Java API method getCustomParameter() returns the custom value from script context, in the context of extension point invocation. Custom values can be placed in the context through the method setCustomParameter(), which accepts the key/value pair as input. Each value is identified through the key and the value must be an object. This method is useful when values need to be transferred across script API and Java API extension point code. This method is available from the function argument objects, which are passed to the extension point implementation classes.
For example,
public void reportGenerate(ReportGenerateFunctionArguments arg0) 
{
	try  {
             String value1Val = (String) arg0.getCustomParameter("value1");
 		}
		catch (Exception e) {
             e.printStackTrace();
             System.out.println("   Exception"+ e.getMessage());
         }
 }

Usage Guidelines

  • To obtain the Java API context in the extension point implementation class, use the API getCurrentContext() instead of creating a new context.
  • The method setCustomParameter() has the same restrictions as defined for setScriptContextValue. For more information, see setScriptContextValue script operation.