本文整理汇总了Java中javax.validation.Path.PropertyNode方法的典型用法代码示例。如果您正苦于以下问题:Java Path.PropertyNode方法的具体用法?Java Path.PropertyNode怎么用?Java Path.PropertyNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.Path
的用法示例。
在下文中一共展示了Path.PropertyNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnnotations
import javax.validation.Path; //导入方法依赖的package包/类
private static Annotation[] getAnnotations(ConstraintViolation<?> violation) {
// create a simple list of nodes from the path
List<Path.Node> nodes = new ArrayList<>();
for (Path.Node node : violation.getPropertyPath()) {
nodes.add(node);
}
Path.Node lastNode = nodes.get(nodes.size() - 1);
// the path refers to some property of the leaf bean
if (lastNode.getKind() == ElementKind.PROPERTY) {
Path.PropertyNode propertyNode = lastNode.as(Path.PropertyNode.class);
return getPropertyAnnotations(violation, propertyNode);
}
// The path refers to a method parameter
else if (lastNode.getKind() == ElementKind.PARAMETER && nodes.size() == 2) {
Path.MethodNode methodNode = nodes.get(0).as(Path.MethodNode.class);
Path.ParameterNode parameterNode = nodes.get(1).as(Path.ParameterNode.class);
return getParameterAnnotations(violation, methodNode, parameterNode);
}
log.warning("Could not read annotations for path: " + violation.getPropertyPath().toString());
return new Annotation[0];
}
示例2: getPropertyAnnotations
import javax.validation.Path; //导入方法依赖的package包/类
private static Annotation[] getPropertyAnnotations(ConstraintViolation<?> violation, Path.PropertyNode node) {
try {
Class<?> leafBeanClass = violation.getLeafBean().getClass();
Field field = leafBeanClass.getDeclaredField(node.getName());
return field.getAnnotations();
} catch (NoSuchFieldException e) {
throw new IllegalStateException(e);
}
}