Creating Functions in Function Library 
You use this procedure to create functions in function library as these functions are customized and enable you to extend the scope of the functions. You save these functions in function libraries.
If you define the functions in the local function libraries then these functions are only visible in the corresponding message mapping. To make these functions available to other mappings of the same or a superordinate (local) function library, you need to create function libraries that are independent of message mappings as a separate object type in the ES Repository.
Note
You can also implement the methods with the defined names init() and cleanUp() in (local) function libraries. These methods are executed by the mapping runtime before or after the whole mapping program has been called.
All user-defined functions in (local) function libraries can access the following objects of the mapping runtime:
Accessing Standard Objects in Local Functions
Object |
Use |
This object enables you to cache the values that you want to read again when you next call the same user-defined function. |
|
This object enables you to cache the values that you want to read again when you next call any user-defined function that is in the same message mapping. |
|
This object enables you to transfer information for the mapping trace during mapping to a container that can be viewed by users in the message monitoring. |
You can also access functions in standard Java packages or imported archives (more information: Archives Used and Import List).
The editor for message mappings has a Local Function section, which lists all the local functions available in the message mapping.
You have created a message mapping in the ES Repository.
Note
The editor for message mappings has a Functions tab page, the ES Builder saves the function of this page in a function library, which is visible locally in the message mapping. The interface of this tab page is the same as that of function libraries.
You have launched the Java editor for editing the local function.
Note
You can launch the Java editor to edit the local functions by selecting the Edit button in the Local Functions section.
Alternatively, you can double-click on the function to navigate to the function definition in the Java Editor or use action available on the message mapping node in ES Browser tree to open the corresponding local function editor for the message mapping object.
You have read the implementation considerations for Java mappings, which apply to Java functions in (local) function libraries as well.
Define local functions by applying various annotations on the Java methods in the Java editor.
Note
The list of annotations available below helps you to describe various features of the local functions. All the annotations are available in the package com.sap.ide.esr.tools.mapping.core.
Annotation |
Description |
LibraryMethod |
When used on a certain method, this annotation will mark it as the Local function. |
Init |
When applied to the method, this annotation will mark it as an Init method and is invoked by the runtime before the execution of the mapping |
Cleanup |
When applied to the method, this annotation will mark it as an Cleanup method and is invoked by the runtime after the execution of the mapping |
Argument |
When applied to method input argument, this annotation will create an argument to function with type as Argument. Argument is also the default value for Argument type. |
Parameter |
When applied to method input argument, this annotation will create an argument to function with type as Parameter. The annotation is not required for arguments of type Channel and ResultList unless the user wants to provide a title to the argument. |
Enumeration |
Description |
ExecutionType |
The enumeration can be used to describe the execution type of the local function. By default the execution type is ExecutionType.SINGLE_VALLUE. Below are the list of execution types available:
|
Note
Methods that are not the Local Functions as well as Init and Cleanup functions are global helper methods and can be used in the Local Functions. You can also define the class fields that are global helper fields.
For functions with execution type All Values of Context or All Values of Queue, note the meaning of the values and the consistent structure of queues. More information: Advanced User-Defined Functions).
Return a result value in your Java function.
Note
Java functions with execution type Single Values must return a String value; Java functions with execution type All Values of Contextor All Values of Queue must return an object of type ResultList
Example
package com.sap.xi.tf;
import com.sap.aii.mapping.api.*;
import com.sap.aii.mapping.lookup.*;
import com.sap.aii.mappingtool.tf7.rt.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import com.sap.ide.esr.tools.mapping.core.Argument;
import com.sap.ide.esr.tools.mapping.core.ExecutionType;
import com.sap.ide.esr.tools.mapping.core.Init;
import com.sap.ide.esr.tools.mapping.core.Cleanup;
import com.sap.ide.esr.tools.mapping.core.LibraryMethod;
public class _demo_ {
@Init(description="init function")
public void init (
GlobalContainer container) throws StreamTransformationException{
//initialization code
}
@Cleanup
public void cleanup (
GlobalContainer container) throws StreamTransformationException{
//cleanup code
}
@LibraryMethod(title="append string", category="string",
type=ExecutionType.SINGLE_VALUE, description="returns a concatenation of two strings after trimming whitespaces")
public String appendAfterTrim(@Argument(title="input1")String in1,
@Argument(title="input2")String in2) {
return in1.trim() + in2.trim(); }
}
Note
If there are any errors in the signature and definition of the local function, they are reported as error markers in the local function editor on saving.
A function defined in the local function editor with incorrect method signature for a given execution type will not be available in the expression editor, such functions are saved as a plain Java method.
You have created a Java function in your function library.
If this is a local function library, the function is immediately visible in the expression editor of the message mapping in the function category usernamespace.
To use the Java function in other message mappings, you must transfer the functions of the local function library to an independent function library.
More information: Copying Functions of a Local Function Library.
If your function library is an independent function library, you can use the Java function in all message mappings of the same or a superordinate software component version.
More information: Implementing Functions of Function Libraries.