
org.tinygroup.mdatool.util.FileCreateUtil Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 1997-2013, tinygroup.org ([email protected]).
*
* Licensed under the GPL, Version 3.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.gnu.org/licenses/gpl.html
*
* 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.
* --------------------------------------------------------------------------
* 版权 (c) 1997-2013, tinygroup.org ([email protected]).
*
* 本开源软件遵循 GPL 3.0 协议;
* 如果您不遵循此协议,则不被允许使用此文件。
* 你可以从下面的地址获取完整的协议文本
*
* http://www.gnu.org/licenses/gpl.html
*/
package org.tinygroup.mdatool.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.tinygroup.logger.LogLevel;
import org.tinygroup.logger.Logger;
import org.tinygroup.logger.LoggerFactory;
import org.tinygroup.codegen.MDAFileCreator;
import org.tinygroup.codegen.ModelManagerFactory;
import org.tinygroup.codegen.config.entity.EntityModel;
import org.tinygroup.codegen.config.trans.MDACreatorConfig;
import org.tinygroup.codegen.config.trans.MDACreators;
import org.tinygroup.codegen.config.trans.MDACreatorsType;
import org.tinygroup.codegen.javabean.BeanDetial;
import org.tinygroup.codegen.transform.entity.EntityModelTransformFactory;
import org.tinygroup.codegen.transform.entity.EntityModelTransformer;
import org.tinygroup.codegen.util.FileUtil;
import org.tinygroup.codegen.util.ModelTransUtil;
import org.tinygroup.springutil.SpringUtil;
public class FileCreateUtil {
private static Logger logger = LoggerFactory
.getLogger(FileCreateUtil.class);
private static Map entityCreatesMap = new HashMap();
private static Map viewCreatesMap = new HashMap();
public static void main(String[] args) {
try {
MDATrans(args[0], args[1], null);
} catch (Throwable e) {
logger.errorMessage(e.getMessage(), e);
}
}
public static void MDATrans(String src, String resource,
List classPaths) {
ModelTransUtil.init(classPaths, resource);
FileUtil fileUtil = new FileUtil(src, resource);
initCreators();
dealAllEntityModel(fileUtil);
}
private static void initCreators() {
for(MDACreators creators:ModelTransUtil.getAllCreators()){
if(creators.getType().toString().equals(MDACreatorsType.VIEW.toString())){
initCreator(creators, viewCreatesMap);
}else if(creators.getType().toString().equals(MDACreatorsType.ENTITY.toString())){
initCreator(creators, entityCreatesMap);
}
}
}
private static void initCreator(MDACreators creators,Map map){
for (MDACreatorConfig creator : creators.getCreators()) {
logger.logMessage(LogLevel.INFO, "初始化MDAFileCreator:{0}",creator.getName());
MDAFileCreator fileCreator = null;
if(!isNull(creator.getName())&&!isNull(creator.getBean())){
fileCreator = SpringUtil.getBean(creator.getBean());
fileCreator.setCreatorConfig(creator,creators);
}else{
logger.logMessage(LogLevel.ERROR, "MDAFileCreator:{0}信息配置不完整",creator.getName());
}
logger.logMessage(LogLevel.INFO, "初始化MDAFileCreator:{0}完成",creator.getName());
map.put(creator.getName(), fileCreator);
}
}
private static void dealAllEntityModel(FileUtil fileUtil) {
// 处理所有
List list = ModelManagerFactory.getManager()
.getEntityModels();
for (EntityModel model : list) {
if (!model.getIgnore()) {
try {
execCreators(model.getUuid(), fileUtil);
} catch (Exception e) {
logger.errorMessage("对模型进行转换时发生异常,模型:{0}", e,
model.getName());
}
}
}
}
/**
* 执行各种处理器处理模型
*
* @param stream
* @param id
* 模型id
* @param fileUtil
*/
private static void execCreators(String id, FileUtil fileUtil) {
logger.logMessage(LogLevel.DEBUG, "开始处理模型:id:{id}",id);
EntityModel model = ModelTransUtil.getEntity(id);
EntityModelTransformer trans = EntityModelTransformFactory
.getMdaTransformer(model);
BeanDetial bean = trans.tranformToBeanDetial();
for(MDAFileCreator fileCreator:entityCreatesMap.values()){
fileCreator.createFile(model, bean, fileUtil);
}
logger.logMessage(LogLevel.DEBUG, "处理模型:id:{id}完成",id);
}
private static boolean isNull(String s) {
return s == null || "".equals(s);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy