Topics: |
The iIT Transformer interface offers an integrated set of useful functions, which are used to perform a variety of operations, such as calculation and manipulation of input data, or retrieving data from a database. You may use functions to modify the output node value to match your requirements. You can build complex expressions for output values using the combinations of functions via the Mapping Builder.
In addition, iIT Transformer enables you to implement your own algorithms for producing output values by adding custom functions according to the specific format. For more information, see Custom Functions.
Topics: |
How to: |
The Mapping Builder is a tool available in iIT Transformer as part of the Mapping Builder facility. It allows you to construct an output node using various methods and formulas implemented in iIT Transformer as functions. You can access the predefined functions and the custom functions that you defined, or build the statement containing several functions if needed.
In iIT Transformer, the predefined functions are subdivided into the following categories:
After selecting a specific function, typically you will need to define the set of parameters associated with it. The number and the names of the parameters for the particular function can be determined in either of the following ways:
@SUBTRACT (number1, number2)
For more details on the parameters to specify for each particular function, see Predefined Functions for a complete reference. If dealing with custom functions, you may consult the author of the function.
Generally, the functions can take four types of values as their parameters:
A function of a parameter can take the value of a specified input node. For information on how to set an input node, see How to Set an Input Node.
You can nest functions within functions, which means the output result of a certain function can serve as the input parameter for another function. For more details, see How to Nest Functions.
You can also set a specific invariable value as a constant function parameter. For information on how to set a constant value, see How to Set a Constant Value for a Function.
Another option for a function parameter type is an expression which is a basic combination of operators, input nodes, and/or constants. For information on how to set an expression, see How to Set an Expression for a Function.
The Mapping Builder enables you to set the output node values using a combination of functions and/or input nodes. Both custom and predefined functions can be utilized. When specifying a function through the Mapping Builder, you must know what the specific function does and how to specify the parameters for it. For more information, see Predefined Functions.
The following image shows the Mapping Builder interface in iIT Transformer.
To open the Mapping Builder:
The Mapping Builder displays as shown in the following image.
The left pane of the Mapping Builder dialog box provides you with the option of switching between the following areas:
Click the name of the corresponding pane to expand its content. Click New to add new values to the Variables and JDBC Data Source panes.
This feature allows you to drag and drop any available configuration that was specified using the Project Properties dialog box into the workspace area of the Mapping Builder. You can switch between the available panes by clicking on the corresponding button, for example, Variables, JDBC Data Source, and so on.
To select a function:
For a list of function categories, see Using the Mapping Builder.
The following image shows String Functions selected in the Category drop-down list, which is located in the Functions pane.
Optionally, you can skip to step 2 and select your function from the whole list of available functions.
Note: You can drag and drop functions above or below the existing mapping tree in the workspace area as needed to create a combination of output values.
The function you choose becomes your working function.
To set an input node as the value for a function parameter:
An alternate way to perform this task is to use Set Selected Input option from the context menu, which appears when you right-click the parameter in the workspace area.
Note: Another method for editing the mapping formula of your node is to type it directly in the preview area located on the lower-right corner of the Mapping Builder window and press Enter. The tree structure will be refreshed. However, this option is recommended for advanced users only. Using the drag and drop interface instead is strongly encouraged.
To specify another function as a parameter for your working function:
An alternative way to perform this task is to use Set Selected Function option from the context menu, which appears when you right-click the parameter in the workspace area.
You must set the parameters for the nested function as well.
Note: You can nest functions multiple times.
To set a constant value:
You can also double-click the parameter box to set a constant.
The following image shows the Constant option selected and a field where you can enter a value.
To set an expression:
You can also double-click the parameter box and select the Expression radio button to set an expression.
An expression concatenation is typically used for any number of input items and constant values in any order, in the following format:
<input item>+'constant'+...
For example:
'For '+tree/fruit+tree/fruit/year+': '+tree/fruit/apple/yield+ ' bushels, '+tree/fruit/apple/avgweight+' grams avg.'
To remove a value for a function parameter:
A context menu opens as shown in the following image.
The parameter is removed from the function.
To cancel and restore an action within the Mapping Builder:
A context menu opens as shown in the following image.
The last action is removed from the workspace.
A context menu opens as shown in the following image.
The last removed action is returned to the workspace.
Note: Multiple levels of undo and redo are supported. You can select Undo/Redo or use the corresponding keyboard shortcut (Ctrl+Z/Ctrl+Y) multiple times until you have achieved the desired result.
How to: |
You can customize the signature of your @CONCAT function for a specific output node by adding or removing parameters as required using the Mapping Builder. This functionality adds flexibility to the design of mapping values, which involve complex string concatenations; it also eliminates the need to use expressions for the concatenation of strings in iIT Transformer.
To add parameters for @CONCAT functions:
The parameter is added to the parameter list, and the number of parameters for this function definition will increase by one.
To remove parameters for @CONCAT functions:
The parameter is removed from the parameter list, and the number of parameters for this particular function definition will decrease by one.
Topics: |
A JDBC replace function is a replace function in which the match and replace values are taken from columns of the specified database table or from the results of an SQL statement run on the specified database. For example, you can configure iIT Transformer to use a database customer information table, reading the value from the "Full Name" column and replacing it with the value from the "Nickname" column. Unlike the regular replace functions where the match and replace pairing is static, the JDBC replace functions read the data from the specified columns of the next database row each time the transformation processing loops past the JDBC replace function while producing your output document.
Replace functions are similar to custom functions in that you must first define the function and then, apply it to the output node mapping value definition that you want to affect. In the case of replace functions, this can be accomplished using the @REPLACE and @SIMPLE_REPLACE functions.
For more advanced database functionality, such as matching across multiple input nodes or running complex SQL queries, see Using the @JDBCLOOKUP Function.
The process of defining a particular replace function accounts for setting up the value to match, but not the mapping of it. You must map the replace functions to the specific node using the Mapping Builder. For more information, see Using the Mapping Builder.
How to: |
Since a JDBC replace function can be defined and used no matter what the data format of your input is, by using JDBC replace functions you can access multiple input data sources. For example, if the input data format of your transform is XML, your incoming document is likely an XML file. By defining and using JDBC replace functions, you can read additional input data from the database. In fact, if you define multiple JDBC replace functions, you can use as many database sources as you like.
To define a JDBC lookup:
The Properties dialog box opens.
The following image shows the Project Properties dialog box with the @REPLACE Functions category selected in the left pane.
The JDBC Replace Function Dialog opens.
To access the particular database, you must provide the necessary information that is required for your JDBC lookup.
Note: To define a predefined function (for example, @SREG) as the URL, click the Browse button to the right of the URL field, which opens the Mapping Builder.
Note: iIT Transformer does not ship with any of the predefined drivers. The driver must be registered with iIT Transformer.
If you select From Table, specify a database table name in the Table Name field.
If you select From SQL Query, specify an SQL statement to run on the database in the SQL Query field.
If you specify an SQL statement, the match and replace values are taken from the result of the SQL statement.
To change or update any information in your JDBC lookup:
The JDBC Replace Function Dialog opens.
To delete a JDBC lookup, select the JDBC lookup, for example, JDBC1, and click Remove.
The JDBC lookup is removed from the list.
How to: |
The @JDBCLOOKUP function returns a matched value from a database using an SQL statement. It takes the JDBC data source name and SQL statement in string form as parameters. The SQL statement can be set dynamically based on the input from other functions within iIT Transformer. If more than one value is matching the query, then the last matching value is returned.
When no result is found in the database, an empty string is returned. When more than one result is found, the last matching result is returned. Regardless of the number of columns in the result set, the value of the first column is always returned. During the transformation with multiple occurrences of @JDBC lookup, if the SQL statements are the same, then the returned result will be the same.
Parameters:
JDBC_data_source_name: String that represents a globally defined JDBC connection configuration.
SQL_statement: SQL statement that can be created using SQL Builder.
Example:
@JDBCLOOKUP('LOOKUP_TEST', {'SELECT field1 FROM LOOKUP_TABLE WHERE field2 ' = '+@QUOTE(Customer/Person/Name)})})
where:
Is the name of a JDBC connection configuration.
Is an SQL statement.
To create an SQL statement, which can be used for the @JDBCLOOKUP function, you must follow the instructions below:
The Properties dialog box opens.
The following image shows the Properties dialog box with the JDBC Data Source category selected in the left pane.
The JDBC Data Source Dialog opens.
Perform the following steps:
This name is used as a string value for the JDBC_data_source_name parameter in the @JDBCLOOKUP function.
Note: To define a predefined function (for example, @SREG) as the URL, click the Browse button to the right of the URL field, which opens the Mapping Builder.
Note: iIT Transformer does not ship with any of the predefined drivers.
Note: If the timeout value is omitted, or the value is 0 (default), then timeout is not enabled.
The JDBC lookup is added to the list of defined JDBC lookups.
The Mapping Builder opens.
The JDBC Data Source dialog box opens as shown in the following image.
The @JDBCLOOKUP function is updated as shown in the following image.
Since the SQL statement is an expression, the Where clause can contain the following:
Note: In the Column Name field, you can also type * or Count (*) to return more advanced data sets.
How to: |
Replace functions are used to match and replace specific values of the input data. For example, suppose your input data has a node called "car_age" with a value of either "new" or "used". If you decide to substitute the term "used" and want to use "pre-owned", you can define a replace function with match and replace value pairing where the match value would be specified as "used" and the replace value is "pre-owned."
Replace functions work similar to custom functions in that you must first define the function itself and then, assign it in the output node mapping value which needs to be modified. This task can be accomplished with the @REPLACE and @SIMPLE_REPLACE functions.
The process of defining replace functions accounts for setting up the values to match and replace, but not the mapping. You must map the replace functions using the Mapping Builder. For more information, see Using the Mapping Builder.
To define a replace function:
The Properties dialog box opens.
The following image shows the Project Properties dialog box with the @REPLACE Functions category selected in the left pane.
The Input Lookup and JDBC Lookup tabs contain the lists for the two types of replace functions available in iIT Transformer.
To define replace functions in which the match and replace values are taken from the columns of the specified database table, enabling you to insert the input values from the different databases, use the JDBC Lookup tab.
To define an input lookup for a replace function:
The Add/Edit Input Lookup dialog box opens.
You are returned to the previous Add New Input Lookup dialog box.
You can add multiple input lookups if required.
For example, the following image shows a replace function named "Mammals." The lower pane of the Add New Input Lookup dialog box has columns for Match and Replace node values for various mammals, for example, “cow” to "bovine.”
To modify an input lookup:
The Input Lookup Properties dialog box opens.
You can perform either one of the following modifications to an input lookup group:
To delete an input lookup, select the input lookup, for example, Mammals, and click Remove.
The input lookup is removed from the list.
Topics: |
The custom functions that can be used with iIT Transformer must be written in Java code, complying with the rules discussed in the following section. Custom functions can be stored as a class file or a jar file, either as part of your iIT project, or on the file system.
Note: The following section is written assuming that you are familiar with the Java programming language.
Each custom function you write must be a subclass of the AbstractFunction super class.
You must implement a constructor for your class and the two abstract methods, execute() and getReturnType(), which are inherited from the AbstractFunction class. You may also choose to add your own methods. The Java code for your custom function must conform to the following format:
import com.iwaysoftware.transform.common.function.AbstractFunction; 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.
You must include the following import statement in the beginning of your custom function implementation:
import com.iwaysoftware.transform.common.function.AbstractFunction;
This enables you access to the methods required for your custom function implementation.
Note: Optionally, you can utilize the logging capabilities of iIT Transformer in the code of your custom function by including the following import statements in the beginning of your custom function implementation:
import com.iwaysoftware.transform.common.log.LogUtil; import com.iwaysoftware.transform.common.log.TransformLogger;
As stated previously, a custom function is a subclass of the AbstractFunction super class. Therefore, you can declare your custom function as follows:
public class MY_FUNCTION_NAME extends AbstractFunction { ... }
where:
Is the name of your custom function.
There are two methods you must call within the constructor of your custom function. They are the setName(String name) and setDescription(String description) methods, which are predefined in the AbstractFunction super class. The values provided as parameters for these methods are utilized when you access your custom function within iIT Transformer.
The name of the function used in iIT Transformer is the parameter that you set using the setName method, and the description of the function used by iIT Transformer is the message you type as the parameter in setDescription.
The method execute(), is one of two abstract methods declared in the AbstractFunction super class, which is supposed to contain the function procedures and instructions. Your custom function, which is a subclass of AbstractFunction, must therefore, implement the execute() method as follows:
public Object execute() throws Exception { ... }
When you are writing the body of this method, you can follow the same style that is used to write any method in Java.
Retrieving arguments passed into your custom function is achieved through the methods getValueInstance(), getArgument(int index), and getFunctionContext(), which are the predefined methods from the functions package that your custom function is a part of. To store two arguments as String variables argOne and argTwo, write the following:
String argOne = (String)getFunctionContext().getArgument(0).getValueInstance();
String argTwo = (String)getFunctionContext().getArgument(1).getValueInstance();
Other methods that you may find useful for your custom function implementation are:
Returns an integer indicating the number of arguments passed to your function by the user, which is used in conjunction with method, getFunctionContext(), as follows:
int num = getFunctionContext().getNumberOfArguments();
Returns an array containing all of the arguments passed to your function by the user. To store your arguments in an array of objects called myArray, use the following format:
Object[] myArray = getFunctionContext().getArguments();
getReturnType() is one of the abstract methods declared in the AbstractFunction class. Therefore your custom function, which is a subclass of AbstractFunction, must implement this method. The value returned by getReturnType() indicates the type of value you return in method execute(). The choices for your return value are:
The custom function interface of iIT Transformer is now updated with the ability to utilize the data structure of customizable global parameters. This data structure is implemented as a Java Map object, which is an object that maps keys to values. This object can be accessed by any custom function within your project. As a result, it can contain global reusable data or information that can be cached, such as your database connection string. The Associated Object Map can also be used to track the usage of the custom functions in your project, if required. Use the following format to access the Associated Object Map:
Map objectMap = super.getAssociatedObjectMap();
The following snippet of Java code is the implementation for a custom function that returns a string resulting from adding 25 to the input value of the function.
import java.math.BigDecimal; import java.util.Map; import com.iwaysoftware.transform.common.function.AbstractFunction; import com.iwaysoftware.transform.common.log.LogUtil; import com.iwaysoftware.transform.common.log.TransformLogger; public class ADD25 extends AbstractFunction { private static final BigDecimal BD25 = new BigDecimal(25); public ADD25() { /* specifies the function name to be used within iAM */ setName("ADD25"); /* specifies the function description to be used within iAM */ setDescription("Return a string resulting from adding 25 to input value."); } public Object execute() throws Exception { /* * retrieves the first argument and assigns it to Double variable * 'input' */
// arguments are String always String inputArg = (String) getFunctionContext().getArgument(0).getValueInstance(); BigDecimal input; try { input = new BigDecimal(inputArg); } catch (Exception e) { input = new BigDecimal(0); } // Gets the instance of the logger TransformLogger logger = super.getLogger(); // Gets the debug flag boolean debug = LogUtil.canDebug(logger); // Fetches associate objects Map objectMap = super.getAssociatedObjectMap(); /* creates a variable to hold the value that will get returned */ String answerString; if (objectMap.containsKey(input)) {
// return stored result String result = (String) objectMap.get(input); if (debug) { LogUtil.debug(false, logger, "returning CACHED result: "); } return result; } else { answerString = input.add(BD25).toString(); objectMap.put(input, answerString); if (debug) {
LogUtil.debug(false, logger, "returning the value : " + answerString); } // return string return answerString; } } public Class getReturnType() { /* specifies that method execute() returns a String */ return java.lang.String.class; }
Topics: |
How to: |
If no predefined iIT 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 iIT Transformer:
<iWaySMHome>/tools/transformer/custom_functions
where:
Is the directory where iWay Service Manager was installed.
Before using a custom function within iIT 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 iIT 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 components. For more information, see How to Import a Custom Function in iIT Transformer.
To define a custom function:
The Properties dialog box opens.
The following image shows the Properties dialog box with the Custom Functions category selected in the left pane.
The Edit Custom Function dialog box opens.
Several options are provided to add one or multiple custom functions if they reside in a .jar file.
Note that your .jar file has been parsed and the list of custom functions contained in the .jar file now appears in the Customizations area, as shown in the following image.
You can make any of the custom functions listed in the Customizations area available in Mapping Builder by clicking the check box next to it, for example, CountChar.class.
The Parameters dialog box opens, which prompts you to verify the name of the custom function. Enter the number of parameters that the custom function accepts as shown in the following image, and click OK.
Note that every custom function that was defined by selecting the corresponding check box in the Customizations area is now included in the Custom Functions visible to the transform area, as shown in the following image.
The custom functions now appear in the list of defined custom functions of the Mapping Builder. 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 or define a custom function, or to define a JDBC Lookup:
The Properties dialog box opens.
In order to make your custom function available for use within iIT 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=%IWAY7% 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.
How to: |
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;
In iIT Transformer, the functionality of custom functions for run time purposes is the same as the design time functionality. For more information on configuring custom functions, see Custom Functions.