use of org.talend.designer.codegen.exception.CodeGeneratorException in project tdi-studio-se by Talend.
the class CodeGenerator method generateComponentCodeWithRows.
/*
* (non-Javadoc)
*
* @see org.talend.designer.codegen.ICodeGenerator#generateComponentCodeWithRows (java.lang.String,
* java.lang.Object)
*/
@Override
public String generateComponentCodeWithRows(String nodeName, IAloneProcessNodeConfigurer nodeConfigurer) {
StringBuffer componentsCode = new StringBuffer();
if (process == null) {
throw new NullPointerException();
} else {
INode nodeToConfigure = extractNodeFromProcess(nodeName);
if (nodeToConfigure != null) {
if (nodeConfigurer != null) {
nodeConfigurer.configure(nodeToConfigure);
}
Vector headerArgument = new Vector(2);
headerArgument.add(process);
headerArgument.add(VersionUtils.getVersion());
// not osgi export
headerArgument.add("false");
this.checkingSyntax = true;
try {
componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER, headerArgument));
componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ADDITIONAL, headerArgument));
for (NodesSubTree subTree : processTree.getSubTrees()) {
INode subTreeNode = subTree.getNode(nodeName);
// if (subTreeNode != null && nodeConfigurer != null) {
// nodeConfigurer.configure(subTreeNode);
// }
componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER, subTree));
StringBuffer finallyPart = new StringBuffer();
if (subTreeNode != null) {
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));
// componentsCode.append(
// generateTypedComponentCode
// (EInternalTemplate.SUBPROCESS_FOOTER,
// subTree));
finallyPart.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.FINALLY, null));
} else {
// 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(generateComponentsCode(subTree, startNode, ECodePart.END, null));
finallyPart.append(generateComponentsCode(subTree, startNode, ECodePart.FINALLY, null));
}
componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN, subTree.getRootNode()));
for (INode mergeNode : subTree.getMergeNodes()) {
componentsCode.append(generateComponentsCode(subTree, mergeNode, ECodePart.END, null));
finallyPart.append(generateComponentsCode(subTree, mergeNode, ECodePart.FINALLY, null));
}
// componentsCode.append(
// generateTypedComponentCode
// (EInternalTemplate.SUBPROCESS_FOOTER,
// subTree));
}
}
Vector subprocess_footerArgument = new Vector(2);
subprocess_footerArgument.add(subTree);
subprocess_footerArgument.add(finallyPart.toString());
componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER, subprocess_footerArgument));
}
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()));
} catch (CodeGeneratorException ce) {
// ce.printStackTrace();
ExceptionHandler.process(ce);
componentsCode = new StringBuffer();
}
} else {
//$NON-NLS-1$
throw new TypeNotPresentException(Messages.getString("CodeGenerator.Node.NotFound"), null);
}
}
return componentsCode.toString();
}
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
*/
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();
}
use of org.talend.designer.codegen.exception.CodeGeneratorException 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;
}
use of org.talend.designer.codegen.exception.CodeGeneratorException 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 "";
}
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();
}
}
Aggregations