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);
}
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);
}
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;
}
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();
}
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;
}
Aggregations