Search in sources :

Example 6 with JetBean

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

the class CodeGeneratorEmittersPoolFactory method getJETEmitter.

/**
     * DOC xtan Comment method "getJETEmitter".
     * 
     * @param jetBean
     * @return
     */
public static JETEmitter getJETEmitter(JetBean jetBean) {
    if (emitterPool == null || (!isInitialized() && !isInitializeStart())) {
        try {
            new CodeGeneratorManager().initTemplate();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // default_template.javajet
    if (jetBean.getTemplateRelativeUri() != null && !jetBean.getTemplateRelativeUri().startsWith("resources")) {
        //$NON-NLS-1$
        if (jetFilesCompileFail.contains(jetBean)) {
            JetBean defaultJetBean = new JetBean();
            defaultJetBean.setTemplateRelativeUri(defaultTemplate);
            return emitterPool.get(defaultJetBean);
        }
    }
    return emitterPool.get(jetBean);
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean)

Example 7 with JetBean

use of org.talend.designer.codegen.config.JetBean 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 8 with JetBean

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

the class JetUtil method createJetBean.

/**
	 * Initialize Jet Bean to pass to the Jet Generator.
	 * 
	 * @param argument
	 *            the node to convert
	 * @return the initialized JetBean
	 */
public static JetBean createJetBean(CodeGeneratorArgument argument) {
    final JetBean jetBean = new JetBean();
    jetBean.setArgument(argument);
    if (argument != null && argument.getArgument() instanceof INode) {
        INode node = (INode) argument.getArgument();
        String componentsPath = IComponentsFactory.COMPONENTS_LOCATION;
        IBrandingService breaningService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        if (breaningService.isPoweredOnlyCamel()) {
            componentsPath = IComponentsFactory.CAMEL_COMPONENTS_LOCATION;
        }
        jetBean.setJetPluginRepository(componentsPath);
        initTemplateRelativeUri(jetBean, node, argument.getCodePart());
    }
    if (jetBean.getJetPluginRepository() == null) {
        jetBean.setJetPluginRepository(Activator.getDefault().getBundle().getSymbolicName());
    }
    return jetBean;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) INode(org.talend.core.model.process.INode) IBrandingService(org.talend.core.ui.branding.IBrandingService)

Example 9 with JetBean

use of org.talend.designer.codegen.config.JetBean 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 10 with JetBean

use of org.talend.designer.codegen.config.JetBean 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

JetBean (org.talend.designer.codegen.config.JetBean)16 LightJetBean (org.talend.designer.codegen.config.LightJetBean)8 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)7 JETException (org.eclipse.emf.codegen.jet.JETException)5 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)3 IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)3 IBrandingService (org.talend.core.ui.branding.IBrandingService)3 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)3 HashMap (java.util.HashMap)2 BusinessException (org.talend.commons.exception.BusinessException)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 INode (org.talend.core.model.process.INode)2 TalendJetEmitter (org.talend.designer.codegen.config.TalendJetEmitter)2 TemplateUtil (org.talend.designer.codegen.config.TemplateUtil)2 JetProxy (org.talend.designer.codegen.proxy.JetProxy)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1