private void validateField(Field f, Object obj) throws IllegalArgumentException, IllegalAccessException {
XmlType xtype = obj.getClass().getAnnotation(XmlType.class);
if (xtype == null) {
return;
}
Object val = f.get(obj);
String elementName = xtype.name();
logger.debug(String.format("validating %s->%s", elementName, f.getName()));
XmlElement eat = f.getAnnotation(XmlElement.class);
if (eat != null && eat.required() && val == null) {
throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", f.getName(), elementName));
}
XmlAttribute aat = f.getAnnotation(XmlAttribute.class);
if (aat != null && aat.required() && val == null) {
throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", aat.name(), elementName));
}
if (val != null) {
validateObject(val);
}
}
DeployerValidator.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:zstack
作者:
评论列表
文章目录