javax.validation.metadata.MethodDescriptor Java Examples
The following examples show how to use
javax.validation.metadata.MethodDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractInterfaceOption.java From joyrpc with Apache License 2.0 | 5 votes |
/** * 获取方法参数验证器 * * @param parametric 参数 * @return 参数验证器 */ protected Validator getValidator(final WrapperParametric parametric) { //过滤掉了不验证的方法或泛型接口 if (validator == null || !parametric.getBoolean(VALIDATION_OPTION.getName(), validation)) { return null; } try { Method method = getPublicMethod(interfaceClass, parametric.getName()); //判断该方法上是有有验证注解 MethodDescriptor descriptor = beanDescriptor.getConstraintsForMethod(method.getName(), method.getParameterTypes()); return descriptor != null && descriptor.hasConstrainedParameters() ? validator : null; } catch (NoSuchMethodException | MethodOverloadException e) { return null; } }
Example #2
Source File: MethodValidator.java From vraptor4 with Apache License 2.0 | 5 votes |
/** * Only accepts if method isn't parameterless and have at least one constraint. */ private boolean hasConstraints(ControllerMethod controllerMethod) { Method method = controllerMethod.getMethod(); if (method.getParameterTypes().length == 0) { logger.debug("method {} has no parameters, skipping", controllerMethod); return false; } BeanDescriptor bean = bvalidator.getConstraintsForClass(controllerMethod.getController().getType()); if(bean == null) { return false; } MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getName(), method.getParameterTypes()); return descriptor != null && descriptor.hasConstrainedParameters(); }