Search in sources :

Example 1 with JetProxy

use of org.talend.designer.codegen.proxy.JetProxy 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 2 with JetProxy

use of org.talend.designer.codegen.proxy.JetProxy in project tdi-studio-se by Talend.

the class CodeGenerator method instantiateJetProxy.

private StringBuffer instantiateJetProxy(JetBean jetBean) throws CodeGeneratorException {
    JetProxy proxy = new JetProxy(jetBean);
    StringBuffer content = new StringBuffer();
    try {
        content.append(proxy.generate());
    } catch (JETException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    } catch (CoreException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    }
    return content;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 3 with JetProxy

use of org.talend.designer.codegen.proxy.JetProxy in project tesb-studio-se by Talend.

the class JetUtil method jetGenerate.

public static String jetGenerate(JetBean jetBean) throws CodeGeneratorException {
    JetProxy proxy = new JetProxy(jetBean);
    try {
        String codePart = proxy.generate();
        String generationError = jetBean.getGenerationError();
        if (generationError != null) {
            throw new CodeGeneratorException(generationError);
        }
        return codePart;
    } catch (JETException e) {
        log.error(e.getMessage(), e);
        CodeGeneratorArgument argument = (CodeGeneratorArgument) jetBean.getArgument();
        throw new CodeGeneratorException(e + " in " + argument.getJobName() + " route", e);
    } catch (CoreException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    }
}
Also used : 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 4 with JetProxy

use of org.talend.designer.codegen.proxy.JetProxy 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)

Aggregations

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)4 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)3 IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)2 JetBean (org.talend.designer.codegen.config.JetBean)2 IComponent (org.talend.core.model.components.IComponent)1