【Java开源代码栏目提醒】:网学会员Java开源代码为您提供EntityModelBeanValidator.java参考,解决您在EntityModelBeanValidator.java学习中工作中的难题,参考学习。
package com.cownew.studio.modelDev.codeGen;
import java.util.List;
import com.cownew.studio.modelDev.common.CommonUtils;
import com.cownew.studio.modelDev.common.EntityFieldModelBean;
import com.cownew.studio.modelDev.common.EntityModelBean;
import com.cownew.studio.modelDev.common.ModeValidateException;
import com.cownew.studio.modelDev.common.enumdef.LinkTypeEnum;
public class EntityModelBeanValidator
{
public static void validate(EntityModelBean bean)
throws ModeValidateException
{
if(CommonUtils.isEmptyString(bean.getName()))
{
throw new ModeValidateException(bean,"Name cannot be null!");
}
if(CommonUtils.isEmptyString(bean.getPackageName()))
{
throw new ModeValidateException(bean,"PackageName cannot be null!");
}
if(bean.getFieldList()==null||bean.getFieldList().size()<1)
{
throw new ModeValidateException(bean,"No Fields defination!");
}
if(CommonUtils.isEmptyString(bean.getDbTableName()))
{
throw new ModeValidateException(bean,"DbTableName cannot be null!");
}
if(CommonUtils.isEmptyString(bean.getPrimaryKey()))
{
throw new ModeValidateException(bean,"PrimaryKey cannot be null!");
}
List<EntityFieldModelBean> fieldList = bean.getFieldList();
for(int i=0,n=fieldList.size();i<n;i++)
{
validate(bean,fieldList.get(i));
}
}
private static void validate(EntityModelBean bean,EntityFieldModelBean fieldBean)
throws ModeValidateException
{
if(CommonUtils.isEmptyString(fieldBean.getName()))
{
throw new ModeValidateException(bean,"FieldName cannot be null!");
}
if(fieldBean.isLinkProperty()==false
&&CommonUtils.isEmptyString(fieldBean.getDbFieldName()))
{
throw new ModeValidateException(bean,"DbFieldName of "+
fieldBean.getName()+" cannot be null!");
}
if(fieldBean.getDataype()==null)
{
throw new ModeValidateException(bean,"Dataype of "+
fieldBean.getName()+" cannot be null!");
}
if(fieldBean.isLinkProperty())
{
if(CommonUtils.isEmptyString(fieldBean.getLinkEntity()))
{
throw new ModeValidateException(bean,"LinkEntity cannot be null!");
}
if(fieldBean.getLinkType()==null)
{
throw new ModeValidateException(bean,"LinkType cannot be null!");
}
if(fieldBean.getLinkType()!=LinkTypeEnum.ONETOMANY
&&CommonUtils.isEmptyString(fieldBean.getDbFieldName()))
{
throw new ModeValidateException(bean,"DbFieldName of "+
fieldBean.getName()+" cannot be null!");
}
}
}
}
上一篇:
EntityModelBean.java
下一篇:
论莫泊桑中短篇小说女权主义思想的表现方式