Search in sources :

Example 1 with NodesSubTree

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

the class TemplatePartGenerator method generateDefaultTypedComponentCode.

private CharSequence generateDefaultTypedComponentCode(ECamelTemplate template, Object... params) throws CodeGeneratorException {
    Object argument = null;
    if (params.length > 0) {
        argument = params[0];
    }
    ECodePart part = null;
    String incomingName = null;
    NodesSubTree subProcess = null;
    if (params.length > 1) {
        for (int i = 1; i < params.length; i++) {
            if (params[i] instanceof ECodePart) {
                part = (ECodePart) params[i];
            } else if (params[i] instanceof String) {
                incomingName = (String) params[i];
            } else if (params[i] instanceof NodesSubTree) {
                subProcess = (NodesSubTree) params[i];
            }
        }
    }
    return generateTypedComponentCode(template, argument, part, incomingName, subProcess);
}
Also used : NodesSubTree(org.talend.designer.codegen.config.NodesSubTree) ECodePart(org.talend.core.model.temp.ECodePart)

Example 2 with NodesSubTree

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

the class ProcessPartBuilder method appendContent.

@Override
public AbstractProcessPartBuilder appendContent() throws CodeGeneratorException {
    appendTyped(ECamelTemplate.HEADER_ROUTE);
    if (hasSubTrees()) {
        for (NodesSubTree subTree : sortedFilteredSubTrees) {
            appendSubTree(subTree);
        }
    }
    appendTyped(ECamelTemplate.FOOTER_ROUTE);
    appendTyped(ECamelTemplate.PROCESSINFO);
    return this;
}
Also used : NodesSubTree(org.talend.designer.codegen.config.NodesSubTree)

Example 3 with NodesSubTree

use of org.talend.designer.codegen.config.NodesSubTree 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();
}
Also used : INode(org.talend.core.model.process.INode) NodesSubTree(org.talend.designer.codegen.config.NodesSubTree) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) Vector(java.util.Vector)

Example 4 with NodesSubTree

use of org.talend.designer.codegen.config.NodesSubTree 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();
    }
}
Also used : INode(org.talend.core.model.process.INode) NodesSubTree(org.talend.designer.codegen.config.NodesSubTree) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) Vector(java.util.Vector)

Aggregations

NodesSubTree (org.talend.designer.codegen.config.NodesSubTree)4 Vector (java.util.Vector)2 INode (org.talend.core.model.process.INode)2 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)2 ECodePart (org.talend.core.model.temp.ECodePart)1