Search in sources :

Example 1 with CodeGeneratorArgument

use of org.talend.designer.codegen.config.CodeGeneratorArgument in project tdi-studio-se by Talend.

the class CodeGenerator method generateTypedComponentCode.

/**
     * Generate Code Part for a given Component.
     * 
     * @param type the internal component template
     * @param argument the bean
     * @param part part of code to generate
     * @param subProcess
     * @return the genrated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
private StringBuffer generateTypedComponentCode(EInternalTemplate type, Object argument, ECodePart part, String incomingName, NodesSubTree subProcess) throws CodeGeneratorException {
    CodeGeneratorArgument codeGenArgument = new CodeGeneratorArgument();
    codeGenArgument.setNode(argument);
    if (subProcess != null) {
        codeGenArgument.setAllMainSubTreeConnections(subProcess.getAllMainSubTreeConnections());
        codeGenArgument.setSubTree(subProcess);
    }
    codeGenArgument.setCodePart(part);
    codeGenArgument.setStatistics(statistics);
    codeGenArgument.setTrace(trace);
    codeGenArgument.setInterpreterPath(interpreterPath);
    codeGenArgument.setLibPath(libPath);
    codeGenArgument.setRuntimeFilePath(runtimeFilePath);
    codeGenArgument.setCurrentProjectName(currentProjectName);
    codeGenArgument.setContextName(contextName);
    codeGenArgument.setJobName(jobName);
    codeGenArgument.setJobVersion(jobVersion);
    codeGenArgument.setCheckingSyntax(checkingSyntax);
    codeGenArgument.setIncomingName(incomingName);
    codeGenArgument.setIsRunInMultiThread(getRunInMultiThread());
    codeGenArgument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
    JetBean jetBean = initializeJetBean(codeGenArgument);
    StringBuffer content = new StringBuffer();
    for (TemplateUtil template : CodeGeneratorInternalTemplatesFactoryProvider.getInstance().getTemplatesFromType(type)) {
        jetBean.setJetPluginRepository(template.getJetPluginRepository());
        jetBean.setTemplateRelativeUri(template.getTemplateRelativeUri());
        content.append(instantiateJetProxy(jetBean));
    }
    return content;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument)

Example 2 with CodeGeneratorArgument

use of org.talend.designer.codegen.config.CodeGeneratorArgument in project tdi-studio-se by Talend.

the class CodeGenerator method generateComponentCode.

/**
     * Generate Part Code for a given Component.
     * 
     * @param node the component
     * @param part the component's part
     * @return the generated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
public String generateComponentCode(NodesSubTree subProcess, INode node, ECodePart part, String incomingName, ETypeGen typeGen) throws CodeGeneratorException {
    CodeGeneratorArgument argument = new CodeGeneratorArgument();
    argument.setNode(node);
    argument.setAllMainSubTreeConnections(subProcess.getAllMainSubTreeConnections());
    argument.setCodePart(part);
    argument.setStatistics(statistics);
    argument.setTrace(trace);
    argument.setInterpreterPath(interpreterPath);
    argument.setLibPath(libPath);
    argument.setRuntimeFilePath(runtimeFilePath);
    argument.setCurrentProjectName(currentProjectName);
    argument.setContextName(contextName);
    argument.setJobName(jobName);
    argument.setJobVersion(jobVersion);
    argument.setCheckingSyntax(checkingSyntax);
    argument.setIncomingName(incomingName);
    argument.setIsRunInMultiThread(getRunInMultiThread());
    argument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
    JetBean jetBean = initializeJetBean(argument);
    StringBuffer content = new StringBuffer();
    try {
        if (typeGen == ETypeGen.ETL) {
            content.append(generateTypedComponentCode(EInternalTemplate.PART_HEADER, node, part, incomingName, subProcess));
        }
        IComponentFileNaming componentFileNaming = ComponentsFactoryProvider.getFileNamingInstance();
        IComponent component = node.getComponent();
        String templateURI = component.getPathSource() + TemplateUtil.DIR_SEP + node.getComponent().getName() + TemplateUtil.DIR_SEP + componentFileNaming.getJetFileName(node.getComponent(), language.getExtension(), part);
        // Need rewrite templateURI for generic component since create a new JetBean .
        if (EComponentType.GENERIC.equals(component.getComponentType())) {
            templateURI = TemplateUtil.JET_STUB_DIRECTORY + TemplateUtil.DIR_SEP + TemplateUtil.RESOURCES_DIRECTORY_GENERIC + TemplateUtil.DIR_SEP + "component_" + //$NON-NLS-1$
            part.getName() + TemplateUtil.EXT_SEP + language.getExtension() + TemplateUtil.TEMPLATE_EXT;
        }
        jetBean.setTemplateRelativeUri(templateURI);
        JetProxy proxy = new JetProxy(jetBean);
        content.append(proxy.generate());
        if (jetBean.getGenerationError() != null) {
            throw new CodeGeneratorException(jetBean.getGenerationError());
        }
        if (typeGen == ETypeGen.ETL) {
            content.append(generateTypedComponentCode(EInternalTemplate.PART_FOOTER, node, part, incomingName, subProcess));
        }
    } catch (JETException jetException) {
        log.error(jetException.getMessage(), jetException);
        throw new CodeGeneratorException(//$NON-NLS-1$
        jetException.toString() + " in " + argument.getJobName() + " job", //$NON-NLS-1$
        jetException);
    } catch (CoreException coreException) {
        log.error(coreException.getMessage(), coreException);
        throw new CodeGeneratorException(coreException);
    }
    return content.toString();
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) IComponentFileNaming(org.talend.core.model.components.IComponentFileNaming) CoreException(org.eclipse.core.runtime.CoreException) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) IComponent(org.talend.core.model.components.IComponent) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 3 with CodeGeneratorArgument

use of org.talend.designer.codegen.config.CodeGeneratorArgument in project tdi-studio-se by Talend.

the class CodeGenerator method generateContextCode.

/**
     * Parse Process, and generate Code for Context Variables.
     * 
     * @param designerContext the context to generate code from
     * @return the generated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
@Override
public String generateContextCode(IContext designerContext) throws CodeGeneratorException {
    if (process != null) {
        if (designerContext == null) {
            designerContext = process.getContextManager().getDefaultContext();
        }
        List<IContextParameter> listParameters = designerContext.getContextParameterList();
        if (listParameters != null) {
            List<IContextParameter> listParametersCopy = new ArrayList<IContextParameter>(listParameters.size());
            CodeGeneratorArgument codeGenArgument = new CodeGeneratorArgument();
            // encrypt the password
            for (IContextParameter iContextParameter : listParameters) {
                if (PasswordEncryptUtil.isPasswordType(iContextParameter.getType())) {
                    IContextParameter icp = iContextParameter.clone();
                    String pwd = icp.getValue();
                    if (pwd != null && !pwd.isEmpty()) {
                        try {
                            icp.setValue(PasswordEncryptUtil.encryptPasswordHex(pwd));
                        } catch (Exception e) {
                            log.error(e.getMessage(), e);
                        }
                    }
                    listParametersCopy.add(icp);
                } else {
                    listParametersCopy.add(iContextParameter);
                }
            }
            codeGenArgument.setNode(listParametersCopy);
            codeGenArgument.setContextName(designerContext.getName());
            codeGenArgument.setCurrentProjectName(currentProjectName);
            codeGenArgument.setJobName(jobName);
            codeGenArgument.setJobVersion(jobVersion);
            codeGenArgument.setIsRunInMultiThread(getRunInMultiThread());
            codeGenArgument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
            JetBean jetBean = initializeJetBean(codeGenArgument);
            StringBuffer content = new StringBuffer();
            for (TemplateUtil template : CodeGeneratorInternalTemplatesFactoryProvider.getInstance().getTemplatesFromType(EInternalTemplate.CONTEXT)) {
                jetBean.setJetPluginRepository(template.getJetPluginRepository());
                jetBean.setTemplateRelativeUri(template.getTemplateRelativeUri());
                content.append(instantiateJetProxy(jetBean));
            }
            return content.toString();
        }
    }
    //$NON-NLS-1$
    return "";
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) CoreException(org.eclipse.core.runtime.CoreException) JETException(org.eclipse.emf.codegen.jet.JETException) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException)

Example 4 with CodeGeneratorArgument

use of org.talend.designer.codegen.config.CodeGeneratorArgument in project tesb-studio-se by Talend.

the class TemplatePartGenerator method generateTypedComponentCode.

/**
	 * Generate Code Part for a given Component.
	 * 
	 * @param type
	 *            the internal component template
	 * @param argument
	 *            the bean
	 * @param part
	 *            part of code to generate
	 * @param subProcess
	 * @return the genrated code
	 * @throws CodeGeneratorException
	 *             if an error occurs during Code Generation
	 */
