All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mycomm.itest.ServiceDaoCodeGen Maven / Gradle / Ivy

The newest version!
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycomm.itest;

import com.mycomm.IProtocol.utils.ITestable;
import com.mycomm.itool.SystemUtil;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author jw362j
 */
public class ServiceDaoCodeGen implements ITestable {

    protected static final Logger logger = LoggerFactory.getLogger(ServiceDaoCodeGen.class);
    //*************************************************************************************************************************************************
    private static String srcDirBase;//= "C:\\Users\\jw362j\\a\\z_temp\\hadoopz\\hadoopz\\AuthN\\src\\main\\java\\com\\mycomm\\web\\authn";
    private static String templateSrcDirBase ;//  "C:\\Users\\jw362j\\a\\z_temp\\hadoopz\\hadoopz\\ITest\\src\\main\\resources\\conf\\autoCodeTemplate\\";//= "C:\\Users\\jw362j\\a\\z_temp\\hadoopz\\hadoopz\\SerenaTVWeb\\src\\main\\resources\\conf\\autoCodeTemplate\\";
    private static String srcPackage;// = "com.mycomm.web.authn";    
    private static String simpleClassName;//= "OpenAuthNUserAccount";
    //*************************************************************************************************************************************************

    private static String daoFileAbsPath ;
    private static String daoImplFileAbsPath ;
    private static String serviceFileAbsPath ;
    private static String serviceImplFileAbsPath ;
    private static String daoDirBase ;
    private static String serviceDirBase ;

    public ServiceDaoCodeGen(String srcDir, String templateSrcDir, String srcPackage, String simpleClassName) {
        if(!srcDir.endsWith(File.separator)){
            srcDir = srcDir+File.separator;
        }
        ServiceDaoCodeGen.srcDirBase = srcDir;
        if (templateSrcDir != null) {
            ServiceDaoCodeGen.templateSrcDirBase = templateSrcDir;
        }
        ServiceDaoCodeGen.srcPackage = srcPackage;
        ServiceDaoCodeGen.simpleClassName = simpleClassName;

        daoFileAbsPath = srcDirBase + File.separator + "dao" + File.separator + simpleClassName + "Dao.java";
        daoImplFileAbsPath = srcDirBase + File.separator + "dao" + File.separator + "impl" + File.separator + "My" + simpleClassName + "DaoImpl.java";
        serviceFileAbsPath = srcDirBase + File.separator + "service" + File.separator + simpleClassName + "Service.java";
        serviceImplFileAbsPath = srcDirBase + File.separator + "service" + File.separator + "impl" + File.separator + "My" + simpleClassName + "ServiceImpl.java";
        daoDirBase = srcDirBase + File.separator + "dao";
        serviceDirBase = srcDirBase + File.separator + "service";
    }

    @Override
    public void onTest(Object object) {
        logger.debug("daoFileAbsPath:" + daoFileAbsPath);
        logger.debug("daoImplFileAbsPath:" + daoImplFileAbsPath);
        logger.debug("serviceFileAbsPath:" + serviceFileAbsPath);
        logger.debug("serviceImplFileAbsPath:" + serviceImplFileAbsPath);

        if(!templateSrcDirBase.endsWith(File.separator)){
            templateSrcDirBase = templateSrcDirBase+File.separator;
        }
        String daoCodeTemplate = SystemUtil.ReadFromFile(templateSrcDirBase + "Dao.tpl");
        String daoImplCodeTemplate = SystemUtil.ReadFromFile(templateSrcDirBase + "DaoImpl.tpl");
        String serviceCodeTemplate = SystemUtil.ReadFromFile(templateSrcDirBase + "Service.tpl");
        String serviceImplCodeTemplate = SystemUtil.ReadFromFile(templateSrcDirBase + "ServiceImpl.tpl");

        daoCodeTemplate = daoCodeTemplate.replace("{srcPackage}", srcPackage);
        daoCodeTemplate = daoCodeTemplate.replace("{simpleClassName}", simpleClassName);
        if (!new File(daoFileAbsPath).exists()) {
            SystemUtil.WriteIntoFile(daoFileAbsPath, daoCodeTemplate);
        }

        daoImplCodeTemplate = daoImplCodeTemplate.replace("{srcPackage}", srcPackage);
        daoImplCodeTemplate = daoImplCodeTemplate.replace("{simpleClassName}", simpleClassName);
        if (!new File(daoImplFileAbsPath).exists()) {
            SystemUtil.WriteIntoFile(daoImplFileAbsPath, daoImplCodeTemplate);
        }

        serviceCodeTemplate = serviceCodeTemplate.replace("{srcPackage}", srcPackage);
        serviceCodeTemplate = serviceCodeTemplate.replace("{simpleClassName}", simpleClassName);
        if (!new File(serviceFileAbsPath).exists()) {
            SystemUtil.WriteIntoFile(serviceFileAbsPath, serviceCodeTemplate);
        }

        serviceImplCodeTemplate = serviceImplCodeTemplate.replace("{srcPackage}", srcPackage);
        serviceImplCodeTemplate = serviceImplCodeTemplate.replace("{simpleClassName}", simpleClassName);
        if (!new File(serviceImplFileAbsPath).exists()) {
            SystemUtil.WriteIntoFile(serviceImplFileAbsPath, serviceImplCodeTemplate);
        }
        logger.debug("*******************************************");
        logger.debug("  ");

        logger.debug("      import " + srcPackage + ".service." + simpleClassName + "Service;");
        logger.debug("      @Resource");
        logger.debug("      protected " + simpleClassName + "Service my" + simpleClassName + "Service;");

        logger.debug("  ");
        logger.debug("*******************************************");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy