Defining Custom Functions in Transformer

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:

<iWaySMHome>

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.


Top of page

x
Procedure: How to Define a Custom Function in Transformer

To define a custom function:

  1. From the menu bar, select Project and then, Properties.

    The Project Properties dialog box opens.

  2. In the left pane, click the Custom Functions category.

    The following image shows the Project Properties dialog box with the Custom Functions category selected in the left pane.

  3. Click New.

    The Add New Custom Function dialog box opens.

    Perform the following steps:

    1. In the Function Location field, provide the full or relative path of the location of the custom function, for example:
      <iWaySMHome>\tools\transformer\custom functions\myFunction.class

      where:

      <iWaySMHome>

      Is the directory where iWay Service Manager was installed.

      myFunction

      Is the name of your custom function.

      You can also click the Browse button and navigate to the file.

    2. In the Function Name field, provide a name for the custom function, for example,
      My_Custom_Function

      Or you can specify a class name, for example,

      myFunction
    3. In the Number of Parameters field, provide the number of parameters that the custom function accepts.
  4. Click OK.

    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.


Top of page

x
Procedure: How to Import a Custom Function in Transformer

To import a custom function:

  1. From the menu bar, select Project and then, Properties.

    The Project Properties dialog box opens.

  2. In the left pane, click the Custom Functions category.
  3. Click Import.

    The Open dialog box appears.

  4. Select a Transform project file from which you want to import the custom function and click Open.

    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.


Top of page

x
Compiling Your .java File

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:

C:/temp/iway_custom_functions/src/

Is the temporary location for your custom function(s) source files on your hard drive.


Top of page

x
Migrating Custom Functions

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:

MY_FUNCTION_NAME

Is the name of your custom function.

MY_FUNCTION'S_RETURN_TYPE

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.



x
Procedure: How to How to Migrate Custom Functions

To migrate custom functions, modify your import statements as follows:

  1. Comment out xmlglobal package(s), for example:
    //import com.xmlglobal.goxmltransform.engine.functions.*;
  2. Add the iwaysoftware package, which must be imported, for example:
    import com.iwaysoftware.transform.common.function.AbstractFunction;

Top of page

x
Using Custom Functions at Run Time

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:

<iWaySMHome>

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