Defining a Java conditional expression for a transform

You can use a Java™ method to set the conditional expression that determines whether a transform is applied in a graphical data map.

To define the conditional expression, you can define an XPath expression or a call to a static method on an imported Java class. You can also create a compound (nested) expression that includes XPath and Java.

Note: If you define a conditional expression for a transform, and then realize that the condition is identical for other transforms in the map, change the transform to an If transform. The conditional expression remains unchanged, and the transform is moved within the nested level of the If transform. Then, place all of the transforms that depend on the same condition in the If nested mapping.

Complete the following steps to set a conditional expression in a transform:

  1. Create a graphical data map.

    For more information, see Creating a graphical data map in the Eclipse editor.

  2. Create a Java project.

    For more information, see Creating a Java project.

  3. Create Java object classes.

    The Java class that you provide to the map must have static methods that return Boolean values.

    For example, the following Java method might be used to define a conditional expression on a transform:

    public static boolean lessThanHund(BigDecimal val) {
    		if ( val.intValueExact() < 100 )
    			return true;
    		return false;
    	}	
    	
  4. Ensure that the Java project the class is in is referenced by the project that contains the map.

    Before you create a reference to a Java project, ensure that the Java class is available in a Java project in your workspace.

    1. In the Application development page, right-click the project where the map is defined.
    2. Select Managed included projects.
    3. Select the Java project, and then click OK.
  5. Make the Java class visible anywhere in the map. Unless you have already used a method from the Java class in a Custom Java transform elsewhere in the map, you must manually create an import for the class. To manually import the Java class, you must configure the Java imports tab in the Properties page of the map:
    1. Select Add.
    2. Click Browse.
    3. In the Select entries field, enter the name of the Java package that contains the Java class.
      Note: You must start typing the name of your Java package before you can see any classes to choose from in the Select entries field.
    4. Select a Java class.
    5. Click OK.
    6. Enter a unique value in the Prefix field.
    Note: If the Java project that contains the Java class does not build in Eclipse, then the Java class is not visible anywhere in the map. You must resolve all the Java errors before you can configure the Java imports tab in the Properties page of the map. You can see the errors in the Problems tab.

    When you add a Java call in the General tab of the Properties page of a Custom Java transform in your map, an import is automatically added in the map to refer to the package qualified Java class, and a prefix based on the class name is added. All the public static methods in this Java class are then available in content assist when building expressions in other transforms. If you want to use this class, you can skip this step.

  6. For non-repeating elements, select the Condition property in the Properties tab, and enter a Java method.
    Note: Always use content assist to select the variable name of the input elements that you use to define the expressions. If you do not use content assist, you might be using an incorrect element name and your map fails at run time.
    You can identify the Java method in content assist by using the prefix. For example, in the following figure the prefix is Conditionals and the method is lessThanHund():
    Conditionals:lessThanHund( $element11)

    Figure that shows a Java expression on a Move transform.

    Note: If the input element being used to provide a value for a Java method is not of the correct type, you can use a type cast function, for example xs:int( $var ), to set the required type. For more information, see Cast type (xs:type).
  7. For repeating elements, select the Filter Inputs property in the Properties tab, and enter a Java method that is applied to each instance of the repeating element.

If the Java method returns true, the transform is applied to the input element.

Deploy and test the graphical data map. For more information, see Troubleshooting a graphical data map.

Copyright IBM Corporation 2013Copyright IBM Corporation 2012.

Task topicTask topic | Version 1.0 | cm40828_