Home | Table of Contents | CustomJavaTransformer | CloverETL 4.6.1
--- | --- | ---
Prev | Transformers | Next

## CustomJavaTransformer

# Available in Community Designer

Short Description
Ports
Metadata
CustomJavaTransformer Attributes
Details
Examples
Best Practices
Compatibility
See also

### Short Description

CustomJavaTransformer executes user-defined Java code.

Component | Same input metadata | Sorted inputs | Inputs | Outputs | Each to all outputs | Java | CTL | Auto-propagated metadata
--- | --- | --- | --- | --- | --- | --- | --- | ---
CustomJavaTransformer | - | - | 0-n | 0-n | - |  |  |

### Icon

### Ports

Number of ports depends on the java code.

### Metadata

CustomJavaTransformer does not propagate metadata.

CustomJavaTransformer has no metadata templates.

Requirements on metadata depend on user-defined transformation.

### CustomJavaTransformer Attributes

Attribute | Req | Description | Possible values
--- | --- | --- | ---
Basic
Algorithm | [1] | Runnable transformation in Java defined in the graph. |
Algorithm URL | [1] | External file defining the runnable transformation in Java. |
Algorithm class | [1] | External runnable transformation class. |
Algorithm source charset |  | Encoding of external file defining the transformation. The default encoding depends on DEFAULT_SOURCE_CODE_CHARSET in defaultProperties. | E.g. UTF-8
[1] One of these must be set. These transformation attributes must be specified.

### Details

CustomJavaTransformer executes Java transformation. CustomJavaTransformer is a more specific CustomJavaComponent and it is focused on transforming data.

There are other similar java components: CustomJavaReader, CustomJavaWriter and CustomJavaComponent. All these components use transformation defined in java, they differ in templates being used.

You can use Public Clover API in this component. Documentation on general parts of custom java components and Public Clover API is described in CustomJavaComponent.

#### Java Interfaces for CustomJavaComponent

Transformation required by the component must extend `org.jetel.component.AbstractGenericTransform` class.

The component has same java interface as CustomJavaComponent, but it provides different java template. See Java Interfaces for CustomJavaComponent.

### Examples

#### Record Duplicator

Create a component duplicating input records.

##### Solution

    package jk;

    import org.jetel.component.AbstractGenericTransform;
    import org.jetel.data.DataRecord;
    import org.jetel.exception.JetelRuntimeException;

    /**
     * This is an example custom transformer. It shows how you can
     * duplicate all incoming records.
     */
    public class CustomJavaTransformerExample01 extends AbstractGenericTransform {

    	@Override
    	public void execute() {
    		try {
    			DataRecord inRecord = inRecords[0];

    			while ((inRecord = readRecordFromPort(0)) != null) {
    				writeRecordToPort(0, inRecord);
    				writeRecordToPort(0, inRecord);
    			}
    		} catch (Exception e) {
    			throw new JetelRuntimeException(e);
    		}
    	}
    }

Metadata on input and output port must be the same for this example.

### Best Practices

If the transformation is specified in an external file (with Algorithm URL), we recommend users to explicitly specify Algorithm source charset.

### Compatibility

CustomJavaTransformer is available since CloverETL 4.1.0-M1. It replaced JavaExecute.

### See also

CustomJavaComponent
CustomJavaReader
CustomJavaWriter
Common Properties of Components
Specific Attribute Types
Others Comparison

Prev | Up | Next
Concatenate | Home | Table of Contents | DataIntersection