use of org.talend.designer.codegen.config.CodeGeneratorArgument 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.config.CodeGeneratorArgument in project tesb-studio-se by Talend.
the class ContextPartGenerator method generatePart.
public CharSequence generatePart(IContext designerContext) throws CodeGeneratorException {
List<IContextParameter> listParameters = designerContext.getContextParameterList();
if (listParameters == null) {
return "";
}
CodeGeneratorArgument codeGenArgument = argumentBuilder.build();
codeGenArgument.setContextName(designerContext.getName());
List<IContextParameter> listParametersCopy = tranformEncryptedParams(listParameters);
codeGenArgument.setNode(listParametersCopy);
JetBean jetBean = JetUtil.createJetBean(codeGenArgument);
jetBean.setTemplateRelativeUri(ECamelTemplate.CONTEXT.getTemplateURL());
return JetUtil.jetGenerate(jetBean);
}
use of org.talend.designer.codegen.config.CodeGeneratorArgument 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.CodeGeneratorArgument 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