本文整理汇总了Java中org.hibernate.validator.internal.engine.path.PathImpl类的典型用法代码示例。如果您正苦于以下问题:Java PathImpl类的具体用法?Java PathImpl怎么用?Java PathImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PathImpl类属于org.hibernate.validator.internal.engine.path包,在下文中一共展示了PathImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processValidationError
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* @param ex {@link ConstraintViolationException}
* @return Returns an object with a list of incorrect parameters.
*/
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ValidationErrorDTO processValidationError(final ConstraintViolationException ex) {
final ValidationErrorDTO validationErrorDTO = new ValidationErrorDTO();
final Set<ConstraintViolation<?>> set = ex.getConstraintViolations();
for (Iterator<ConstraintViolation<?>> iterator = set.iterator();iterator.hasNext(); ) {
ConstraintViolation<?> next = iterator.next();
validationErrorDTO.getFieldErrors()
.add(new ErrorFieldDTO(((PathImpl)next.getPropertyPath()).getLeafNode().getName(),
next.getMessage()));
}
return validationErrorDTO;
}
示例2: validate
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Validate a bean of given declared class.
*
* @param bean
* the bean to validate.
* @param parameter
* the runtime annotations of this parameter.
* @param validationErrors
* the errors list to fill.
*/
private void validate(final Object bean, final Method method, final Parameter parameter, final int index,
final Set<ConstraintViolation<?>> validationErrors) {
if (bean == null) {
// Parameter is null, is it manually checked of managed by CXF for
// multipart?
// All non-body parameters are required by default
final PathImpl propertyPath = PathImpl.createPathFromString(method.getName());
propertyPath.addParameterNode(parameter.getName(), index);
validationErrors.add(ConstraintViolationImpl.forParameterValidation(NotNull.class.getName(), null, null, "interpolated", null,
null, null, null, propertyPath, NOT_NULL_DESCRIPTOR, null, null, null));
return;
}
final Class<?> clazz = bean.getClass();
if (Collection.class.isAssignableFrom(clazz)) {
validate((Collection<?>) bean, validationErrors);
} else if (clazz.isArray()) {
validate((Object[]) bean, validationErrors);
} else {
validateSimpleBean(bean, validationErrors);
}
}
示例3: testConstraintViolationExceptionParameter
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
@Test
public void testConstraintViolationExceptionParameter() {
final Wine bean = new Wine();
final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();
final ConstraintHelper helper = new ConstraintHelper();
final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("name", NotEmpty.class), ElementType.FIELD);
PathImpl path = PathImpl.createPathFromString("name");
violations.add(ConstraintViolationImpl.<Wine> forParameterValidation("name-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
"value", path, notEmptyNameDescriptor, ElementType.PARAMETER, null, null));
path.addParameterNode("parameter1", 0);
final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);
final ValidationJsonException validationJsonException = new ValidationJsonException(violationException);
Assert.assertFalse(validationJsonException.getErrors().isEmpty());
Assert.assertEquals("{parameter1=[{rule=name-Empty}]}", validationJsonException.getErrors().toString());
}
示例4: getPropertyPath
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Return the property path from the given validation error.
*/
private String getPropertyPath(final ConstraintViolation<?> error) {
if (((PathImpl) error.getPropertyPath()).getLeafNode().getKind() == ElementKind.PARAMETER) {
// JSR-349 - Parameter, drop parent context
return ((PathImpl) error.getPropertyPath()).getLeafNode().getName();
}
// JSR-303 - Bean violation
return error.getPropertyPath().toString();
}
示例5: testConstraintViolationException
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
@Test
public void testConstraintViolationException() {
final Wine bean = new Wine();
final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();
final ConstraintHelper helper = new ConstraintHelper();
final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("name", NotEmpty.class), ElementType.FIELD);
final ConstraintDescriptor<NotEmpty> notEmptyGrapesDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("grapes", NotEmpty.class), ElementType.FIELD);
final ConstraintDescriptor<Length> lengthNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("name", Length.class), ElementType.FIELD);
violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
"value", PathImpl.createPathFromString("name"), notEmptyNameDescriptor, ElementType.FIELD, null));
violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-length", null, null, "interpolated", Wine.class, bean, new Object(),
"value", PathImpl.createPathFromString("name"), lengthNameDescriptor, ElementType.FIELD, null));
violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("grapes-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
"value", PathImpl.createPathFromString("grapes"), notEmptyGrapesDescriptor, ElementType.FIELD, null));
final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);
final ValidationJsonException validationJsonException = new ValidationJsonException(violationException);
Assert.assertFalse(validationJsonException.getErrors().isEmpty());
Assert.assertEquals("{name=[{rule=name-Empty}, {rule=name-length, parameters={min=0, max=50}}], grapes=[{rule=grapes-Empty}]}",
validationJsonException.getErrors().toString());
}
示例6: addValidationError
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Utility method for adding error of ConstraintViolation. Usually when a @Validated validation fails.
*
* @param cv the ConstraintViolation
*/
private void addValidationError(ConstraintViolation<?> cv) {
this.addValidationError(
cv.getRootBeanClass().getSimpleName(),
((PathImpl) cv.getPropertyPath()).getLeafNode().asString(),
cv.getInvalidValue(),
cv.getMessage());
}
示例7: NodeBuilderCustomizableContextImpl
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* constructor.
*
* @param parent ConstraintViolationBuilderImpl which is parent
* @param messageTemplate message template
* @param path path of the element
*/
public NodeBuilderCustomizableContextImpl(final ConstraintViolationBuilderImpl parent,
final String messageTemplate, final PathImpl path) {
super();
this.parent = parent;
this.messageTemplate = messageTemplate;
this.path = path;
}
示例8: NodeContextBuilderImpl
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* constructor.
*
* @param parent ConstraintViolationBuilderImpl which is parent
* @param messageTemplate message template
* @param path path of the element
*/
public NodeContextBuilderImpl(final PathImpl path, final String messageTemplate,
final ConstraintViolationBuilderImpl parent) {
super();
this.path = path;
this.messageTemplate = messageTemplate;
this.parent = parent;
}
示例9: ConstraintValidatorContextImpl
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* constructor.
*
* @param path path of the element
* @param descriptor constraint descriptor
*/
public ConstraintValidatorContextImpl(final PathImpl path,
final ConstraintDescriptor<A> descriptor) {
super();
this.basePath = path;
this.descriptor = descriptor;
}
示例10: append
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Append a node named name to the path..
*
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> append(final String name) {
final GwtValidationContext<T> temp = new GwtValidationContext<>(this.rootBeanClass,
this.rootBean, this.beanDescriptor, this.messageInterpolator, this.traversableResolver,
this.validator, this.validatedObjects);
temp.path = PathImpl.createCopy(this.path);
temp.path.addPropertyNode(name);
return temp;
}
示例11: appendIndex
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Append an indexed node to the path.
*
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> appendIndex(final String name, final int index) {
final GwtValidationContext<T> temp = new GwtValidationContext<>(this.rootBeanClass,
this.rootBean, this.beanDescriptor, this.messageInterpolator, this.traversableResolver,
this.validator, this.validatedObjects);
temp.path = PathImpl.createCopy(this.path);
temp.path.addParameterNode(name, index);
temp.path.makeLeafNodeIterable();
temp.path.makeLeafNodeIterableAndSetIndex(index);
return temp;
}
示例12: appendIterable
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Append an iterable node to the path.
*
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> appendIterable(final String name) {
final GwtValidationContext<T> temp = new GwtValidationContext<>(this.rootBeanClass,
this.rootBean, this.beanDescriptor, this.messageInterpolator, this.traversableResolver,
this.validator, this.validatedObjects);
temp.path = PathImpl.createCopy(this.path);
temp.path.addPropertyNode(name);
temp.path.makeLeafNodeIterable();
return temp;
}
示例13: appendKey
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* Append a keyed node to the path.
*
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> appendKey(final String name, final Object key) {
final GwtValidationContext<T> temp = new GwtValidationContext<>(this.rootBeanClass,
this.rootBean, this.beanDescriptor, this.messageInterpolator, this.traversableResolver,
this.validator, this.validatedObjects);
temp.path = PathImpl.createCopy(this.path);
temp.path.addPropertyNode(name);
NodeImpl.makeIterableAndSetMapKey(temp.path.getLeafNode(), key);
return temp;
}
示例14: ConstraintViolationCreationContext
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
/**
* constructor.
*/
public ConstraintViolationCreationContext(final String message, final PathImpl property,
final Map<String, Object> messageParameters, final Map<String, Object> expressionVariables,
final Object dynamicPayload) {
this.message = message;
this.propertyPath = property;
this.messageParameters = toImmutableMap(messageParameters);
this.expressionVariables = toImmutableMap(expressionVariables);
this.dynamicPayload = dynamicPayload;
}
示例15: compose
import org.hibernate.validator.internal.engine.path.PathImpl; //导入依赖的package包/类
@Override
protected void compose(final ClassSourceFileComposerFactory composerFactory) {
this.addImports(composerFactory, Annotation.class, ConstraintViolation.class, GWT.class,
ValidationGroupsMetadata.class, Group.class, GroupChain.class, PathImpl.class, Node.class,
GroupChainGenerator.class, GwtBeanDescriptor.class, BeanMetadata.class,
GwtValidationContext.class, ArrayList.class, HashSet.class, IllegalArgumentException.class,
Set.class, Collection.class, Iterator.class, List.class, ValidationException.class);
composerFactory.setSuperclass(AbstractGwtSpecificValidator.class.getCanonicalName() + "<"
+ this.beanType.getQualifiedSourceName() + ">");
composerFactory.addImplementedInterface(this.validatorType.getName());
}