private CharSequence generateTypedComponentCode(ECamelTemplate type, Object argument, ECodePart part, String incomingName, NodesSubTree subProcess) throws CodeGeneratorException {
    CodeGeneratorArgument codeGenArgument = argumentBuilder.build();
    codeGenArgument.setNode(argument);
    if (subProcess != null) {
        codeGenArgument.setAllMainSubTreeConnections(subProcess.getAllMainSubTreeConnections());
        codeGenArgument.setSubTree(subProcess);
    }
    codeGenArgument.setCodePart(part);
    codeGenArgument.setIncomingName(incomingName);
    JetBean jetBean = JetUtil.createJetBean(codeGenArgument);
    jetBean.setTemplateRelativeUri(type.getTemplateURL());
    return JetUtil.jetGenerate(jetBean);
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument)

Example 5 with CodeGeneratorArgument

use of org.talend.designer.codegen.config.CodeGeneratorArgument in project tesb-studio-se by Talend.

the class NodePartBuilder method appendContent.

@Override
public NodePartBuilder appendContent() throws CodeGeneratorException {
    CodeGeneratorArgument argument = manager.getArgumentBuilder().build();
    argument.setNode(node);
    if (subTree != null) {
        argument.setAllMainSubTreeConnections(subTree.getAllMainSubTreeConnections());
        argument.setSubTree(subTree);
    }
    argument.setCodePart(part);
    argument.setIncomingName(incomingName);
    append(JetUtil.jetGenerate(argument));
    return this;
}
Also used : CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument)

Aggregations

CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)9 JetBean (org.talend.designer.codegen.config.JetBean)7 CoreException (org.eclipse.core.runtime.CoreException)4 JETException (org.eclipse.emf.codegen.jet.JETException)4 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)4 JetProxy (org.talend.designer.codegen.proxy.JetProxy)3 IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 TemplateUtil (org.talend.designer.codegen.config.TemplateUtil)2 ArrayList (java.util.ArrayList)1 IComponent (org.talend.core.model.components.IComponent)1 INode (org.talend.core.model.process.INode)1 IBrandingService (org.talend.core.ui.branding.IBrandingService)1