命名Talend自定义组件 - 除tTutorialRow外不起作用

时间:2014-08-18 21:45:29

标签: java xml talend

我一直在关注"如何创建自定义组件"的Talend tutorial。如果我逐字地按照示例操作,我的文件命名如下并放在文件夹tTutorialRow内,教程可以正常工作:

tTutorialRow_java.xml
tTutorialRow_messages.properties
tTutorialRow_begin.javajet
tTutorialRow_main.javajet
tTutorialRow_end.javajet

这是使用以下代码:

tTutorialRow_java.xml:

<COMPONENT>
  <HEADER
    PLATEFORM="ALL"
    SERIAL=""
    VERSION="2.0"
    STATUS="ALPHA"

    COMPATIBILITY="ALL"
    AUTHOR="Talend"
    RELEASE_DATE="20070525A"
    STARTABLE="false"
  >
    <SIGNATURE/>
  </HEADER>

  <FAMILIES> 
    <FAMILY>Helium</FAMILY> 
  </FAMILIES> 

  <DOCUMENTATION>
    <URL/>
  </DOCUMENTATION>

  <CONNECTORS>
    <CONNECTOR CTYPE="FLOW" MAX_INPUT="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="ADDRESSES" FIELD="TABLE" REQUIRED="true" NUM_ROW="3" NB_LINES="5" SHOW="true">
      <ITEMS BASED_ON_SCHEMA="false">
        <ITEM NAME="USERNAME" />
        <ITEM NAME="DOMAIN" />
      </ITEMS>
    </PARAMETER>
  </PARAMETERS>

  <CODEGENERATION/>

  <RETURNS>
    <RETURN NAME="NB_LINE" TYPE="id_Integer" AVAILABILITY="AFTER"/>
  </RETURNS>

</COMPONENT>

tTutorialRow_messages.properties:

LONG_NAME=Tutorial component
HELP=org.talend.help.TutorialRow

NB_LINE.NAME=Number of lines
ADDRESSES.ITEM.USERNAME=Username
ADDRESSES.ITEM.DOMAIN=Domain
ADDRESSES.NAME=Addresses

tTutorialRow_begin.javajet:

<%@ jet 
    imports="
        org.talend.core.model.process.INode 
        org.talend.core.model.process.ElementParameterParser 
        org.talend.core.model.metadata.IMetadataTable 
        org.talend.core.model.metadata.IMetadataColumn 
        org.talend.core.model.process.IConnection
        org.talend.core.model.process.IConnectionCategory
        org.talend.designer.codegen.config.CodeGeneratorArgument
        org.talend.core.model.metadata.types.JavaTypesManager
        org.talend.core.model.metadata.types.JavaType
        java.util.List 
        java.util.Map       
    " 
%>
<% 
    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode)codeGenArgument.getArgument();
    String cid = node.getUniqueName();  
    List<Map<String, String>> lines = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__ADDRESSES__");
%> 
java.util.List<String> addresses_<%=cid %> = new java.util.ArrayList<String>();
<%
  for (int i=0; i<lines.size(); i++) {
    Map<String, String> line = lines.get(i);
%>
    addresses_<%=cid %>.add(<%= line.get("USERNAME") %> + "@" + <%= line.get("DOMAIN") %>);
<%
  }
%>
int nb_line_<%=cid %> = 0;

tTutorialRow_main.javajet:

<%@ jet 
    imports="
        org.talend.core.model.process.INode 
        org.talend.core.model.process.ElementParameterParser 
        org.talend.core.model.metadata.IMetadataTable 
        org.talend.core.model.metadata.IMetadataColumn 
        org.talend.core.model.process.IConnection
        org.talend.core.model.process.IConnectionCategory
        org.talend.designer.codegen.config.CodeGeneratorArgument
        org.talend.core.model.metadata.types.JavaTypesManager
        org.talend.core.model.metadata.types.JavaType
        java.util.List 
        java.util.Map       
    " 
%>
<% 
    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode)codeGenArgument.getArgument();
    String cid = node.getUniqueName();  
%>
    String[] adresses_<%=cid %> = addresses_<%=cid %>.toArray(new String[] {});

    System.out.print(nb_line_<%=cid %>++ + ": ");
    for (int i_<%=cid %> = 0; i_<%=cid %> < adresses_<%=cid %>.length; i_<%=cid %>++ )
    {
      System.out.print(adresses_<%=cid %>[i_<%=cid %>]);
      if (i_<%=cid %> < adresses_<%=cid %>.length-1) System.out.print(",");
    }   
    System.out.println();

tTutorialRow_end.javajet:

<%@ jet 
    imports="
        org.talend.core.model.process.INode 
        org.talend.core.model.process.ElementParameterParser 
        org.talend.core.model.metadata.IMetadataTable 
        org.talend.core.model.metadata.IMetadataColumn 
        org.talend.core.model.process.IConnection
        org.talend.core.model.process.IConnectionCategory
        org.talend.designer.codegen.config.CodeGeneratorArgument
        org.talend.core.model.metadata.types.JavaTypesManager
        org.talend.core.model.metadata.types.JavaType
        java.util.List 
        java.util.Map       
    " 
%>
<% 
    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode)codeGenArgument.getArgument();
    String cid = node.getUniqueName();  
%>   
    globalMap.put("<%=cid %>_NB_LINE",nb_line_<%=cid %>);

如果我更改文件名:

tTutorialRow_java.xml
tTutorialRow_messages.properties
tTutorialRow_begin.javajet
tTutorialRow_main.javajet
tTutorialRow_end.javajet

到:

myProject_java.xml
myProject_messages.properties
myProject_begin.javajet
myProject_main.javajet
myProject_end.javajet

并将文件夹名称更新为myProject,添加该组件不再有效。如何使用新名称添加组件?

谢谢!

1 个答案:

答案 0 :(得分:1)

答案是在Talend中包含自定义组件有某些命名细节/要求。

以下工作:

我必须在名为tProjectName的主文件夹中包含一个文件夹,其中包含:

tProjectName_begin.javajet
tProjectName_end.javajet
tProjectName_icon32.png
tProjectName_java.xml
tProjectName_main.javajet
tProjectName_message.properties

这些文件根本不需要在此stackoverflow问题的问题部分的格式中进行更改。