A site about Talend
You're achingly close to building your first component; however, we'll first analyse an existing component. This will provide you with an overview of the component files.
As discussed in previous articles, component design is poorly documented and the purpose of many features and parameters are often based on a little bit of guess-work. Once you have established the basics and you're at the level of being able to create a useful component, you'll be ready for the remaining articles that attempt to provide an in-depth analysis of all of the features and parameters.
We'll now take a look at the source code of the tJava component. This is a powerful component; but has relatively simple source code, so it's a great starting point. The code shown here is from Talend Open Studio 5.5.0. You may see variations with other product versions.
As previously discussed, there is a minimum set of files that make up a component's source code. These files were summarised in the Minimum File Set table shown in the Design Introduction article.
This file is described as the XML configuration file for JAVA Component. It is the starting point for creating a component and is where you specify connectors, inputs, outputs and numerous other parameters. This is an XML file that may be edited using the Component Designer, a text editor, or an XML editor of your choice.
For full documentation on all of the available elements and attributes, as defined by the file
Component.xsd, read the Component.xsd Reference.
You would usually expect the first line of an XML file to specify the XML version and the encoding. The source code for tJava (as with most of the standard components) does not have this line. When you create a new component using Component Designer, the line shown below will be added. Although it would appear that this line is not mandatory, it would seem sensible to add it to all of your own components.
<?xml version="1.0" encoding="UTF-8"?>
In this section, we will analyse the interesting elements and attributes that are specified in this file. You may find it helpful to read the Component.xsd Reference which provides an in-depth analysis of all of the elements and attibutes that are available.
The following shows the entire code the the tJava component, as supplied with Talend Open Studio version 5.5.0. We will look at
ADVANCED_PARAMETERS. If you are not familiar with the other elments and attributes, read the Component.xsd Reference.
<COMPONENT> <HEADER PLATEFORM="ALL" SERIAL="" VERSION="0.101" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Talend" RELEASE_DATE="20070210A" STARTABLE="true" PARTITIONING="AUTO"> <SIGNATURE></SIGNATURE> </HEADER> <FAMILIES> <FAMILY>Custom_Code</FAMILY> </FAMILIES> <DOCUMENTATION> <URL/> </DOCUMENTATION> <CONNECTORS> <CONNECTOR CTYPE="FLOW" MAX_INPUT="1" MAX_OUTPUT="1"/> <CONNECTOR CTYPE="ITERATE" MAX_OUTPUT="1" MAX_INPUT="1"/> <CONNECTOR CTYPE="SUBJOB_OK" MAX_INPUT="1" /> <CONNECTOR CTYPE="SUBJOB_ERROR" MAX_INPUT="1" /> <CONNECTOR CTYPE="COMPONENT_OK"/> <CONNECTOR CTYPE="COMPONENT_ERROR"/> <CONNECTOR CTYPE="RUN_IF"/> </CONNECTORS> <PARAMETERS> <PARAMETER NAME="CODE" FIELD="MEMO_JAVA" REQUIRED="false" NUM_ROW="2" NB_LINES="9" CONTEXT="begin"> <DEFAULT>String foo = "bar";</DEFAULT> </PARAMETER> </PARAMETERS> <ADVANCED_PARAMETERS> <PARAMETER NAME="IMPORT" FIELD="MEMO_IMPORT" REQUIRED="false" NUM_ROW="1" NB_LINES="3"> <DEFAULT>//import java.util.List;</DEFAULT> </PARAMETER> </ADVANCED_PARAMETERS> <CODEGENERATION/> <RETURNS/> </COMPONENT>
The tJava component supports 7 of the most commonly used connectors (as defined by the attribute
CTYPE). These connectors are
RUN_IF. You will find all of these described in the Component.xsd Reference. The most interesting part of these connectors are the settings for
MAX_OUTPUT, as these help to describes how the component interacts with the other components in your Job (
MIN_OUTPUT are also available).
If these are not specified with a value, then there is no limit to the number of connections of this type, that may be made with the other components within your job.
The tJava component has a single basic parameter, and a single advanced parameter. The significant difference between the placement of these parameters (basic or advanced), is the Component Settings tab that they will appear on, within the Job Designer (either Basic settings or Advanced settings). for more information on parameters, refer to the Component.xsd Reference.
CODE parameter is a Java-styled memo field (
MEMO_JAVA), that will specify the Java code that should be executed. This is provided with a
DEFAULT value of
String foo = "bar";. When the component is used, the Job Designer will replace this line with their own code. Talend provides styled memo fields, to provide features such as syntax-highlighting and auto-completion, if available.
IMPORT parameter is am import-styled
MEMO field, that will specify any Java libraries that are required by the code was specified by the Job Designer for the
CODE parameter. This is provided with a
DEFAULT value of
import java.util.List;. When nthe component is used, the Job Designer will replace this commented line with their own imports, as required by their custom code. This parameter is placed on Advanced settings as it is used less frequently that the
CODEGENERATION parameter is not implemented by the tJava component. It should be included in all component definitions, even when it has not been implemented. This element will be discussed in a future article; however, for further information on this and other elements and attributes, please read the Component.xsd Reference.
RETURNS parameter is not implemented by the tJava component. It should be included in all component definitions, even when it has not been implemented. This element will be discussed in a future article; however, for further information on this and other elements and attributes, please read the Component.xsd Reference.
This is the default Java Property File and provides language specific support for attributes such as Field Labels, for the tJava component. There are a number of other Java Property Files, for example,
tJava_messages_fr.properties that provide support for different languages; however,
tJava_messages.properties is the only mandatory Java Property File.
This file provides textural information for the component, including field labels for the parameters.
The following shows the content of this file for the tJava component. The attributes of this file are in no particular order; however, I would encourage you to group and order these, to make this file more readable.
#Created by JInto - www.guh-software.de #Mon Feb 25 13:37:58 CST 2008 CODE.NAME=Code HELP=org.talend.help.tJava LONG_NAME=Allows to enter manually the start Java-code part of a component IMPORT.NAME=Import
The first two lines of the file provide comments, indicating the creator of the file and when it was created.
LONG_NAME specifies the description for your component and is ths shown when the mose hovers over the component, when displayed in the Component Palette.
IMPORT.NAME provide labels for the two parameters that are defined in the file
A simple but important file is the icon that will represent your component within Talend Studio. This is a 32x32 pixel image file in the PNG format. In the case of the component tJava component, this file is named
tJava_icon32.png. Without an icon file, you will not be able to push your own components to the Component Palette.
As discussed in other articles, each component requires between one and three JET template files. In the case of the tJava component, there is a single
begin file named
tJava_begin.javajet. The other files are
The following code shows the JET template for this component.
<%@ jet imports=" org.talend.core.model.process.INode org.talend.core.model.process.ElementParameterParser org.talend.designer.codegen.config.CodeGeneratorArgument " %> <% CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument; INode node = (INode)codeGenArgument.getArgument(); %> <%=ElementParameterParser.getValue(node, "__CODE__") %>
As can be seen from the code, this is pretty simple stuff. We'll discuss the majority of this code in a later article and it is standard code that you should find in all components. The important part, for our analysis of tJava is the line
<%=ElementParameterParser.getValue(node, "__CODE__") %>. This is a directive to JET, to emmit the code that was entered in the
PARAMETER that is named
NAME="CODE", as described in the section CODE, shown above.