In this section: How to: |
If no pre-defined Transformer function or their combination is sufficient to perform the task you require, you can write your own custom function containing the implementations of your task and returning the desired value. The custom functions must be written in Java code and compiled to produce a .class file, which then must be stored in the following directory to be available for use in design time with Transformer:
<iWaySMHome>/tools/transformer/custom_functions
where:
Is the directory where iWay Service Manager was installed.
Before using a custom function within Transformer, test it to ensure it works properly. For more information on creating or writing custom functions, see Writing Custom Functions.
Defining a custom function in Transformer creates a link to the actual custom function .class file stored in the custom_functions directory. Custom functions are defined using the Project Properties dialog box.
You can also import the custom functions from the other Transform projects. For more information, see How to Import a Custom Function in Transformer.
To define a custom function:
The Project Properties dialog box opens.
The following image shows the Project Properties dialog box with the Custom Functions category selected in the left pane.
The Add New Custom Function dialog box opens.
Perform the following steps:
<iWaySMHome>\tools\transformer\custom functions\myFunction.class
where:
Is the directory where iWay Service Manager was installed.
Is the name of your custom function.
You can also click the Browse button and navigate to the file.
My_Custom_Function
Or you can specify a class name, for example,
myFunction
Your custom function now appears in the list of defined custom functions. The name of the function is listed in the Function Signature column, and the location of the function is listed in the Location column.
To import a custom function:
The Project Properties dialog box opens.
The Open dialog box appears.
The imported custom functions appear in the list of defined custom functions for your Transform project. The name of the function is listed in the Function Signature column, and the location of the function is listed in the Location column.
In order to make your custom function available for use within Transformer, you need to compile the completed Java code of your custom function, integrating it with the Transformer engine code to create a .class file.
To compile custom functions, the %IWAY_HOME%/lib path must be part of your building environment. For example, you can use the following script to compile your custom function(s) with JDK version 1.6:
set IWAY_HOME=%IWAY60% set LIB="%IWAY_HOME%lib/*" set CLASS_FILES=%IWAY_HOME%etc/manager/transformations/custom_functions set SOURCE_FILES=C:/temp/iway_custom_functions/src/*.java javac -classpath %LIB%; -d %CLASS_FILES% %SOURCE_FILES% @pause
where:
Is the temporary location for your custom function(s) source files on your hard drive.
In early versions of Transformer, for example, 5.2.104, the Java code for a custom function had a format similar to the following:
import com.xmlglobal.goxmltransform.engine.functions.*; public class MY_FUNCTION_NAME extends AbstractFunction { public MY_FUNCTION_NAME() { setName("MY_FUNCTION_NAME"); setDescription("This is what my function does..."); } public Object execute() throws Exception { // perform function's execution here // and return desired output value } public Class getReturnType() { return MY_FUNCTION'S_RETURN_TYPE; } }
where:
Is the name of your custom function.
Is the data type of your custom function's return value.
The following procedure describes how to migrate custom functions created for the early versions of Transformer, for example, 5.2.104, to be called by your modified .xch file.
Note: Before you compile the migrated custom functions, verify that the iwtranse.jar file is in your classpath.
To migrate custom functions, modify your import statements as follows:
//import com.xmlglobal.goxmltransform.engine.functions.*;
import com.iwaysoftware.transform.common.function.AbstractFunction;
To use custom functions during the run time, they must be placed in a compressed registered library .jar file, or in the following iWay Service Manager classpath:
<iWaySMHome>\etc\manager\transformations\custom_functions
where:
Is the directory where iWay Service Manager was installed.
For more information on how to register a library .jar file, see the iWay Service Manager User's Guide.
iWay Software |