org.ourbeehive.mbp.builder.OprImplBuilder.java Source code

Java tutorial

Introduction

Here is the source code for org.ourbeehive.mbp.builder.OprImplBuilder.java

Source

/**
 * Copyright (C) 2015-2016 OurBeehive(http://ourbeehive.github.io/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * Project Name: MyBatisPioneer
 * File Name: OprImplBuilder.java
 * Package Name: org.ourbeehive.mbp.builder
 * 
 * Date: Jan 20, 2016
 * Author: Sericloud
 * 
 */

package org.ourbeehive.mbp.builder;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.ourbeehive.mbp.exception.AppException;
import org.ourbeehive.mbp.lang.GlobalConst;
import org.ourbeehive.mbp.lang.JavaSrcElm;
import org.ourbeehive.mbp.model.OrmAttr;
import org.ourbeehive.mbp.model.OrmClass;
import org.ourbeehive.mbp.model.OrmMethod;
import org.ourbeehive.mbp.model.OrmOpr;
import org.ourbeehive.mbp.model.ant.MapperProfile;
import org.ourbeehive.mbp.model.ant.OprBatchMethod;
import org.ourbeehive.mbp.model.ant.OprConfig;
import org.ourbeehive.mbp.model.ant.OprMethod;
import org.ourbeehive.mbp.model.ant.SingleMapperProfile;
import org.ourbeehive.mbp.register.CtxCacheFacade;
import org.ourbeehive.mbp.util.ExceptionUtil;
import org.ourbeehive.mbp.util.JavaFormatter;
import org.ourbeehive.mbp.util.MapperFormatter;
import org.ourbeehive.mbp.util.StringHelper;

public class OprImplBuilder {

    private static String REQUIRE = "require";
    private static String IF_REQUIRE = "ifRequire";
    private static String NOT_REQUIRE = "notRequire";

    private static String USER_NAME = "userInfo.getIpAcctLoginName()";
    private static String OPERATION_TIME = "DateUtils.currentTimestamp()";

    private static String CRT_BY = "setCrtBy(" + USER_NAME + ")";
    private static String CRT_TM = "setCrtTm(" + OPERATION_TIME + ")";
    private static String UPD_BY = "setUpdBy(" + USER_NAME + ")";
    private static String UPD_TM = "setUpdTm(" + OPERATION_TIME + ")";

    private static String EDIT_FLAG_DELETED = "setEditFlag(CatSysCode.RevisionDeleted.cd())";
    private static String EDIT_FLAG_NEW = "setEditFlag(CatSysCode.RevisionNew.cd())";
    private static String RELS_NBR = "setRelsNbr(GlobalConstant.DEFAULT_RELEASE_NUMER)";

    // \n( )*\n
    private static String REGEX_REMOVE_LINES = JavaSrcElm.LINE_SEPARATOR + JavaSrcElm.LEFT_PARENTHESIS
            + JavaSrcElm.WHITE_SPACE + JavaSrcElm.RIGHT_PARENTHESIS + JavaSrcElm.ASTERISK
            + JavaSrcElm.LINE_SEPARATOR;

    private static String PARAM_TIMES = "times";
    private static String PARAM_INDEX = "index";
    private static String PARAM_SUB_LIST = "subList";

    private static Logger logger = Logger.getLogger(OprImplBuilder.class);
    private static OprImplBuilder oprImplBuilder;

    private OprImplBuilder() {
    }

    public synchronized static OprImplBuilder getInstance() {

        if (oprImplBuilder == null) {
            oprImplBuilder = new OprImplBuilder();
        }

        return oprImplBuilder;

    }

    public void buildOprImpl(MapperProfile mapperProfile) throws AppException {
        //      buildAllMethods(mapperProfile);

        // add by Yuan.Bin
        buildAllSaveMethod(mapperProfile);
        buildAllUpdMethod(mapperProfile);
        buildAllDefunctMethod(mapperProfile);
        buildAllDelMethod(mapperProfile);
        buildAllSaveBatchMethod(mapperProfile);
    }

    public String exportOprImpl(OrmClass ormClass) {

        // Content of current class entity.
        StringBuffer srcCode = new StringBuffer();

        // Export the package statement.
        srcCode.append(BuilderHelper.exportPackage(ormClass.getPkgName()));
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        // Export the import statement.
        srcCode.append(exportImport(ormClass.getImportList()));
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        // Export the annotation statement.
        srcCode.append(BuilderHelper.exportAnnot(ormClass));

        // Export type and name.
        srcCode.append(BuilderHelper.exportName(ormClass, true));

        // Export implements or extends.
        srcCode.append(BuilderHelper.exportSuperCls(ormClass));

        // Append opening brace.
        srcCode.append(BuilderHelper.exportOpeningBrace());

        // Export fields.
        srcCode.append(exportAllAttrs(ormClass.getSimpleName(), ormClass.getAttrList()));

        // Build implicit constructor.
        // srcCode.append(BuilderHelper.exportImplicitConstructor(ormClass));

        // Build constructor.
        // srcCode.append(exportExplicitConstructor(ormClass));

        // Build setter of sqlMapClient.
        // srcCode.append(exportSqlMapClientSetter());

        // Export methods.
        srcCode.append(exportAllMethods(ormClass.getMethodList()));

        // Close the class
        srcCode.append(GlobalConst.LINE_SEPARATOR);
        srcCode.append(JavaSrcElm.RIGHT_BRACKET);

        return srcCode.toString();

    }

