本文整理匯總了Java中javax.validation.Path.MethodNode方法的典型用法代碼示例。如果您正苦於以下問題:Java Path.MethodNode方法的具體用法?Java Path.MethodNode怎麽用?Java Path.MethodNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.validation.Path
的用法示例。
在下文中一共展示了Path.MethodNode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParameterAnnotations
import javax.validation.Path; //導入方法依賴的package包/類
private static Annotation[] getParameterAnnotations(ConstraintViolation<?> violation, Path.MethodNode methodNode,
Path.ParameterNode parameterNode) {
try {
String methodName = methodNode.getName();
int paramCount = methodNode.getParameterTypes().size();
Class[] paramTypes = methodNode.getParameterTypes().toArray(new Class[paramCount]);
Class<?> rootBeanClass = violation.getRootBean().getClass();
Method method = rootBeanClass.getMethod(methodName, paramTypes);
int parameterIndex = parameterNode.getParameterIndex();
return method.getParameterAnnotations()[parameterIndex];
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
示例2: 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];
}