本文整理汇总了Java中javax.validation.ElementKind类的典型用法代码示例。如果您正苦于以下问题:Java ElementKind类的具体用法?Java ElementKind怎么用?Java ElementKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ElementKind类属于javax.validation包,在下文中一共展示了ElementKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateAdditionalRules
import javax.validation.ElementKind; //导入依赖的package包/类
public void validateAdditionalRules(ValidationErrors errors) {
// all previous validations return no errors
if (crossFieldValidate && errors.isEmpty()) {
BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
Validator validator = beanValidation.getValidator();
Set<ConstraintViolation<Entity>> violations = validator.validate(getItem(), UiCrossFieldChecks.class);
violations.stream()
.filter(violation -> {
Path propertyPath = violation.getPropertyPath();
Path.Node lastNode = Iterables.getLast(propertyPath);
return lastNode.getKind() == ElementKind.BEAN;
})
.forEach(violation -> errors.add(violation.getMessage()));
}
}
示例2: testExtractViolationInfoFromNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* Test of extractViolationInfoFromNode method, of class ConstraintServices.
*/
@Test
public void testExtractViolationInfoFromNode() {
System.out.println("extractViolationInfoFromNode");
Path.Node node = mock(Path.Node.class);
when(node.getKind()).thenReturn(ElementKind.METHOD).thenReturn(ElementKind.PARAMETER).thenReturn(ElementKind.PROPERTY);
when(node.getName()).thenReturn("arg0").thenReturn("prop");
doReturn(5).when(instance).getIndexFromArgname(anyString());
ConstraintViolation cv = new ConstraintViolation();
instance.extractViolationInfoFromNode(node, cv);
assertThat(cv.getMessage()).isNull();
assertThat(cv.getIndex()).isEqualTo(0);
assertThat(cv.getProp()).isNull();
cv = new ConstraintViolation();
instance.extractViolationInfoFromNode(node, cv);
assertThat(cv.getMessage()).isNull();
assertThat(cv.getIndex()).isEqualTo(5);
assertThat(cv.getProp()).isNull();
cv = new ConstraintViolation();
instance.extractViolationInfoFromNode(node, cv);
assertThat(cv.getMessage()).isNull();
assertThat(cv.getIndex()).isEqualTo(0);
assertThat(cv.getProp()).isEqualTo("prop");
}
示例3: NodeImpl
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* constructor, do not use.
*/
public NodeImpl(final String name, final NodeImpl parent, final boolean isIterable,
final Integer index, final Object key, final ElementKind kind,
final Class<?>[] parameterTypes, final Integer parameterIndex, final Object value,
final Class<?> containerClass, final Integer typeArgumentIndex) {
this.name = name;
this.parent = parent;
this.index = index;
this.key = key;
this.value = value;
this.isIterableValue = isIterable;
this.kind = kind;
this.parameterTypes = parameterTypes;
this.parameterIndex = parameterIndex;
this.containerClass = containerClass;
this.typeArgumentIndex = typeArgumentIndex;
}
示例4: createPropertyNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create property node.
*
* @param name name of the node
* @param parent parent node
* @return new node implementation
*/
// TODO It would be nicer if we could return PropertyNode
public static NodeImpl createPropertyNode(final String name, final NodeImpl parent) {
return new NodeImpl( //
name, //
parent, //
false, //
null, //
null, //
ElementKind.PROPERTY, //
EMPTY_CLASS_ARRAY, //
null, //
null, //
null, //
null //
);
}
示例5: createContainerElementNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create container element node.
*
* @param name name of the node
* @param parent parent node
* @return new node implementation
*/
public static NodeImpl createContainerElementNode(final String name, final NodeImpl parent) {
return new NodeImpl( //
name, //
parent, //
false, //
null, //
null, //
ElementKind.CONTAINER_ELEMENT, //
EMPTY_CLASS_ARRAY, //
null, //
null, //
null, //
null //
);
}
示例6: createParameterNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create parameter node.
*
* @param name name of the node
* @param parent parent node
* @return new node implementation
*/
public static NodeImpl createParameterNode(final String name, final NodeImpl parent,
final int parameterIndex) {
return new NodeImpl( //
name, //
parent, //
false, //
null, //
null, //
ElementKind.PARAMETER, //
EMPTY_CLASS_ARRAY, //
parameterIndex, //
null, //
null, //
null //
);
}
示例7: createCrossParameterNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create cross parameter node node.
*
* @param parent parent node
* @return new node implementation
*/
public static NodeImpl createCrossParameterNode(final NodeImpl parent) {
return new NodeImpl( //
CROSS_PARAMETER_NODE_NAME, //
parent, //
false, //
null, //
null, //
ElementKind.CROSS_PARAMETER, //
EMPTY_CLASS_ARRAY, //
null, //
null, //
null, //
null //
);
}
示例8: createMethodNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create method node.
*
* @param name name of the node
* @param parent parent node
* @param parameterTypes parameter types
* @return new node implementation
*/
public static NodeImpl createMethodNode(final String name, final NodeImpl parent,
final Class<?>[] parameterTypes) {
return new NodeImpl( //
name, //
parent, //
false, //
null, //
null, //
ElementKind.METHOD, //
parameterTypes, //
null, //
null, //
null, //
null //
);
}
示例9: createConstructorNode
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create constructor node.
*
* @param name name of the node
* @param parent parent node
* @param parameterTypes parameter types
* @return new node implementation
*/
public static NodeImpl createConstructorNode(final String name, final NodeImpl parent,
final Class<?>[] parameterTypes) {
return new NodeImpl( //
name, //
parent, //
false, //
null, //
null, //
ElementKind.CONSTRUCTOR, //
parameterTypes, //
null, //
null, //
null, //
null //
);
}
示例10: createReturnValue
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* create return node.
*
* @param parent parent node
* @return new node implementation
*/
public static NodeImpl createReturnValue(final NodeImpl parent) {
return new NodeImpl( //
RETURN_VALUE_NODE_NAME, //
parent, //
false, //
null, //
null, //
ElementKind.RETURN_VALUE, //
EMPTY_CLASS_ARRAY, //
null, //
null, //
null, //
null //
);
}
示例11: as
import javax.validation.ElementKind; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends Path.Node> T as(final Class<T> nodeType) throws ClassCastException { // NOPMD
if (this.kind == ElementKind.BEAN && nodeType == BeanNode.class
|| this.kind == ElementKind.CONSTRUCTOR && nodeType == ConstructorNode.class
|| this.kind == ElementKind.CROSS_PARAMETER && nodeType == CrossParameterNode.class
|| this.kind == ElementKind.METHOD && nodeType == MethodNode.class
|| this.kind == ElementKind.PARAMETER && nodeType == ParameterNode.class
|| this.kind == ElementKind.PROPERTY && (nodeType == PropertyNode.class
|| nodeType == org.hibernate.validator.path.PropertyNode.class)
|| this.kind == ElementKind.RETURN_VALUE && nodeType == ReturnValueNode.class
|| this.kind == ElementKind.CONTAINER_ELEMENT && (nodeType == ContainerElementNode.class
|| nodeType == org.hibernate.validator.path.ContainerElementNode.class)) {
return (T) this;
}
throw LOG.getUnableToNarrowNodeTypeException(this.getClass(), this.kind, nodeType);
}
示例12: getResponseStatus
import javax.validation.ElementKind; //导入依赖的package包/类
/**
* Determine the response status (400 or 500) from the given BV exception.
*
* @param violation BV exception.
* @return response status (400 or 500).
*/
public static Response.Status getResponseStatus(final ConstraintViolationException violation) {
final Iterator<ConstraintViolation<?>> iterator = violation.getConstraintViolations().iterator();
if (iterator.hasNext()) {
for (final Path.Node node : iterator.next().getPropertyPath()) {
final ElementKind kind = node.getKind();
if (ElementKind.RETURN_VALUE.equals(kind)) {
return Response.Status.INTERNAL_SERVER_ERROR;
}
}
}
return Response.Status.BAD_REQUEST;
}
示例13: createBody
import javax.validation.ElementKind; //导入依赖的package包/类
@Override
public ValidationErrorMessage createBody(ConstraintViolationException ex, HttpServletRequest req) {
ErrorMessage tmpl = super.createBody(ex, req);
ValidationErrorMessage msg = new ValidationErrorMessage(tmpl);
for (ConstraintViolation<?> violation : ex.getConstraintViolations()) {
Node pathNode = findLastNonEmptyPathNode(violation.getPropertyPath());
// path is probably useful only for properties (fields)
if (pathNode != null && pathNode.getKind() == ElementKind.PROPERTY) {
msg.addError(pathNode.getName(), convertToString(violation.getInvalidValue()), violation.getMessage());
// type level constraints etc.
} else {
msg.addError(violation.getMessage());
}
}
return msg;
}
开发者ID:jirutka,项目名称:spring-rest-exception-handler,代码行数:21,代码来源:ConstraintViolationExceptionHandler.java
示例14: beforeNode
import javax.validation.ElementKind; //导入依赖的package包/类
@Override
public void beforeNode(Object obj, DescriptorPath path) {
if (path.getHeadNode().getKind() != ElementKind.BEAN) {
return;
}
BeanDescriptorNode node = path.getHeadNode().as(BeanDescriptorNode.class);
Named named = ReflectionHelper.findAnnotation(node.getBean().getClass(), Named.class);
Referenced referenced = ReflectionHelper.findAnnotation(node.getBean().getClass(), Referenced.class);
if (referenced != null) {
if (referenced.as().length == 0 && named == null) {
throw new IllegalStateException("The @Referenced annotation requires the @Named to also exist.");
}
ReferenceType type = referenced.type();
references.put(type, path.onlyInclude(ElementKind.BEAN));
}
}
示例15: callReferenceConstraints
import javax.validation.ElementKind; //导入依赖的package包/类
private void callReferenceConstraints(Object obj, DescriptorPath path) {
DescriptorNode node = path.getHeadNode();
for (ReferenceConstraint<T> constraint : constraints) {
if (node.getClass().isAssignableFrom(constraint.getNodeType())) {
continue;
}
Annotation annotation;
Class<? extends Annotation> annClass = constraint.getAnnotationType();
if (node.getKind() == ElementKind.BEAN) {
annotation = ReflectionHelper.findAnnotation(obj.getClass(), annClass);
} else if (node.getKind() == ElementKind.PROPERTY) {
Method method = node.as(PropertyNode.class).getMethod();
annotation = ReflectionHelper.findAnnotation(method, annClass);
} else {
throw new IllegalStateException(node.getKind() + " is an unsupported type.");
}
if (annotation == null) {
continue;
}
this.violations.addAll(constraint.checkConstraint(annotation, obj, path, allowedRefs));
}
}