use of org.talend.designer.codegen.exception.CodeGeneratorException in project tdi-studio-se by Talend.
the class CodeGenerator method generateProcessCode.
/**
* Generate the code for the process given to the constructor.
*
* @return the generated code
* @throws CodeGeneratorException if an error occurs during Code Generation
*/
@Override
@SuppressWarnings("unchecked")
public String generateProcessCode() throws CodeGeneratorException {
// Parse Process, generate Code for Individual Components
// generate Assembly Code for individual Components
StringBuffer componentsCode = new StringBuffer();
long startTimer = System.currentTimeMillis();
long endTimer = startTimer;
try {
while ((!CodeGeneratorEmittersPoolFactory.isInitialized()) && ((endTimer - startTimer) < INIT_TIMEOUT)) {
Thread.sleep(INIT_PAUSE);
endTimer = System.currentTimeMillis();
}
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
throw new CodeGeneratorException(e);
}
if ((endTimer - startTimer) > INIT_TIMEOUT) {
//$NON-NLS-1$
throw new CodeGeneratorException(Messages.getString("CodeGenerator.JET.TimeOut"));
} else {
// ####0005204: Cannot Call SubJob with RunJob Component
Vector headerArgument = new Vector(3);
headerArgument.add(process);
headerArgument.add(VersionUtils.getVersion());
componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER, headerArgument));
// ####
componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ADDITIONAL, headerArgument));
if ((processTree.getSubTrees() != null) && (processTree.getSubTrees().size() > 0)) {
boolean displayMethodSize = isMethodSizeNeeded();
for (NodesSubTree subTree : processTree.getSubTrees()) {
subTree.setMethodSizeNeeded(displayMethodSize);
if (!subTree.isMergeSubTree()) {
componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER, subTree));
componentsCode.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.BEGIN, null));
componentsCode.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.MAIN, null));
componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN, subTree.getRootNode()));
componentsCode.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.END, null));
StringBuffer finallyPart = new StringBuffer();
finallyPart.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.FINALLY, null));
Vector subprocess_footerArgument = new Vector(2);
subprocess_footerArgument.add(subTree);
subprocess_footerArgument.add(finallyPart.toString());
componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER, subprocess_footerArgument));
} else {
StringBuffer finallyPart = new StringBuffer();
componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER, subTree));
for (INode mergeNode : subTree.getMergeNodes()) {
componentsCode.append(generateComponentsCode(subTree, mergeNode, ECodePart.BEGIN, null));
}
List<INode> sortedMergeBranchStarts = subTree.getSortedMergeBranchStarts();
for (INode startNode : sortedMergeBranchStarts) {
componentsCode.append(generateComponentsCode(subTree, startNode, ECodePart.BEGIN, null));
componentsCode.append(generateComponentsCode(subTree, startNode, ECodePart.MAIN, null));
componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN, subTree.getRootNode()));
componentsCode.append(generateComponentsCode(subTree, startNode, ECodePart.END, null));
finallyPart.append(generateComponentsCode(subTree, startNode, ECodePart.FINALLY, null));
}
for (INode mergeNode : subTree.getMergeNodes()) {
componentsCode.append(generateComponentsCode(subTree, mergeNode, ECodePart.END, null));
finallyPart.append(generateComponentsCode(subTree, mergeNode, ECodePart.FINALLY, null));
}
Vector subprocess_footerArgument = new Vector(2);
subprocess_footerArgument.add(subTree);
subprocess_footerArgument.add(finallyPart.toString());
componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER, subprocess_footerArgument));
}
}
}
// ####0005204: Cannot Call SubJob with RunJob Component
Vector footerArgument = new Vector(2);
footerArgument.add(process);
footerArgument.add(processTree.getRootNodes());
componentsCode.append(generateTypedComponentCode(EInternalTemplate.FOOTER, footerArgument));
componentsCode.append(generateTypedComponentCode(EInternalTemplate.PROCESSINFO, componentsCode.length()));
// ####
return componentsCode.toString();
}
}
use of org.talend.designer.codegen.exception.CodeGeneratorException in project tesb-studio-se by Talend.
the class JetUtil method checkEmittersPoolFactoryIsReady.
public static void checkEmittersPoolFactoryIsReady() throws CodeGeneratorException {
long startTimer = System.currentTimeMillis();
long endTimer = startTimer;
try {
while (!CodeGeneratorEmittersPoolFactory.isInitialized() && (endTimer - startTimer) < INIT_TIMEOUT) {
Thread.sleep(INIT_PAUSE);
endTimer = System.currentTimeMillis();
}
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
throw new CodeGeneratorException(e);
}
if ((endTimer - startTimer) > INIT_TIMEOUT) {
//$NON-NLS-1$
throw new CodeGeneratorException(Messages.getString("CodeGenerator.JET.TimeOut"));
}
}
use of org.talend.designer.codegen.exception.CodeGeneratorException 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();
}
Aggregations