代码生成工具:
package com.dhcc.framework.common.codegen;
import java.io.*;
import java.util.ArrayList;
public abstract class CodeGenUtils
{
public CodeGenUtils()
{
}
private static String createTemplateType(String type)
{
String templateName = "";
String s;
switch((s = type.trim().toUpperCase()).hashCode())
{
default:
break;
case -1592831339:
if(s.equals("SERVICE"))
templateName = SERVICE_TEMPLATE;
break;
case 65854:
if(s.equals("BLH"))
templateName = BLH_TEMPLATE;
break;
case 67442:
if(s.equals("DAO"))
templateName = DAO_TEMPLATE;
break;
case 68031:
if(s.equals("DTO"))
templateName = DTO_TEMPLATE;
break;
case 225204789:
if(s.equals("SERVICEIMPL"))
templateName = SERVICEIMPL_TEMPLATE;
break;
case 1925345846:
if(s.equals("ACTION"))
templateName = ACTION_TEMPLATE;
break;
}
return templateName;
}
private static String to1Upper(String str)
{
return (new StringBuilder(String.valueOf((char)((str.charAt(0) - 97) + 65)))).append(str.substring(1)).toString();
}
private static String to1Lower(String str)
{
return (new StringBuilder(String.valueOf((char)((str.charAt(0) + 97) - 65)))).append(str.substring(1)).toString();
}
private static void readTemplateFile2Code(ArrayList parmsList, String type, String proLocation)
{
String templateFileName;
String dirSeparator;
String postfix;
String innerDir;
BufferedReader reader;
BufferedWriter output;
templateFileName = (new StringBuilder("/codeTemplate/")).append(createTemplateType(type)).toString();
dirSeparator = File.separator;
postfix = to1Upper(type);
innerDir = ((String)parmsList.get(0)).replaceAll("\\.", "\\\\");
reader = null;
output = null;
try
{
InputStreamReader fr = new InputStreamReader(com/dhcc/framework/common/codegen/CodeGenUtils.getResourceAsStream(templateFileName));
reader = new BufferedReader(fr);
String tempString = null;
File outFile = null;
if("serviceimpl".equals(type))
{
System.out.println("======start gene serviceimpl code ======");
String filePath = (new StringBuilder("src")).append(dirSeparator).append("main").append(dirSeparator).append("java").append(dirSeparator).append(innerDir).append(dirSeparator).append("service").append(dirSeparator).append(((String)parmsList.get(1)).toLowerCase()).append(dirSeparator).append("impl").append(dirSeparator).append((String)parmsList.get(1)).append("ServiceImpl").append(".java").toString();
if(proLocation != null)
filePath = (new StringBuilder(String.valueOf(proLocation))).append(dirSeparator).append(filePath).toString();
outFile = new File(filePath);
} else
if("action".equals(type))
{
System.out.println("======start gene action code======");
String filePath = (new StringBuilder("src")).append(dirSeparator).append("main").append(dirSeparator).append("java").append(dirSeparator).append(innerDir).append(dirSeparator).append("web").append(dirSeparator).append(((String)parmsList.get(1)).toLowerCase()).append(dirSeparator).append(type).append(dirSeparator).append((String)parmsList.get(1)).append(postfix).append(".java").toString();
if(proLocation != null)
filePath = (new StringBuilder(String.valueOf(proLocation))).append(dirSeparator).append(filePath).toString();
outFile = new File(filePath);
} else
if("dao".equals(type))
{
System.out.println("======start gene dao code======");
String filePath = (new StringBuilder("src")).append(dirSeparator).append("main").append(dirSeparator).append("java").append(dirSeparator).append(innerDir).append(dirSeparator).append(type).append(dirSeparator).append(((String)parmsList.get(1)).toLowerCase()).append(dirSeparator).append((String)parmsList.get(2)).append(postfix).append(".java").toString();
if(proLocation != null)
filePath = (new StringBuilder(String.valueOf(proLocation))).append(dirSeparator).append(filePath).toString();
outFile = new File(filePath);
} else
{
if("dto".equals(type))
System.out.println("======start gene dto code======");
else
if("blh".equals(type))
System.out.println("======start gene blh code======");
else
if("service".equals(type))
System.out.println("======start gene service interface code======");
String filePath = (new StringBuilder("src")).append(dirSeparator).append("main").append(dirSeparator).append("java").append(dirSeparator).append(innerDir).append(dirSeparator).append(type).append(dirSeparator).append(((String)parmsList.get(1)).toLowerCase()).append(dirSeparator).append((String)parmsList.get(1)).append(postfix).append(".java").toString();
if(proLocation != null)
filePath = (new StringBuilder(String.valueOf(proLocation))).append(dirSeparator).append(filePath).toString();
outFile = new File(filePath);
}
try
{
if(outFile.exists() || outFile.createNewFile())
output = new BufferedWriter(new FileWriter(outFile));
}
catch(IOException ex)
{
outFile.getParentFile().mkdirs();
output = new BufferedWriter(new FileWriter(outFile));
}
while((tempString = reader.readLine()) != null)
{
String replaceString = tempString.replace("{$packageName}", (CharSequence)parmsList.get(0)).replace("{$businessName}", (CharSequence)parmsList.get(1)).replace("{$businessName_lower}", ((String)parmsList.get(1)).toLowerCase()).replace("{$businessName_1lower}", to1Lower((String)parmsList.get(1))).replace("{$entityName}", (CharSequence)parmsList.get(2)).replace("{$entityName_1lower}", to1Lower((String)parmsList.get(2)));
output.write(replaceString);
output.newLine();
}
reader.close();
output.close();
if("dto".equals(type))
System.out.println("======end gene dto code======");
else
if("blh".equals(type))
System.out.println("======end gene blh code======");
else
if("service".equals(type))
System.out.println("======end gene service interface code======");
else
if("action".equals(type))
System.out.println("======end gene action code======");
else
if("serviceimpl".equals(type))
System.out.println("======end gene service implements code======");
else
if("dao".equals(type))
System.out.println("======end gene dao code======");
break MISSING_BLOCK_LABEL_1174;
}
catch(IOException e)
{
e.printStackTrace();
}
if(reader != null)
try
{
reader.close();
}
catch(IOException ioexception) { }
if(output != null)
try
{
output.close();
}
catch(IOException ioexception1) { }
break MISSING_BLOCK_LABEL_1204;
Exception exception;
exception;
if(reader != null)
try
{
reader.close();
}
catch(IOException ioexception2) { }
if(output != null)
try
{
output.close();
}
catch(IOException ioexception3) { }
throw exception;
if(reader != null)
try
{
reader.close();
}
catch(IOException ioexception4) { }
if(output != null)
try
{
output.close();
}
catch(IOException ioexception5) { }
}
public static void createCode(String packageName, String businessName, String entityName)
{
ArrayList parmsList = new ArrayList();
parmsList.add(packageName);
parmsList.add(businessName);
parmsList.add(entityName);
String as[];
int j = (as = (new String[] {
"action", "blh", "serviceimpl", "service", "dao", "dto"
})).length;
for(int i = 0; i < j; i++)
{
String type = as[i];
readTemplateFile2Code(parmsList, type, null);
}
}
public static void createCode(String packageName, String businessName, String entityName, String proLocation)
{
ArrayList parmsList = new ArrayList();
parmsList.add(packageName);
parmsList.add(businessName);
parmsList.add(entityName);
String as[];
int j = (as = (new String[] {
"action", "blh", "serviceimpl", "service", "dao", "dto"
})).length;
for(int i = 0; i < j; i++)
{
String type = as[i];
readTemplateFile2Code(parmsList, type, proLocation);
}
}
public static void main(String args[])
{
createCode("com.dhcc.ehr", "UserManager", "User");
}
private static String ACTION_TEMPLATE = "WebActionTemplate.dhcctemplate";
private static String BLH_TEMPLATE = "BlhTemplate.dhcctemplate";
private static String SERVICE_TEMPLATE = "ServiceTemplate.dhcctemplate";
private static String DAO_TEMPLATE = "DaoTemplate.dhcctemplate";
private static String DTO_TEMPLATE = "DtoTemplate.dhcctemplate";
private static String SERVICEIMPL_TEMPLATE = "ServiceImplTemplate.dhcctemplate";
}