    private void buildAllSaveMethod(MapperProfile mapperProfile) throws AppException {
        try {
            List<SingleMapperProfile> singleMapperProfileList = mapperProfile.getSingleMapperProfile();
            for (SingleMapperProfile singleMapperProfile : singleMapperProfileList) {
                // Handle every single "addDtoConfig" element.
                List<OprConfig> oprConfigList = singleMapperProfile.getOprConfig();
                for (OprConfig oprConfig : oprConfigList) {
                    List<OprMethod> saveMethodConfigList = oprConfig.getSaveMethod();
                    for (OprMethod saveMethodConfig : saveMethodConfigList) {
                        logger.info("OPR INTF: Handle \"opr saveMethodConfig\" with methodName \""
                                + saveMethodConfig.getMethodName() + "\".");
                        buildSaveMethod(mapperProfile, oprConfig, saveMethodConfig);
                    }
                }
            }
        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildAllUpdMethod(MapperProfile mapperProfile) throws AppException {
        try {
            List<SingleMapperProfile> singleMapperProfileList = mapperProfile.getSingleMapperProfile();
            for (SingleMapperProfile singleMapperProfile : singleMapperProfileList) {
                // Handle every single "addDtoConfig" element.
                List<OprConfig> oprConfigList = singleMapperProfile.getOprConfig();
                for (OprConfig oprConfig : oprConfigList) {
                    List<OprMethod> updMethodConfigList = oprConfig.getUpdMethod();
                    for (OprMethod updMethodConfig : updMethodConfigList) {
                        logger.info("OPR INTF: Handle \"opr updMethodConfig\" with methodName \""
                                + updMethodConfig.getMethodName() + "\".");
                        buildUpdMethod(mapperProfile, oprConfig, updMethodConfig);
                    }
                }
            }
        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildAllDefunctMethod(MapperProfile mapperProfile) throws AppException {
        try {
            List<SingleMapperProfile> singleMapperProfileList = mapperProfile.getSingleMapperProfile();
            for (SingleMapperProfile singleMapperProfile : singleMapperProfileList) {
                // Handle every single "addDtoConfig" element.
                List<OprConfig> oprConfigList = singleMapperProfile.getOprConfig();
                for (OprConfig oprConfig : oprConfigList) {
                    List<OprMethod> defunctMethodConfigList = oprConfig.getDefunctMethod();
                    for (OprMethod defunctMethodConfig : defunctMethodConfigList) {
                        logger.info("OPR INTF: Handle \"opr defunctMethodConfig\" with methodName \""
                                + defunctMethodConfig.getMethodName() + "\".");
                        buildDefunctMethod(mapperProfile, oprConfig, defunctMethodConfig);
                    }
                }
            }
        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildAllDelMethod(MapperProfile mapperProfile) throws AppException {
        try {
            List<SingleMapperProfile> singleMapperProfileList = mapperProfile.getSingleMapperProfile();
            for (SingleMapperProfile singleMapperProfile : singleMapperProfileList) {
                // Handle every single "addDtoConfig" element.
                List<OprConfig> oprConfigList = singleMapperProfile.getOprConfig();
                for (OprConfig oprConfig : oprConfigList) {
                    List<OprMethod> delMethodConfigList = oprConfig.getDelMethod();
                    for (OprMethod delMethodConfig : delMethodConfigList) {
                        logger.info("OPR INTF: Handle \"opr delMethodConfig\" with methodName \""
                                + delMethodConfig.getMethodName() + "\".");
                        buildDelMethod(mapperProfile, oprConfig, delMethodConfig);
                    }
                }
            }
        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildAllSaveBatchMethod(MapperProfile mapperProfile) throws AppException {
        try {
            List<SingleMapperProfile> singleMapperProfileList = mapperProfile.getSingleMapperProfile();
            for (SingleMapperProfile singleMapperProfile : singleMapperProfileList) {
                // Handle every single "addDtoConfig" element.
                List<OprConfig> oprConfigList = singleMapperProfile.getOprConfig();
                for (OprConfig oprConfig : oprConfigList) {
                    List<OprBatchMethod> saveBatchMethodConfigList = oprConfig.getSaveBatchMethod();
                    for (OprBatchMethod saveBatchMethodConfig : saveBatchMethodConfigList) {
                        logger.info("OPR INTF: Handle \"opr saveBatchMethodConfig\" with methodName \""
                                + saveBatchMethodConfig.getMethodName() + "\".");
                        buildSaveBatchMethod(mapperProfile, oprConfig, saveBatchMethodConfig);
                    }
                }
            }
        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildSaveMethod(MapperProfile mapperProfile, OprConfig oprConfig, OprMethod saveMethodConfig)
            throws AppException {
        try {
            String methodName = saveMethodConfig.getMethodName();

            // Register a OPR method.
            List<String> paramTypeList = new ArrayList<String>();
            String dtoClassName = oprConfig.getDtoClassName();
            paramTypeList.add(dtoClassName);
            paramTypeList.add(JavaSrcElm.USER_INFO_FULL);
            String comments = saveMethodConfig.getComments();
            CtxCacheFacade.addOprImplMethod(mapperProfile, saveMethodConfig, methodName, dtoClassName,
                    paramTypeList, JavaSrcElm.VOID, comments, JavaSrcElm.CRUD_TYPE_SAVE);

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildUpdMethod(MapperProfile mapperProfile, OprConfig oprConfig, OprMethod updMethodConfig)
            throws AppException {
        try {
            String methodName = updMethodConfig.getMethodName();

            // Register a OPR method.
            List<String> paramTypeList = new ArrayList<String>();
            String dtoClassName = oprConfig.getDtoClassName();
            paramTypeList.add(dtoClassName);
            paramTypeList.add(JavaSrcElm.USER_INFO_FULL);
            String comments = updMethodConfig.getComments();
            CtxCacheFacade.addOprImplMethod(mapperProfile, updMethodConfig, methodName, dtoClassName, paramTypeList,
                    JavaSrcElm.VOID, comments, JavaSrcElm.CRUD_TYPE_UPDATE);

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildDefunctMethod(MapperProfile mapperProfile, OprConfig oprConfig, OprMethod defunctMethodConfig)
            throws AppException {
        try {
            String methodName = defunctMethodConfig.getMethodName();

            // Register a OPR method.
            List<String> paramTypeList = new ArrayList<String>();
            String dtoClassName = oprConfig.getDtoClassName();
            paramTypeList.add(dtoClassName);
            paramTypeList.add(JavaSrcElm.USER_INFO_FULL);
            String comments = defunctMethodConfig.getComments();
            CtxCacheFacade.addOprImplMethod(mapperProfile, defunctMethodConfig, methodName, dtoClassName,
                    paramTypeList, JavaSrcElm.VOID, comments, JavaSrcElm.CRUD_TYPE_DEFUNCT);

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }

    }

    private void buildDelMethod(MapperProfile mapperProfile, OprConfig oprConfig, OprMethod delMethodConfig)
            throws AppException {
        try {
            String methodName = delMethodConfig.getMethodName();

            // Register a OPR method.
            List<String> paramTypeList = new ArrayList<String>();
            String dtoClassName = oprConfig.getDtoClassName();
            paramTypeList.add(dtoClassName);
            String comments = delMethodConfig.getComments();
            CtxCacheFacade.addOprImplMethod(mapperProfile, delMethodConfig, methodName, dtoClassName, paramTypeList,
                    JavaSrcElm.VOID, comments, JavaSrcElm.CRUD_TYPE_DELETE);

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }

    private void buildSaveBatchMethod(MapperProfile mapperProfile, OprConfig oprConfig,
            OprBatchMethod saveBatchMethodConfig) throws AppException {
        try {
            String methodName = saveBatchMethodConfig.getMethodName();

            // Register a OPR method.
            List<String> paramTypeList = new ArrayList<String>();
            String voClassName = saveBatchMethodConfig.getVoClassName();
            paramTypeList
                    .add(JavaSrcElm.UTIL_LIST_FULL + JavaSrcElm.LESS_THAN + voClassName + JavaSrcElm.GREATER_THAN);
            paramTypeList.add(JavaSrcElm.LANG_INTEGER_FULL);
            paramTypeList.add(JavaSrcElm.USER_INFO_FULL);
            String comments = saveBatchMethodConfig.getComments();
            CtxCacheFacade.addOprImplMethod(mapperProfile, null, methodName, oprConfig.getDtoClassName(),
                    paramTypeList, JavaSrcElm.VOID, comments, JavaSrcElm.CRUD_TYPE_SAVE_BATCH);

        } catch (Throwable t) {
            ExceptionUtil.handleException(t, logger);
        }
    }
    //   private void buildAllMethods(MapperProfile mapperProfile) throws AppException {
    //
    //      try {
    //
    //         List<SingleMapperProfile> singleMapperProfileList = mapperProfile.getSingleMapperProfile();
    //         for (SingleMapperProfile singleMapperProfile : singleMapperProfileList) {
    //
    //            // Handle every single "addDtoConfig" element.
    //            List<InsertConfig> addDtoConfigList = singleMapperProfile.getAddDtoConfig();
    //            String methodName = null;
    //            List<String> paramTypeList = null;
    //            String dtoClassName = null;
    //            String comments = null;
    //            for (InsertConfig addDtoConfig : addDtoConfigList) {
    //
    //               logger.info("OPR IMPL: Handle \"addDtoConfig\" with class \"" + addDtoConfig.getClassName() + "\".");
    //               // Get the 'methodName' according to the type of DTO.
    //               methodName = MapperFormatter.getAddDtoMethodName(addDtoConfig);
    //
    //               // Register a OPR method.
    //               paramTypeList = new ArrayList<String>();
    //               dtoClassName = addDtoConfig.getClassName();
    //               paramTypeList.add(dtoClassName);
    //               comments = addDtoConfig.getComments();
    //               CtxCacheFacade.addOprImplMethod(mapperProfile, methodName, dtoClassName, paramTypeList, JavaSrcElm.VOID, comments);
    //
    //            }
    //
    //            // Handle every single "addDtoConfig" element.
    //            List<UpdateConfig> updStatConfigList = singleMapperProfile.getUpdStatConfig();
    //            for (UpdateConfig updStatConfig : updStatConfigList) {
    //
    //               logger.info("OPR IMPL: Handle \"updStatConfig\" with class \"" + updStatConfig.getClassName() + "\".");
    //               // Get the 'methodName' according to the type of DTO.
    //               methodName = MapperFormatter.getChgByPKMethodName(updStatConfig);
    //
    //               // Register a OPR method.
    //               paramTypeList = new ArrayList<String>();
    //               dtoClassName = updStatConfig.getClassName();
    //               paramTypeList.add(dtoClassName);
    //               comments = updStatConfig.getComments();
    //               CtxCacheFacade.addOprImplMethod(mapperProfile, methodName, dtoClassName, paramTypeList, JavaSrcElm.VOID, comments);
    //
    //            }
    //
    //            // Handle every single "addDtoConfig" element.
    //            List<UpdateConfig> delByPKConfigList = singleMapperProfile.getDelByPKConfig();
    //            for (UpdateConfig delByPKConfig : delByPKConfigList) {
    //
    //               logger.info("OPR: Handle \"delByPKConfig\" with class \"" + delByPKConfig.getClassName() + "\".");
    //               // Get the 'methodName' according to the type of DTO.
    //               methodName = MapperFormatter.getDelByPKMethodName(delByPKConfig);
    //
    //               // Register a OPR method.
    //               paramTypeList = new ArrayList<String>();
    //               dtoClassName = delByPKConfig.getClassName();
    //               paramTypeList.add(dtoClassName);
    //               comments = delByPKConfig.getComments();
    //               CtxCacheFacade.addOprImplMethod(mapperProfile, methodName, dtoClassName, paramTypeList, JavaSrcElm.VOID, comments);
    //
    //            }
    //
    //            // Handle every single "addDtoConfig" element.
    //            List<UpdateConfig> delBySqlConfigList = singleMapperProfile.getDelBySqlConfig();
    //            for (UpdateConfig delBySqlConfig : delBySqlConfigList) {
    //
    //               logger.info("OPR: Handle \"delBySqlConfig\" with class \"" + delBySqlConfig.getClassName() + "\".");
    //               // Get the 'methodName' according to the type of DTO.
    //               methodName = MapperFormatter.getDelBySqlMethodName(delBySqlConfig);
    //
    //               // Register a OPR method.
    //               paramTypeList = new ArrayList<String>();
    //               dtoClassName = delBySqlConfig.getClassName();
    //               paramTypeList.add(dtoClassName);
    //               comments = delBySqlConfig.getComments();
    //               CtxCacheFacade.addOprImplMethod(mapperProfile, methodName, dtoClassName, paramTypeList, JavaSrcElm.VOID, comments);
    //
    //            }
    //
    //         }
    //
    //      } catch (Throwable t) {
    //         ExceptionUtil.handleException(t, logger);
    //      }
    //
    //   }

    private String exportImport(List<String> importList) {

        StringBuffer srcCode = new StringBuffer();

        srcCode.append(JavaSrcElm.IMPORT);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.LOG4J_LOGGER_FULL);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);
        srcCode.append(JavaSrcElm.IMPORT);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.SPRING_AUTOWIRED);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);
        srcCode.append(JavaSrcElm.IMPORT);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.SPRING_COMPONENT);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        srcCode.append(JavaSrcElm.IMPORT);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.GLOBAL_CONSTANT);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        srcCode.append(JavaSrcElm.IMPORT);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.DATE_UTILS);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        srcCode.append(JavaSrcElm.IMPORT);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.CAT_SYS_CODE);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        int importListSize = importList.size();
        if (importListSize == 0) {
            return srcCode.toString();
        }

        for (int i = 0; i < importListSize; i++) {
            srcCode.append(JavaSrcElm.IMPORT);
            srcCode.append(JavaSrcElm.WHITE_SPACE);
            srcCode.append(importList.get(i).toString());
            srcCode.append(JavaSrcElm.SEMICOLON);
            srcCode.append(GlobalConst.LINE_SEPARATOR);
            // if (i == importListSize - 1) {
            // srcCode.append(GlobalConst.LINE_SEPARATOR);
            // }
        }

        return srcCode.toString();

    }

    private String exportAllAttrs(String className, List<OrmAttr> attrList) {

        StringBuffer srcCode = new StringBuffer();
        // Add 'private static final long serialVersionUID = 1257330972265L;'
        OrmAttr ormAttr = new OrmAttr();
        //      ormAttr.setModifier(JavaSrcElm.PRIVATE_STATIC_FINAL);
        //      ormAttr.setDataType(JavaSrcElm.LONG);
        //      ormAttr.setName(JavaSrcElm.SERIAL_VERSION_UID);
        //      ormAttr.setDefaultValue(1 + JavaSrcElm.LONG_SUFFIX);
        //      attrList.add(ormAttr);

        // Add 'private static Log logger = LogFactory.getLog(XXX.class);'
        ormAttr = new OrmAttr();
        ormAttr.setModifier(JavaSrcElm.PRIVATE_STATIC);
        ormAttr.setDataType(JavaSrcElm.LOG4J_LOGGER_SIMPLE);
        ormAttr.setName(JavaSrcElm.LOG4J_LOGGER_OBJ);
        ormAttr.setDefaultValue(JavaSrcElm.LOG4J_LOGGER_GETLOGGER + JavaSrcElm.LEFT_PARENTHESIS + className
                + JavaSrcElm.ATTR_CLASS + JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(exportAttr(ormAttr));

        // Add 'protected SqlMapClient sqlMapClient;'
        // ormAttr = new OrmAttr();
        // ormAttr.setModifier(JavaSrcElm.PROTECTED);
        // ormAttr.setDataType(JavaSrcElm.SQLMAP_CLT_CLASS);
        // ormAttr.setName(JavaSrcElm.SQLMAP_CLT_OBJ);
        // attrList.add(ormAttr);

        srcCode.append(GlobalConst.LINE_SEPARATOR);
        int attrListSize = attrList.size();
        for (int i = 0; i < attrListSize; i++) {
            ormAttr = attrList.get(i);
            srcCode.append(exportAttr(ormAttr));
        }

        return srcCode.toString();

    }

    private String exportAttr(OrmAttr ormAttr) {

        StringBuffer srcCode = new StringBuffer();
        String indents = BuilderHelper.exportIndents();

        //add annotations
        List<String> annotList = ormAttr.getAnnotList();
        if (annotList.size() > 0) {
            for (String anno : annotList) {
                srcCode.append(indents);
                srcCode.append(anno);
                srcCode.append(GlobalConst.LINE_SEPARATOR);
            }
        }

        srcCode.append(indents);
        srcCode.append(ormAttr.getModifier());
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(ormAttr.getDataType());
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(ormAttr.getName());
        if (ormAttr.getDefaultValue() != null) {
            srcCode.append(JavaSrcElm.EQUAL);
            srcCode.append(ormAttr.getDefaultValue());
        }
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        return srcCode.toString();

    }

    // private String exportExplicitConstructor(OrmClass ormClass) {
    //
    // StringBuffer srcCode = new StringBuffer();
    // String indents = BuilderHelper.exportIndents();
    //
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // srcCode.append(indents);
    // srcCode.append(JavaSrcElm.PUBLIC);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(ormClass.getSimpleName());
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_CLASS);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_OBJ);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(BuilderHelper.exportOpeningBracket());
    // srcCode.append(indents);
    // srcCode.append(indents);
    // srcCode.append(JavaSrcElm.THIS);
    // srcCode.append(JavaSrcElm.DOT);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_OBJ);
    // srcCode.append(JavaSrcElm.EQUAL);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_OBJ);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // srcCode.append(BuilderHelper.exportClosingBracket(indents));
    //
    // return srcCode.toString();
    //
    // }

    // private String exportSqlMapClientSetter() {
    //
    // StringBuffer srcCode = new StringBuffer();
    // String indents = BuilderHelper.exportIndents();
    //
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // srcCode.append(indents);
    // srcCode.append(JavaSrcElm.PUBLIC);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.VOID);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.SET);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_CLASS);
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_CLASS);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_OBJ);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(BuilderHelper.exportOpeningBracket());
    // srcCode.append(indents);
    // srcCode.append(indents);
    // srcCode.append(JavaSrcElm.THIS);
    // srcCode.append(JavaSrcElm.DOT);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_OBJ);
    // srcCode.append(JavaSrcElm.EQUAL);
    // // srcCode.append(JavaSrcElm.SQLMAP_CLT_OBJ);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // srcCode.append(BuilderHelper.exportClosingBracket(indents));
    //
    // return srcCode.toString();
    //
    // }

    private String exportAllMethods(List<OrmMethod> methodList) {

        StringBuffer srcCode = new StringBuffer();

        int methodListSize = methodList.size();
        if (methodListSize == 0) {
            return srcCode.toString();
        }

        OrmMethod ormMethod = null;
        for (int i = 0; i < methodListSize; i++) {

            ormMethod = methodList.get(i);
            srcCode.append(exportMethod(ormMethod));

        }

        return srcCode.toString();
    }

    private String exportMethod(OrmMethod ormMethod) {

        // Add the mandatory exception.
        // ormMethod.getExceptionList().add(JavaSrcElm.APP_EXCEPTION_SIMPLE);

        StringBuffer srcCode = new StringBuffer();
        String indents = BuilderHelper.exportIndents();

        // Process the method modifiers, return value and name.
        String returnType = ormMethod.getReturnType();
        String methodName = ormMethod.getName();

        srcCode.append(GlobalConst.LINE_SEPARATOR);

        // Process the comments, method modifiers, return value and name.
        String comments = ormMethod.getComments();
        if (StringUtils.isNotBlank(comments) == true) {
            srcCode.append(indents);
            srcCode.append(JavaSrcElm.SLASH);
            srcCode.append(JavaSrcElm.SLASH);
            srcCode.append(JavaSrcElm.WHITE_SPACE);
            srcCode.append(comments);
            srcCode.append(GlobalConst.LINE_SEPARATOR);
        }

        // add annotations
        List<String> annotList = ormMethod.getAnnotList();
        if (annotList.size() > 0) {
            for (String anno : annotList) {
                srcCode.append(indents);
                srcCode.append(anno);
                srcCode.append(GlobalConst.LINE_SEPARATOR);
            }
        }

        srcCode.append(indents);
        // if (methodName.startsWith(MapperElm.SQL_SELECT) == true && methodName.endsWith(MapperElm.MAPPER_BYSQL) == true) {
        // srcCode.append(JavaSrcElm.SUPPRESS_WARNINGS);
        // srcCode.append(GlobalConst.LINE_SEPARATOR);
        // srcCode.append(indents);
        // }
        srcCode.append(JavaSrcElm.PUBLIC);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        if (StringUtils.isNotBlank(returnType) == true) {
            srcCode.append(returnType);
            srcCode.append(JavaSrcElm.WHITE_SPACE);
        }
        srcCode.append(methodName);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);

        // Process parameters.
        List<String> parameterList = ormMethod.getParameterList();
        int paramListSize = parameterList.size();

        if (paramListSize != 0) {
            for (int i = 0; i < paramListSize; i++) {
                if (paramListSize >= JavaSrcElm.MAX_NUM_OF_PARAM) {
                    if (i > 0) {
                        srcCode.append(JavaSrcElm.COMMA);
                    }
                    srcCode.append(GlobalConst.LINE_SEPARATOR);
                    srcCode.append(indents);
                    srcCode.append(indents);
                } else {
                    if (i > 0) {
                        srcCode.append(JavaSrcElm.COMMA);
                        srcCode.append(JavaSrcElm.WHITE_SPACE);
                    }
                }
                srcCode.append(parameterList.get(i));
                srcCode.append(JavaSrcElm.WHITE_SPACE);
                srcCode.append(JavaFormatter.getAttributeName((parameterList.get(i))));
            }
        }

        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);

        // Process exceptions.
        List<String> exceptionList = ormMethod.getExceptionList();
        int expListSize = exceptionList.size();
        StringBuffer allExeptions = new StringBuffer();

        if (expListSize != 0) {
            allExeptions.append(JavaSrcElm.THROWS);
            allExeptions.append(JavaSrcElm.WHITE_SPACE);
            for (int i = 0; i < expListSize; i++) {
                if (i > 0) {
                    allExeptions.append(JavaSrcElm.COMMA);
                    allExeptions.append(JavaSrcElm.WHITE_SPACE);
                }

                allExeptions.append(exceptionList.get(i));
            }
        }

        // Begin with new line if current line has exceeded the limit.
        MapperFormatter.checkWidth(srcCode, JavaSrcElm.WHITE_SPACE, 3);
        srcCode.append(allExeptions.toString());

        // Process method body.
        srcCode.append(BuilderHelper.exportOpeningBracket());
        srcCode.append(exportMethodBody(ormMethod));
        srcCode.append(BuilderHelper.exportClosingBracket());

        return srcCode.toString();

    }

    //   private String exportMethodBody(OrmMethod ormMethod) {

    // Invoke the corresponding method exporter according to their names.
    //      StringBuffer srcCode = new StringBuffer();
    // String methodName = ormMethod.getName();

    //      srcCode.append(GlobalConst.LINE_SEPARATOR);
    // if (methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_INSERT) == true
    // || methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_INSERT_SELECTIVE) == true) {
    //
    // buildInsert(ormMethod, srcCode);
    //
    // } else if (methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_UPD_BYPK) == true
    // || methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_UPD_BYPK_SELECTIVE) == true
    // || methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_UPD_BYSQL) == true
    // || methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_UPD_BYSQL_SELECTIVE) == true) {
    //
    // buildUpdate(method, srcCode);
    //
    // } else if (methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_UPD_BYPK_TM) == true
    // || methodType.equalsIgnoreCase(SqlMapGenConstant.STATEMENT_UPD_BYPK_SELECTIVE_TM) == true) {
    // buildUpdateWithTmLck(method, srcCode);
    // } else if (methodType.startsWith(SqlMapGenConstant.STATEMENT_COUNT) == true) {
    //
    // buildCountBySqlClause(method, srcCode);
    //
    // } else if (methodType.startsWith(SqlMapGenConstant.STATEMENT_SELECT) == true
    // && methodType.endsWith(SqlMapGenConstant.STATEMENT_SELECT_BYPK) == true) {
    //
    // buildSelectByPK(ormMethod, srcCode);
    //
    // } else if (methodType.startsWith(SqlMapGenConstant.STATEMENT_SELECT) == true
    // && methodType.endsWith(SqlMapGenConstant.STATEMENT_SELECT_BYSQL) == true) {
    //
    // buildSelectBySqlClause(method, srcCode);
    //
    // }

    //      return srcCode.toString();

    //   }

    // private void buildInsert(OrmMethod ormMethod, StringBuffer srcCode) {
    //
    // String indents = buildIndents();
    // StringBuffer line = new StringBuffer();
    // StringBuffer phrase = new StringBuffer();
    // String methodName = ormormMethod.getName();
    //
    // // New line for "try {".
    // srcCode.append(buildOpeningTry(indents + indents));
    //
    // // New line for "sqlMapClient.insert...".
    // // line.delete(0, line.length());
    // // phrase.delete(0, line.length());
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.SQLMAP_CLT_INSERT);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(ormormMethod.getBody().get(methodName));
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.PARAM_PREFIX + 0);
    // phrase.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // phrase.append(JavaSrcElm.SEMICOLON);
    // SqlMapFormatter.judgeNewLine(line, "", phrase.toString(), 4);
    // srcCode.append(line);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "catch (Throwable t) {".
    // srcCode.append(buildCatchThrowable(indents + indents));
    // // New line for "logger.error".
    // srcCode.append(buildLoggerError(indents + indents + indents, JavaSrcElm.FAIL_TO_CREATE_RECORD));
    // // New line for "throw new ...".
    // srcCode.append(buildThrowNewException(indents + indents + indents, JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE, JavaSrcElm.FAIL_TO_CREATE_RECORD));
    // // New line for closing catch.
    // srcCode.append(buildClosingBracket(indents + indents));
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // srcCode.append(buildClosingBracket(indents));
    //
    // }
    //
    // private void buildUpdate(OrmMethod method, StringBuffer srcCode) {
    //
    // String indents = buildIndents();
    // StringBuffer line = new StringBuffer();
    // StringBuffer phrase = new StringBuffer();
    // String methodName = ormMethod.getName();
    //
    // // New line for "int result = 0;"
    // srcCode.append(indents + indents);
    // srcCode.append(JavaSrcElm.INT);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.RESULT);
    // srcCode.append(JavaSrcElm.INT_INIT);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "try {".
    // srcCode.append(buildOpeningTry(indents + indents));
    // // New line for "result = ...".
    // // line.delete(0, line.length());
    // // phrase.delete(0, line.length());
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.RESULT);
    // line.append(JavaSrcElm.EQUAL);
    // line.append(JavaSrcElm.SQLMAP_CLT_UPD);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(ormMethod.getBody().get(methodName));
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.PARAM_PREFIX + 0);
    // phrase.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // phrase.append(JavaSrcElm.SEMICOLON);
    // SqlMapFormatter.judgeNewLine(line, "", phrase.toString(), 4);
    // srcCode.append(line);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "catch (Throwable t) {".
    // srcCode.append(buildCatchThrowable(indents + indents));
    // // New line for "logger.error".
    // srcCode.append(buildLoggerError(indents + indents + indents, JavaSrcElm.FAIL_TO_UPDATE_RECORES));
    // // New line for "throw new ...".
    // srcCode.append(buildThrowNewException(indents + indents + indents, JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE, JavaSrcElm.FAIL_TO_UPDATE_RECORES));
    // // New line for closing catch.
    // srcCode.append(buildClosingBracket(indents + indents));
    // // New line for "return result;".
    // srcCode.append(buildReturnResult(indents + indents));
    // srcCode.append(buildClosingBracket(indents));
    //
    // }
    //
    // /**
    // * update with time locker
    // *
    // * @param method
    // * @param srcCode
    // */
    // private void buildUpdateWithTmLck(OrmMethod method, StringBuffer srcCode) {
    //
    // String indents = buildIndents();
    // StringBuffer line = new StringBuffer();
    // StringBuffer phrase = new StringBuffer();
    // String methodName = ormMethod.getName();
    //
    // // New line for "int result = 0;"
    // srcCode.append(indents + indents);
    // srcCode.append(JavaSrcElm.INT);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.RESULT);
    // srcCode.append(JavaSrcElm.INT_INIT);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "try {".
    // srcCode.append(buildOpeningTry(indents + indents));
    // // New line for "result = ...".
    // // line.delete(0, line.length());
    // // phrase.delete(0, line.length());
    //
    // // line.append("Map<String, Object> map = new HashMap<String, Object>();\n");
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.UTIL_MAP_SIMPLE);
    // line.append(JavaSrcElm.SMALLER_THAN);
    // line.append(JavaSrcElm.STRING);
    // line.append(JavaSrcElm.COMMA);
    // line.append(JavaSrcElm.WHITE_SPACE);
    // line.append(JavaSrcElm.LANG_OBJECT_SIMPLE);
    // line.append(JavaSrcElm.LARGER_THAN);
    // line.append(JavaSrcElm.WHITE_SPACE);
    // line.append(JavaSrcElm.VAR_NAME_MAP);
    // line.append(JavaSrcElm.EQUAL);
    // line.append(JavaSrcElm.NEW);
    // line.append(JavaSrcElm.WHITE_SPACE);
    // line.append(JavaSrcElm.UTIL_HASHMAP_SIMPLE);
    // line.append(JavaSrcElm.SMALLER_THAN);
    // line.append(JavaSrcElm.STRING);
    // line.append(JavaSrcElm.COMMA);
    // line.append(JavaSrcElm.WHITE_SPACE);
    // line.append(JavaSrcElm.LANG_OBJECT_SIMPLE);
    // line.append(JavaSrcElm.LARGER_THAN);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // line.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // line.append(JavaSrcElm.SEMICOLON);
    // line.append(GlobalConst.LINE_SEPARATOR);
    //
    // // line.append("map.put(\"oldDTO\", param0);\n");
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.VAR_NAME_MAP);
    // line.append(JavaSrcElm.DOT);
    // line.append(JavaSrcElm.PUT);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // line.append(JavaSrcElm.DOUBLE_QUOTATION);
    // line.append(JavaSrcElm.VAR_NAME_OLDDTO);
    // line.append(JavaSrcElm.DOUBLE_QUOTATION);
    // line.append(JavaSrcElm.COMMA);
    // line.append(JavaSrcElm.PARAM_PREFIX + "0");
    // line.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // line.append(JavaSrcElm.SEMICOLON);
    // line.append(GlobalConst.LINE_SEPARATOR);
    //
    // // line.append("map.put(\"newDTO\", param1);\n");
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.VAR_NAME_MAP);
    // line.append(JavaSrcElm.DOT);
    // line.append(JavaSrcElm.PUT);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // line.append(JavaSrcElm.DOUBLE_QUOTATION);
    // line.append(JavaSrcElm.VAR_NAME_NEWDTO);
    // line.append(JavaSrcElm.DOUBLE_QUOTATION);
    // line.append(JavaSrcElm.COMMA);
    // line.append(JavaSrcElm.PARAM_PREFIX + "1");
    // line.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // line.append(JavaSrcElm.SEMICOLON);
    // line.append(GlobalConst.LINE_SEPARATOR);
    //
    // // result = sqlMapClient.update("META.BED.updateByPK", map);
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.RESULT);
    // line.append(JavaSrcElm.EQUAL);
    // line.append(JavaSrcElm.SQLMAP_CLT_UPD);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(ormMethod.getBody().get(methodName));
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.VAR_NAME_MAP);
    // phrase.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // phrase.append(JavaSrcElm.SEMICOLON);
    // SqlMapFormatter.judgeNewLine(line, "", phrase.toString(), 4);
    // srcCode.append(line);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // srcCode.append("if (0 == result) {   \n");
    // srcCode.append(indents + indents + indents);
    // srcCode.append(JavaSrcElm.IF);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.ZERO);
    // srcCode.append(JavaSrcElm.DOUBLE_EQUAL);
    // srcCode.append(JavaSrcElm.RESULT);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.LEFT_BRACKET);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // // srcCode.append("throw new DateOutTimeException();\n");
    // // srcCode.append(indents + indents + indents + indents);
    // // srcCode.append(JavaSrcElm.THROW_NEW);
    // // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // // srcCode.append(JavaSrcElm.DATEOUTTIME_EXCEPTION_SIMPLE);
    // // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // // srcCode.append(JavaSrcElm.SEMICOLON);
    // // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // String expCode = FrameworkMsgCode.DATA_IS_EXPIRED;
    // srcCode.append(indents + indents + indents + indents);
    // srcCode.append(JavaSrcElm.VAR_EXP_CODE_DEF);
    // srcCode.append(JavaSrcElm.EQUAL);
    // srcCode.append(JavaSrcElm.DATA_IS_EXPIRED);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // String expMsg = ResourceReader.getEncodedString(expCode);
    // srcCode.append(indents + indents + indents + indents);
    // srcCode.append(JavaSrcElm.VAR_EXP_MSG_DEF);
    // srcCode.append(JavaSrcElm.EQUAL);
    // srcCode.append(JavaSrcElm.RSRC_READER_GET_STR);
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.VAR_EXP_CODE_REF);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // logger.error(expMsg);
    // srcCode.append(indents + indents + indents + indents);
    // srcCode.append(JavaSrcElm.LOGGER_ERROR);
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.VAR_EXP_MSG_REF);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // throw new PerstncException(expCode);
    // srcCode.append(indents + indents + indents + indents);
    // srcCode.append(JavaSrcElm.THROW_NEW);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE);
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.VAR_EXP_CODE_REF);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // srcCode.append("}\n");
    // srcCode.append(indents + indents + indents);
    // srcCode.append(JavaSrcElm.RIGHT_BRACKET);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // } catch (PerstncException ex) {
    // srcCode.append(indents + indents);
    // srcCode.append(JavaSrcElm.RIGHT_BRACKET);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.CATCH);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.PARAM_EX);
    // srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.LEFT_BRACKET);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // throw ex;
    // srcCode.append(indents + indents + indents);
    // srcCode.append(JavaSrcElm.THROW);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.PARAM_EX);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // // New line for "} catch (Throwable t) {".
    // srcCode.append(buildCatchThrowable(indents + indents));
    // // New line for "logger.error".
    // srcCode.append(buildLoggerError(indents + indents + indents, JavaSrcElm.FAIL_TO_UPDATE_RECORES));
    // // New line for "throw new ...".
    // srcCode.append(buildThrowNewException(indents + indents + indents, JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE, JavaSrcElm.FAIL_TO_UPDATE_RECORES));
    // // New line for closing catch.
    // srcCode.append(buildClosingBracket(indents + indents));
    // // New line for "return result;".
    // srcCode.append(buildReturnResult(indents + indents));
    // srcCode.append(buildClosingBracket(indents));
    //
    // }
    //
    // private void buildCountBySqlClause(OrmMethod method, StringBuffer srcCode) {
    //
    // String indents = buildIndents();
    // StringBuffer line = new StringBuffer();
    // StringBuffer phrase = new StringBuffer();
    // String methodName = ormMethod.getName();
    //
    // // New line for "[Return Type] = null;"
    // srcCode.append(indents + indents);
    // srcCode.append(JavaSrcElm.LANG_INTEGER_SIMPLE);
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.RESULT);
    // srcCode.append(JavaSrcElm.EQUAL);
    // srcCode.append(JavaSrcElm.NULL);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "try {".
    // srcCode.append(buildOpeningTry(indents + indents));
    // // New line for "result = ...".
    // // line.delete(0, line.length());
    // // phrase.delete(0, line.length());
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.RESULT);
    // line.append(JavaSrcElm.EQUAL);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // line.append(JavaSrcElm.LANG_INTEGER_SIMPLE);
    // line.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // line.append(JavaSrcElm.WHITE_SPACE);
    // line.append(JavaSrcElm.SQLMAP_CLT_QUERY_FOR_OBJ);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(ormMethod.getBody().get(methodName));
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.PARAM_PREFIX + 0);
    // phrase.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // phrase.append(JavaSrcElm.SEMICOLON);
    // SqlMapFormatter.judgeNewLine(line, "", phrase.toString(), 4);
    // srcCode.append(line);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "catch (Throwable t) {".
    // srcCode.append(buildCatchThrowable(indents + indents));
    // // New line for "logger.error".
    // srcCode.append(buildLoggerError(indents + indents + indents, JavaSrcElm.FAIL_TO_RETRIEVE_RECORDS));
    // // New line for "throw new ...".
    // srcCode.append(buildThrowNewException(indents + indents + indents, JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE, JavaSrcElm.FAIL_TO_RETRIEVE_RECORDS));
    // // New line for closing catch.
    // srcCode.append(buildClosingBracket(indents + indents));
    // // New line for "return result;".
    // srcCode.append(buildReturnResult(indents + indents));
    // srcCode.append(buildClosingBracket(indents));
    //
    // }
    //
    // private void buildSelectByPK(OrmMethod method, StringBuffer srcCode) {
    //
    // String indents = buildIndents();
    // StringBuffer line = new StringBuffer();
    // StringBuffer phrase = new StringBuffer();
    // String methodName = ormMethod.getName();
    //
    // // New line for "[Return Type] = null;"
    // srcCode.append(indents + indents);
    // srcCode.append(ormMethod.getReturnType());
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.RESULT);
    // srcCode.append(JavaSrcElm.EQUAL);
    // srcCode.append(JavaSrcElm.NULL);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "try {".
    // srcCode.append(buildOpeningTry(indents + indents));
    // // New line for "result = ...".
    // // line.delete(0, line.length());
    // // phrase.delete(0, line.length());
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.RESULT);
    // line.append(JavaSrcElm.EQUAL);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // line.append(ormMethod.getReturnType());
    // line.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // line.append(JavaSrcElm.WHITE_SPACE);
    // line.append(JavaSrcElm.SQLMAP_CLT_QUERY_FOR_OBJ);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(ormMethod.getBody().get(methodName));
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.PARAM_PREFIX + 0);
    // phrase.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // phrase.append(JavaSrcElm.SEMICOLON);
    // SqlMapFormatter.judgeNewLine(line, "", phrase.toString(), 4);
    // srcCode.append(line);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "catch (Throwable t) {".
    // srcCode.append(buildCatchThrowable(indents + indents));
    // // New line for "logger.error".
    // srcCode.append(buildLoggerError(indents + indents + indents, JavaSrcElm.FAIL_TO_RETRIEVE_RECORDS));
    // // New line for "throw new ...".
    // srcCode.append(buildThrowNewException(indents + indents + indents, JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE, JavaSrcElm.FAIL_TO_RETRIEVE_RECORDS));
    // // New line for closing catch.
    // srcCode.append(buildClosingBracket(indents + indents));
    // // New line for "return result;".
    // srcCode.append(buildReturnResult(indents + indents));
    // srcCode.append(buildClosingBracket(indents));
    //
    // }
    //
    // private void buildSelectBySqlClause(OrmMethod method, StringBuffer srcCode) {
    //
    // String indents = buildIndents();
    // StringBuffer line = new StringBuffer();
    // StringBuffer phrase = new StringBuffer();
    // String ormMethodName = ormormMethod.getName();
    //
    // // New line for "[Return Type] = null;"
    // srcCode.append(indents + indents);
    // srcCode.append(ormormMethod.getReturnType());
    // srcCode.append(JavaSrcElm.WHITE_SPACE);
    // srcCode.append(JavaSrcElm.RESULT);
    // srcCode.append(JavaSrcElm.EQUAL);
    // srcCode.append(JavaSrcElm.NULL);
    // srcCode.append(JavaSrcElm.SEMICOLON);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "try {".
    // srcCode.append(buildOpeningTry(indents + indents));
    // // New line for "result = ...".
    // // line.delete(0, line.length());
    // // phrase.delete(0, line.length());
    // line.append(indents + indents + indents);
    // line.append(JavaSrcElm.RESULT);
    // line.append(JavaSrcElm.EQUAL);
    // line.append(JavaSrcElm.SQLMAP_CLT_QUERY_FOR_LIST);
    // line.append(JavaSrcElm.LEFT_PARENTHESIS);
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(ormormMethod.getBody().get(ormMethodName));
    // phrase.append(JavaSrcElm.DOUBLE_QUOTATION);
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.PARAM_PREFIX + 0);
    //
    // for (int i = 1; i < ormormMethod.getParameterList().size(); i++) {
    // phrase.append(JavaSrcElm.COMMA);
    // phrase.append(JavaSrcElm.WHITE_SPACE);
    // phrase.append(JavaSrcElm.PARAM_PREFIX + i);
    // }
    //
    // phrase.append(JavaSrcElm.RIGHT_PARENTHESIS);
    // phrase.append(JavaSrcElm.SEMICOLON);
    // SqlMapFormatter.judgeNewLine(line, "", phrase.toString(), 4);
    // srcCode.append(line);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // // New line for "catch (Throwable t) {".
    // srcCode.append(buildCatchThrowable(indents + indents));
    // // New line for "logger.error".
    // srcCode.append(buildLoggerError(indents + indents + indents, JavaSrcElm.FAIL_TO_RETRIEVE_RECORDS));
    // // New line for "throw new ...".
    // srcCode.append(buildThrowNewException(indents + indents + indents, JavaSrcElm.PERSTNC_EXCEPTION_SIMPLE, JavaSrcElm.FAIL_TO_RETRIEVE_RECORDS));
    // // New line for closing catch.
    // srcCode.append(buildClosingBracket(indents + indents));
    // // New line for "return result;".
    // srcCode.append(buildReturnResult(indents + indents));
    // srcCode.append(buildClosingBracket(indents));
    //
    // }

    /**
     * @param indents
     *            The extra indents should be added.
     * @return java.lang.String
     */
    // private String buildElseIf(String indents) {
    //
    // StringBuffer srcCode = new StringBuffer();
    //
    // if (indents == null) {
    // indents = new String();
    // }
    //
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    // srcCode.append(indents);
    // srcCode.append("else if ");
    // srcCode.append(JavaSrcElm.LEFT_BRACKET);
    // srcCode.append(GlobalConst.LINE_SEPARATOR);
    //
    // return srcCode.toString();
    //
    // }

    private String exportOpeningTry(String indents) {

        if (indents == null) {
            indents = new String();
        }

        StringBuffer srcCode = new StringBuffer();

        srcCode.append(indents);
        srcCode.append(JavaSrcElm.TRY);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.LEFT_BRACKET);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        return srcCode.toString();

    }

    private String exportCatchThrowable(String indents) {

        if (indents == null) {
            indents = new String();
        }

        StringBuffer srcCode = new StringBuffer();

        srcCode.append(indents);
        srcCode.append(JavaSrcElm.RIGHT_BRACKET);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.CATCH);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(JavaSrcElm.THROABLE);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.LEFT_BRACKET);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        return srcCode.toString();

    }

    private String exportLoggerError(String indents, String expCode) {

        StringBuffer srcCode = new StringBuffer();

        srcCode.append(indents);
        srcCode.append(JavaSrcElm.VAR_EXP_CODE_DEF);
        srcCode.append(JavaSrcElm.EQUAL);
        srcCode.append(expCode);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        srcCode.append(indents);
        srcCode.append(JavaSrcElm.VAR_EXP_MSG_DEF);
        srcCode.append(JavaSrcElm.EQUAL);
        srcCode.append(JavaSrcElm.RSRC_READER_GET_STR);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(JavaSrcElm.VAR_EXP_CODE_REF);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        srcCode.append(indents);
        srcCode.append(JavaSrcElm.LOGGER_ERROR);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(JavaSrcElm.VAR_EXP_MSG_REF);
        srcCode.append(JavaSrcElm.COMMA);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.PARAM_T);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        return srcCode.toString();

    }

    private String exportThrowNewException(String indents, String exp, String expCode) {

        if (indents == null) {
            indents = new String();
        }

        StringBuffer srcCode = new StringBuffer();

        srcCode.append(indents);
        srcCode.append(JavaSrcElm.THROW_NEW);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(exp);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(JavaSrcElm.VAR_EXP_CODE_REF);
        srcCode.append(JavaSrcElm.COMMA);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.PARAM_T);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        return srcCode.toString();

    }

    private String exportReturnResult(String indents) {

        if (indents == null) {
            indents = new String();
        }

        StringBuffer srcCode = new StringBuffer();

        srcCode.append(GlobalConst.LINE_SEPARATOR);
        srcCode.append(indents);
        srcCode.append(JavaSrcElm.RETURN);
        srcCode.append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.RESULT);
        srcCode.append(JavaSrcElm.SEMICOLON);
        srcCode.append(GlobalConst.LINE_SEPARATOR);

        return srcCode.toString();

    }

    /**
     * export body of method
     * @param ormMethod
     * @return
     */
    private String exportMethodBody(OrmMethod ormMethod) {

        // Invoke the corresponding method exporter according to their names.
        StringBuffer srcCode = new StringBuffer();
        String oprBlock = null;
        String indents = BuilderHelper.exportIndents();
        String crudType = ormMethod.getCrudType();
        if (JavaSrcElm.CRUD_TYPE_SAVE_BATCH.equals(crudType)) {
            oprBlock = exportSaveBatchMethod(ormMethod);
            srcCode.append(rectifyContent(oprBlock, indents));
        } else if (JavaSrcElm.CRUD_TYPE_DELETE_BATCH.equals(crudType)) {
            oprBlock = exportDelBatchMethod(ormMethod);
        } else if (JavaSrcElm.CRUD_TYPE_UPDATE_BATCH.equals(crudType)) {
            oprBlock = exportUpdBatchMethod(ormMethod);
        } else {
            // normal operation
            oprBlock = dealWithOrmPor(ormMethod, ormMethod.getOrmOprList(), null).toString();
            srcCode.append(rectifyContent(oprBlock, ""));
        }

        srcCode.append(JavaSrcElm.LINE_SEPARATOR);

        return srcCode.toString().replaceFirst(REGEX_REMOVE_LINES, JavaSrcElm.LINE_SEPARATOR);
    }

    /**
     * deal with ormPor, generate java code
     * @param ormMethod
     * @param ormOprList
     * @param father
     * @return
     */
    private StringBuffer dealWithOrmPor(OrmMethod ormMethod, List<OrmOpr> ormOprList, OrmOpr father) {

        StringBuffer srcCode = new StringBuffer();
        if (ormOprList == null || ormOprList.size() == 0) {
            return srcCode;
        }
        String indents = BuilderHelper.exportIndents();
        List<String> list = ormMethod.getParameterList();
        if (list == null || list.isEmpty()) {
            return srcCode;
        }

        // **dtox
        String ormName = "";
        for (String name : list) {
            if (name.endsWith(JavaSrcElm.DTOX_NAME_SUFFIX)) {
                ormName = getOprAttributeName(name);
            }
        }

        srcCode.append(GlobalConst.LINE_SEPARATOR);

        for (OrmOpr target : ormOprList) {
            String oprType = target.getOprType(); // attribute operation type

            // exclude the not required attribute
            if (oprType.equals(NOT_REQUIRE)) {
                continue;
            }

            StringBuffer content = new StringBuffer();
            String targetName = target.getTargetObjName();
            String targetClass = target.getTargetObjClassName();
            String left = generateGetAttribute(ormName, targetName, false).toString();

            String fatherAttr = target.getFatherAttrName();
            String sonAttr = target.getSonAttrName();
            if (fatherAttr == null || sonAttr == null) {
                logger.warn("OPR INTF: CALL \"opr dealWithOrmPor: " + targetName
                        + "->fatherAttr and sonAttr can't be null");
            }
            String targetObjCollectionType = target.getTargetObjCollectionType();

            // deal with List, 'sonAttr' likes '**vo.**pk', so need to separate it by '.'
            String sonVo = "";
            String source = ormName;
            String indentsOfIF = indents;
            if (JavaSrcElm.UTIL_LIST_SIMPLE.equals(targetObjCollectionType)) {
                targetName = getOprAttributeName(targetClass.trim());
                int index = sonAttr.indexOf(JavaSrcElm.DOT);
                if (index == -1) {
                    logger.error("OPR ERROR: CALL \"opr dealWithOrmPor: " + targetName + "->sonAttr is Error");
                    continue;
                }
                // **vo
                sonVo = sonAttr.substring(0, index);
                // **pk
                sonAttr = JavaFormatter.getClassSimpleName(sonAttr.trim());
                // **dotx.get**Vo()
                left = generateGetAttribute(targetName, sonVo, false).toString();

                source = targetName;
                targetName = sonVo;
                indentsOfIF = "";
            }

            //         if (TARGET_TYPE_VO.equals(targetObjCollectionType)) {
            if (father != null) {
                String fatherTarget = generateGetAttribute(ormName, father.getTargetObjName(), false).toString();
                String fatherPk = generateGetAttribute(fatherTarget, fatherAttr, false).toString();
                String setAttr = generateSetAttribute(left, sonAttr, fatherPk, true).toString();
                content.append(setAttr);
                content.append(JavaSrcElm.LINE_SEPARATOR);
            }

            // set information
            String crudType = target.getCrudType();
            if (crudType.equals(JavaSrcElm.CRUD_TYPE_SAVE)) {
                StringBuffer saveSetStr = generateSaveSetBlock(source, targetName, "");
                content.append(saveSetStr);
            } else if (crudType.equals(JavaSrcElm.CRUD_TYPE_UPDATE)) {
                StringBuffer updateSetStr = generateUpdateSetBlock(source, targetName, "");
                content.append(updateSetStr);
            } else if (crudType.equals(JavaSrcElm.CRUD_TYPE_DEFUNCT)) {
                StringBuffer defunctSetStr = generateDefunctSetBlock(source, targetName, "");
                content.append(defunctSetStr);
            }

            // call Dao method
            String daoName = target.getCallDaoName();
            String daoMethod = target.getCallDaoMethod();
            List<String> paramList = new ArrayList<String>();
            paramList.add(left);
            StringBuffer daoMethodStr = generateDaoMethodBlock(daoName, daoMethod, paramList);
            content.append(daoMethodStr);

            // if
            if (oprType.equals(IF_REQUIRE)) {
                StringBuffer condition = generateIfCondition(left, JavaSrcElm.EXPR_OBJ_NOT_NULL);
                StringBuffer ifStr = generateIfBlock(condition.toString(), content.toString(), indentsOfIF);
                content.setLength(0);
                content.append(JavaSrcElm.LINE_SEPARATOR);
                content.append(ifStr);
            } else {
                srcCode.append(JavaSrcElm.LINE_SEPARATOR);
                content = rectifyContent(content.toString(), "");
            }

            // foreach 
            if (JavaSrcElm.UTIL_LIST_SIMPLE.equals(targetObjCollectionType)) {
                String listName = generateGetAttribute(ormName, target.getTargetObjName(), false).toString();
                StringBuffer foreachStr = generateForeachBlock(targetClass, listName, content.toString(), indents);
                content.setLength(0);
                content.append(JavaSrcElm.LINE_SEPARATOR);
                content.append(foreachStr);
            }
            srcCode.append(content);

            // recursive call the son omrOprs
            srcCode.append(dealWithOrmPor(ormMethod, target.getSonOrmOprs(), target));

        }

        return srcCode;
    }

    /**
     * export save Btach method
     * @param ormMethod
     * @return
     */
    private String exportSaveBatchMethod(OrmMethod ormMethod) {
        logger.info("OPR INTF: CALL \"opr exportSaveBatchMethod.");
        StringBuffer srcCode = new StringBuffer();
        if (ormMethod == null || ormMethod.getParameterList() == null || ormMethod.getParameterList().size() < 3) {
            logger.error("OPR ERROR: CALL \"opr exportSaveBatchMethod->param is error");
            return srcCode.toString();
        }
        srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        //      String indents = BuilderHelper.exportIndents();
        // **List
        String listType = ormMethod.getParameterList().get(0);
        String listParamTypeName = JavaFormatter.getCollectionParamType(listType);
        String listParamSimpleName = JavaFormatter.getAttributeName(listParamTypeName);
        String listName = JavaFormatter.getAttributeName(listType);

        // integer
        String limitType = ormMethod.getParameterList().get(1);
        String limitName = JavaFormatter.getAttributeName(limitType);

        // int times = (int) Math.ceil((double)**List.size()/integer);
        StringBuffer mathCeilStr = generateMathCeilBlock(PARAM_TIMES, listName, limitName, true, true);
        srcCode.append(mathCeilStr);

        StringBuffer saveSetStr = generateSaveSetBlock(listParamSimpleName, null, null);
        StringBuffer foreachStr = generateForeachBlock(listParamTypeName, listName, saveSetStr.toString(), null);
        srcCode.append(foreachStr);

        StringBuffer forContent = new StringBuffer();

        // List<**Vo> subList = null;
        forContent.append(listType).append(JavaSrcElm.WHITE_SPACE).append(PARAM_SUB_LIST);
        forContent.append(JavaSrcElm.EQUAL).append(JavaSrcElm.NULL).append(JavaSrcElm.SEMICOLON);
        forContent.append(JavaSrcElm.LINE_SEPARATOR);
        // times-index
        String left = PARAM_TIMES + JavaSrcElm.MIMUS + PARAM_INDEX;
        // times-index == 1
        StringBuffer condition = generateIfCondition(left, JavaSrcElm.EXPR_VALUE_IS_ONE);

        // if(times-index == 1) {subList = **List.subList(i*integer,**List.size());}
        StringBuffer ifContent = new StringBuffer();
        String subListEqualStr = PARAM_SUB_LIST + JavaSrcElm.EQUAL;
        ifContent.append(subListEqualStr);
        String fromIndex = PARAM_INDEX + JavaSrcElm.ASTERISK + limitName;
        String toIndex = listName + JavaSrcElm.DOT + JavaSrcElm.METHOD_SIZE + JavaSrcElm.CLOSE_PARENTHESIS;
        ifContent = generateSubListBlock(listName, fromIndex, toIndex, true, true);
        StringBuffer ifStr = generateIfBlock(condition.toString(), ifContent.toString(), null);
        forContent.append(ifStr);

        // else {subList = **List.subList(i*integer,(i+1)*integer);}
        StringBuffer elseContent = new StringBuffer();
        ifContent.append(subListEqualStr);
        toIndex = JavaSrcElm.LEFT_PARENTHESIS + PARAM_INDEX + JavaSrcElm.PLUS + JavaSrcElm.ONE
                + JavaSrcElm.RIGHT_PARENTHESIS + JavaSrcElm.ASTERISK + limitName;
        elseContent = generateSubListBlock(listName, fromIndex, toIndex, true, true);
        StringBuffer elseStr = generateElseBlock(elseContent.toString(), null);
        forContent.append(elseStr);

        if (ormMethod.getOrmOprList() == null || ormMethod.getOrmOprList().size() == 0) {
            logger.error("OPR ERROR: CALL \"opr exportSaveBatchMethod->OrmOprList is empty");
            forContent.append("\n\\\\_**Dao.insert**Batch(sublist)\n");
        } else {
            OrmOpr target = ormMethod.getOrmOprList().get(0);
            String daoName = target.getCallDaoName();
            String daoMethod = target.getCallDaoMethod();
            List<String> paramList = new ArrayList<String>();
            paramList.add(PARAM_SUB_LIST);
            StringBuffer daoMethodStr = generateDaoMethodBlock(daoName, daoMethod, paramList);
            forContent.append(JavaSrcElm.DOUBLE_LINE_SEPARATOR);
            forContent.append(daoMethodStr);
        }

        StringBuffer forStr = generateForBlock(PARAM_INDEX, PARAM_TIMES, forContent.toString(), null);
        srcCode.append(JavaSrcElm.DOUBLE_LINE_SEPARATOR);
        srcCode.append(forStr);

        logger.info("OPR INTF: GENERATE \"opr SaveBatchMethod SUCCESS.");
        return srcCode.toString();
    }

    /**
     * export update Batch method
     * @param ormMethod
     * @return
     */
    private String exportUpdBatchMethod(OrmMethod ormMethod) {
        logger.info("OPR INTF: CALL \"opr exportUpdBatchMethod.");

        // TODO export update Batch method

        logger.info("OPR INTF: GENERATE \"opr UpdBatchMethod SUCCESS.");
        return "";
    }

    /**
     * export delete batch method
     * @param omrMethod
     * @return
     */
    private String exportDelBatchMethod(OrmMethod omrMethod) {
        logger.info("OPR INTF: CALL \"opr exportDelBatchMethod.");

        // TODO export delete Batch method

        logger.info("OPR INTF: GENERATE \"opr DelBatchMethod SUCCESS.");
        return "";
    }

    /*********************util**********************/

    private String getOprAttributeName(String attributeName) {
        String simpleName = JavaFormatter.getClassSimpleName(attributeName.trim());
        return JavaFormatter.getAttributeName(simpleName);
    }

    /*********************generate segment**********************/

    /**
     * 'source'.get'attribute'()[;]
     * @param source
     * @param attributeName
     * @param hasSemicolon
     * @return
     */
    private StringBuffer generateGetAttribute(String source, String attributeName, boolean hasSemicolon) {
        StringBuffer srcCode = new StringBuffer();
        if ((source == null && attributeName == null) || (source.isEmpty() && attributeName.isEmpty())) {
            return srcCode;
        }
        if (source == null || source.isEmpty()) {
            srcCode.append(attributeName);
        } else if (attributeName == null || attributeName.isEmpty()) {
            srcCode.append(source);
        } else {
            srcCode.append(source).append(JavaSrcElm.DOT).append(JavaSrcElm.GET);
            srcCode.append(StringHelper.toUpperCase(attributeName.trim(), 0));
            srcCode.append(JavaSrcElm.CLOSE_PARENTHESIS);
        }
        if (hasSemicolon) {
            srcCode.append(JavaSrcElm.SEMICOLON);
        }
        return srcCode;
    }

    /**
     * 'source'.set'attribute'('content')[;]
     * @param source
     * @param attributeName
     * @param content
     * @param hasSemicolon
     * @return
     */
    private StringBuffer generateSetAttribute(String source, String attributeName, String content,
            boolean hasSemicolon) {
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(source).append(JavaSrcElm.DOT).append(JavaSrcElm.SET);
        srcCode.append(StringHelper.toUpperCase(attributeName.trim(), 0));
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(content);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);
        if (hasSemicolon) {
            srcCode.append(JavaSrcElm.SEMICOLON);
        }
        return srcCode;
    }

    /**
     * 'srouce'.get'attribute'()'setContent'
     * @param source
     * @param attributeName
     * @param setContent
     * @param hasSemicolon
     * @param hasSeparator
     * @return
     */
    private StringBuffer generateSetSegment(String source, String attributeName, String setContent,
            boolean hasSemicolon, boolean hasSeparator) {
        StringBuffer srcCode = new StringBuffer();
        StringBuffer getCode = generateGetAttribute(source, attributeName, false);
        srcCode.append(getCode).append(JavaSrcElm.DOT).append(setContent);
        if (hasSemicolon) {
            srcCode.append(JavaSrcElm.SEMICOLON);
        }
        if (hasSeparator) {
            srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        }
        return srcCode;
    }

    /**
     * 'indents' if('condition') {
     * @param condition
     * @param indents
     * @return
     */
    private StringBuffer generateIfBegin(String condition, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(indents);
        srcCode.append(JavaSrcElm.IF).append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(condition);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS).append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_BRACKET);
        return srcCode;
    }

    /**
     * 'indents' else {
     * @param condition
     * @param indents
     * @return
     */
    private StringBuffer generateElseBegin(String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(indents);
        srcCode.append(JavaSrcElm.ELSE).append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_BRACKET);
        return srcCode;
    }

    /**
     * 'left' 'expresson'
     * for example: 'left' == null
     * @param left
     * @return
     */
    private StringBuffer generateIfCondition(String left, String expression) {
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(left).append(expression);
        return srcCode;
    }

    /**
     * 'indents' else if('condition') {
     * @param condition
     * @param indents
     * @return
     */
    private StringBuffer generateElseIfBegin(String condition, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(indents);
        srcCode.append(JavaSrcElm.ELSE).append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(JavaSrcElm.IF).append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(condition);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS).append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_BRACKET);
        return srcCode;
    }

    /**
     * 'indents' for ( 'typeName' 'attributeName' : 'listName') {
     * 
     * @param typeName
     * @param listName
     * @param indents
     * @return
     */
    private StringBuffer generateForeachBegin(String typeName, String listName, String indents) {
        StringBuffer srcCode = new StringBuffer();
        String simpleName = JavaFormatter.getClassSimpleName(typeName.trim());
        String itemName = getOprAttributeName(simpleName);
        srcCode.append(indents).append(JavaSrcElm.FOR).append(JavaSrcElm.WHITE_SPACE)
                .append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(simpleName).append(JavaSrcElm.WHITE_SPACE).append(itemName)
                .append(JavaSrcElm.COLON_WITH_BLANK).append(listName).append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_BRACKET);
        return srcCode;
    }

    /**
     * for (int 'indexName' = 0; 'indexName' < 'sizeName'; 'indexName'++) {
     * @param indexName
     * @param sizeName
     * @param indents
     * @return
     */
    private StringBuffer generateForBegin(String indexName, String sizeName, String indents) {
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(indents).append(JavaSrcElm.FOR).append(JavaSrcElm.WHITE_SPACE)
                .append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(JavaSrcElm.INT).append(JavaSrcElm.WHITE_SPACE).append(indexName).append(JavaSrcElm.EQUAL)
                .append(JavaSrcElm.ZERO).append(JavaSrcElm.SEMICOLON);
        srcCode.append(JavaSrcElm.WHITE_SPACE).append(indexName).append(JavaSrcElm.LESS_THAN_WITH_BLACK)
                .append(sizeName).append(JavaSrcElm.SEMICOLON);
        srcCode.append(JavaSrcElm.WHITE_SPACE).append(indexName).append(JavaSrcElm.DOUBLE_PLUS)
                .append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.WHITE_SPACE).append(JavaSrcElm.LEFT_BRACKET);
        return srcCode;
    }

    /*********************generate Util**********************/

    /**
     * rectify content to adapt its parent's structure
     * @param content
     * @param parentIndents
     * @return
     */
    private StringBuffer rectifyContent(String content, String parentIndents) {
        StringBuffer srcCode = new StringBuffer();
        if (content == null) {
            return srcCode;
        }
        String indents = BuilderHelper.exportIndents() + parentIndents;
        srcCode.append(content);
        srcCode.insert(0, indents);
        for (int offset = 1; offset < srcCode.length();) {
            int index = srcCode.indexOf(JavaSrcElm.LINE_SEPARATOR, offset);
            if (index == -1) {
                break;
            }
            srcCode.insert(index + 1, indents);
            offset = index + 1;
        }

        return srcCode;
    }

    /*********************generate block**********************/

    /**
     * 'indents' if('condition') {
     * 'content'
     * 'indents' }
     * @param condition
     * @param content
     * @param indents
     * @return
     */
    private StringBuffer generateIfBlock(String condition, String content, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = generateIfBegin(condition, indents);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        srcCode.append(rectifyContent(content, indents));
        //      srcCode.append(content);

        srcCode.append(JavaSrcElm.LINE_SEPARATOR).append(indents).append(JavaSrcElm.RIGHT_BRACKET);
        return srcCode;
    }

    /**
     * 'else {
     * 'content'
     * 'indents' }
     * @param condition
     * @param content
     * @param indents
     * @return
     */
    private StringBuffer generateElseBlock(String content, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = generateElseBegin(null);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        srcCode.append(rectifyContent(content, indents));
        //      srcCode.append(content);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR).append(indents).append(JavaSrcElm.RIGHT_BRACKET);
        return srcCode;
    }

    /**
     * else if {
     * 'content'
     * 'indents' }
     * @param condition
     * @param content
     * @param indents
     * @return
     */
    private StringBuffer generateElseIfBlock(String condition, String content, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = generateElseIfBegin(condition, null);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        srcCode.append(rectifyContent(content, indents));
        //      srcCode.append(content);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR).append(indents).append(JavaSrcElm.RIGHT_BRACKET);
        return srcCode;
    }

    /**
     * 'indents' for ( 'typeName' 'attributeName' : 'listName') {
     * 'content'
     * 'indents' }
     * 
     * @param typeName
     * @param listName
     * @param content
     * @param indents
     * @return
     */
    private StringBuffer generateForeachBlock(String typeName, String listName, String content, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = generateForeachBegin(typeName, listName, indents);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        srcCode.append(rectifyContent(content, indents));
        //      srcCode.append(content);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR).append(indents).append(JavaSrcElm.RIGHT_BRACKET);
        return srcCode;
    }

    private StringBuffer generateForBlock(String indexName, String sizeName, String content, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = generateForBegin(indexName, sizeName, indents);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        srcCode.append(rectifyContent(content, indents));
        //      srcCode.append(content);
        srcCode.append(JavaSrcElm.LINE_SEPARATOR).append(indents).append(JavaSrcElm.RIGHT_BRACKET);
        return srcCode;
    }

    /**
     * 'srouce'.get'attribute'.'CRT_BY'
     * 'srouce'.get'attribute'.'CRT_TM'
     * 'srouce'.get'attribute'.'EDIT_FLAG'
     * 'srouce'.get'attribute'.'RELS_NBR'
     * 
     * @param source
     * @param attributeName
     * @return
     */
    private StringBuffer generateSaveSetBlock(String source, String attributeName, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = new StringBuffer();
        List<String> contentList = new ArrayList<String>();
        contentList.add(CRT_BY);
        contentList.add(CRT_TM);
        contentList.add(EDIT_FLAG_NEW);
        contentList.add(RELS_NBR);
        for (String content : contentList) {
            StringBuffer seg = generateSetSegment(source, attributeName, content, true, true);
            srcCode.append(indents);
            srcCode.append(seg);
        }
        return srcCode;
    }

    /**
     * 'srouce'.get'attribute'.'UPD_BY'
     * 'srouce'.get'attribute'.'UPD_TM'
     * 'srouce'.get'attribute'.'EDIT_FLAG'
     * 
     * @param source
     * @param attributeName
     * @return
     */
    private StringBuffer generateDefunctSetBlock(String source, String attributeName, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = new StringBuffer();
        List<String> contentList = new ArrayList<String>();
        contentList.add(UPD_BY);
        contentList.add(UPD_TM);
        contentList.add(EDIT_FLAG_DELETED);
        for (String content : contentList) {
            StringBuffer seg = generateSetSegment(source, attributeName, content, true, true);
            srcCode.append(indents);
            srcCode.append(seg);
        }
        return srcCode;
    }

    /**
     * 'srouce'.get'attribute'.'UPD_BY'
     * 'srouce'.get'attribute'.'UPD_TM'
     * 
     * @param source
     * @param attributeName
     * @return
     */
    private StringBuffer generateUpdateSetBlock(String source, String attributeName, String indents) {
        if (indents == null) {
            indents = "";
        }
        StringBuffer srcCode = new StringBuffer();
        List<String> contentList = new ArrayList<String>();
        contentList.add(UPD_BY);
        contentList.add(UPD_TM);
        for (String content : contentList) {
            StringBuffer seg = generateSetSegment(source, attributeName, content, true, true);
            srcCode.append(indents);
            srcCode.append(seg);
        }
        return srcCode;
    }

    /**
     * 'daoName'.'methodName'([paramList])
     * @param daoName
     * @param methodName
     * @param paramList ??
     * @return
     */
    private StringBuffer generateDaoMethodBlock(String daoName, String methodName, List<String> paramList) {
        StringBuffer srcCode = new StringBuffer();
        srcCode.append(daoName).append(JavaSrcElm.DOT).append(methodName);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS);
        boolean isFirst = true;
        for (String param : paramList) {
            if (!isFirst) {
                srcCode.append(JavaSrcElm.COMMA).append(JavaSrcElm.WHITE_SPACE);
            }
            srcCode.append(param);
            isFirst = false;
        }
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS).append(JavaSrcElm.SEMICOLON);
        return srcCode;
    }

    /**
     * 'listName'.sublist('fromIndex', 'toIndex');
     * @param listName
     * @param limitName
     * @return
     */
    private StringBuffer generateSubListBlock(String listName, String fromIndex, String toIndex,
            boolean hasSemicolon, boolean hasSeparator) {
        StringBuffer srcCode = new StringBuffer();

        srcCode.append(listName).append(JavaSrcElm.DOT);
        srcCode.append(JavaSrcElm.METHOD_SUBLIST).append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(fromIndex).append(JavaSrcElm.COMMA).append(JavaSrcElm.WHITE_SPACE);
        srcCode.append(toIndex).append(JavaSrcElm.RIGHT_PARENTHESIS);

        if (hasSemicolon) {
            srcCode.append(JavaSrcElm.SEMICOLON);
        }
        if (hasSeparator) {
            srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        }
        return srcCode;
    }

    /**
    * int 'resultName' = (int) Math.ceil((double)'listName'.size()/'limitName');
    * 
    * @param resultName
    * @param listName
    * @param limitName
    * @param hasSemicolon
    * @param hasSeparator
    * @return
    */
    private StringBuffer generateMathCeilBlock(String resultName, String listName, String limitName,
            boolean hasSemicolon, boolean hasSeparator) {
        StringBuffer srcCode = new StringBuffer();
        if (resultName == null || resultName.isEmpty() || listName == null || listName.isEmpty()
                || limitName == null || limitName.isEmpty()) {
            return srcCode;
        }
        srcCode.append(JavaSrcElm.INT).append(JavaSrcElm.WHITE_SPACE).append(resultName).append(JavaSrcElm.EQUAL);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS).append(JavaSrcElm.INT).append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(JavaSrcElm.METHOD_MATH_CEIL).append(JavaSrcElm.LEFT_PARENTHESIS);
        srcCode.append(JavaSrcElm.LEFT_PARENTHESIS).append(JavaSrcElm.DOUBLE).append(JavaSrcElm.RIGHT_PARENTHESIS);
        srcCode.append(listName).append(JavaSrcElm.DOT).append(JavaSrcElm.METHOD_SIZE)
                .append(JavaSrcElm.CLOSE_PARENTHESIS);
        srcCode.append(JavaSrcElm.SLASH).append(limitName);
        srcCode.append(JavaSrcElm.RIGHT_PARENTHESIS);

        if (hasSemicolon) {
            srcCode.append(JavaSrcElm.SEMICOLON);
        }
        if (hasSeparator) {
            srcCode.append(JavaSrcElm.LINE_SEPARATOR);
        }
        return srcCode;
    }

}