Search in sources :

Example 6 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 7 with CodeGeneratorArgument

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

the class ContextPartGenerator method generatePart.

public CharSequence generatePart(IContext designerContext) throws CodeGeneratorException {
    List<IContextParameter> listParameters = designerContext.getContextParameterList();
    if (listParameters == null) {
        return "";
    }
    CodeGeneratorArgument codeGenArgument = argumentBuilder.build();
    codeGenArgument.setContextName(designerContext.getName());
    List<IContextParameter> listParametersCopy = tranformEncryptedParams(listParameters);
    codeGenArgument.setNode(listParametersCopy);
    JetBean jetBean = JetUtil.createJetBean(codeGenArgument);
    jetBean.setTemplateRelativeUri(ECamelTemplate.CONTEXT.getTemplateURL());
    return JetUtil.jetGenerate(jetBean);
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 8 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
     */
@Override
public String generateComponentCode(INode node, ECodePart part) throws CodeGeneratorException {
    CodeGeneratorArgument argument = new CodeGeneratorArgument();
    argument.setNode(node);
    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.setIsRunInMultiThread(getRunInMultiThread());
    argument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
    JetBean jetBean = initializeJetBean(argument);
    StringBuffer content = new StringBuffer();
    try {
        content.append(generateTypedComponentCode(EInternalTemplate.PART_HEADER, node, part));
        IComponentFileNaming componentFileNaming = ComponentsFactoryProvider.getFileNamingInstance();
        String templateURI = node.getComponent().getPathSource() + TemplateUtil.DIR_SEP + node.getComponent().getName() + TemplateUtil.DIR_SEP + componentFileNaming.getJetFileName(node.getComponent(), language.getExtension(), part);
        jetBean.setTemplateRelativeUri(templateURI);
        JetProxy proxy = new JetProxy(jetBean);
        content.append(proxy.generate());
        content.append(generateTypedComponentCode(EInternalTemplate.PART_FOOTER, node, part));
    } catch (JETException jetException) {
        log.error(jetException.getMessage(), jetException);
        throw new CodeGeneratorException(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) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 9 with CodeGeneratorArgument

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

the class CodeGenerator method initializeJetBean.

/**
     * Initialize Jet Bean to pass to the Jet Generator.
     * 
     * @param argument the node to convert
     * @return the initialized JetBean
     */
private JetBean initializeJetBean(Object argument) {
    JetBean jetBean = new JetBean();
    if (argument == null) {
        jetBean.setJetPluginRepository(CodeGeneratorActivator.PLUGIN_ID);
    } else {
        if (argument instanceof CodeGeneratorArgument) {
            CodeGeneratorArgument codeArgument = (CodeGeneratorArgument) argument;
            if (codeArgument.getArgument() instanceof INode) {
                String componentsPath = IComponentsFactory.COMPONENTS_LOCATION;
                IBrandingService breaningService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
                if (breaningService.isPoweredOnlyCamel()) {
                    componentsPath = IComponentsFactory.CAMEL_COMPONENTS_LOCATION;
                }
                jetBean.setJetPluginRepository(componentsPath);
            } else {
                jetBean.setJetPluginRepository(CodeGeneratorActivator.PLUGIN_ID);
            }
        } else {
            jetBean.setJetPluginRepository(CodeGeneratorActivator.PLUGIN_ID);
        }
    }
    jetBean.setArgument(argument);
    return jetBean;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) INode(org.talend.core.model.process.INode) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) IBrandingService(org.talend.core.ui.branding.IBrandingService)

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