IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Defining and transforming data > Transforming data > Transforming data using XML maps
Create a custom lookup
In the XML map editor, you can look up a value from a file by using a key from the input element and populate the target element with the retrieved value. In addition to the lookups provided by the map editor, you can contribute lookup engines for your own custom file types.
To add your own custom engine to the map editor, follow these instructions:
Procedure
- Create a Java™ class that implements the interface com.ibm.wbit.mapping.xml.ILookupEngine.
- In the map editor, connect the input and output elements and change the transform type to Lookup.
- In the General tab of the Properties editor, click the New Engine button. The name of the class is displayed in the list of available lookup engines.
For example, if you choose the class name EnterpriseDatabaseLookup, the name that is displayed is Enterprise Database Lookup:
- Define the properties that are required by the lookup engine. The user will enter the property value in the map editor, and these values will be set in the engine at run time.
Properties are defined in JavaBeans style where the presence of a “set” method indicates a property of the engine. All methods in the engine class that start with the word “set” will be considered property definitions. The type of the parameter on the set method is the type required for the property.
For example, the method setDatabaseFilename(File) generates the property DatabaseFileName of type File.
Supported types are String, File, int, and boolean.
Example:
Suppose that this is the lookup engine class:
import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.xpath.NodeSet; import com.ibm.wbit.mapping.xml.lookup.ILookupEngine; import com.ibm.wbit.mapping.xml.lookup.LookupEngineFileUtil; import com.ibm.wbit.mapping.xml.lookup.LookupEngineNodeUtil; public class EnterpriseDatabaseLookup implements ILookupEngine { private String keyColumName; private String valueColumnName; private File dbFileName; private HashMap<String, String> parsedDatabaseFileContent; /**********************************************************************/ /*************** Engine Property Definitions *******************/ /**********************************************************************/ public void setDatabaseFileName(File entDBFileName){ this.dbFileName = entDBFileName; } public void setKeyColumName(String keyColumName) { this.keyColumName = keyColumName; } public void setValueColumnName(String valueColumnName) { this.valueColumnName = valueColumnName; }The resulting properties page will look like this:
- Implement the lookup method in the engine.
- String and NodeList are the valid return types for the lookup method.
- The following utility classes are available:
- com.ibm.wbit.mapping.xml.lookup.LookupEngineNodeUtil
- Provides methods to extract simple values from a list of given inputs
- com.ibm.wbit.mapping.xml.lookup.LookupEnginePropertyUtil
- Provides methods to access properties in the binding hashmap.
Example
Once implemented, the new engine will be found automatically when the list of engines is loaded. You might need to click Reload to refresh the list or the engine properties.