• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ElementKind类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.validation.ElementKind的典型用法代码示例。如果您正苦于以下问题:Java ElementKind类的具体用法?Java ElementKind怎么用?Java ElementKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ElementKind类属于javax.validation包,在下文中一共展示了ElementKind类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()));
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:EditorWindowDelegate.java


示例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");
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:28,代码来源:ConstraintServicesTest.java


示例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;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:20,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:24,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:23,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:24,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:22,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:25,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:25,代码来源:NodeImpl.java


示例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 //
  );
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:22,代码来源:NodeImpl.java


示例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);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:19,代码来源:NodeImpl.java


示例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;
}
 
开发者ID:icode,项目名称:ameba,代码行数:22,代码来源:ValidationHelper.java


示例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));
  }
}
 
开发者ID:cloudera,项目名称:cm_ext,代码行数:17,代码来源:ReferenceValidatorImpl.java


示例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));
  }
}
 
开发者ID:cloudera,项目名称:cm_ext,代码行数:26,代码来源:ReferenceValidatorImpl.java


示例16: printPropertyPath

import javax.validation.ElementKind; //导入依赖的package包/类
private String printPropertyPath(Path path) {
  if (path == null) return "UNKNOWN";

  String propertyPath = "";
  Path.Node parameterNode = null;
  // Construct string representation of property path.
  // This will strip away any other nodes added by RESTEasy (method, parameter, ...).
  for (Path.Node node : path) {
    if (node.getKind() == ElementKind.PARAMETER) {
      parameterNode = node;
    }

    if (node.getKind() == ElementKind.PROPERTY) {
      if (!propertyPath.isEmpty()) {
        propertyPath += ".";
      }

      propertyPath += node;
    }
  }

  if (propertyPath.isEmpty() && parameterNode != null) {
    // No property path constructed, assume this is a validation failure on a request parameter.
    propertyPath = parameterNode.toString();
  }

  return propertyPath;
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:29,代码来源:ConstraintViolationMapper.java


示例17: resolvePath

import javax.validation.ElementKind; //导入依赖的package包/类
/**
 * Translate validated bean and root path into validated resource and
 * resource path. For example, embeddables belonging to an entity document
 * are mapped back to an entity violation and a proper path to the
 * embeddable attribute.
 *
 * @param violation to compute the reference
 * @return computaed reference
 */
private ResourceRef resolvePath(ConstraintViolation<?> violation) {
	Object resource = violation.getRootBean();

	Object nodeObject = resource;
	ResourceRef ref = new ResourceRef(resource);

	Iterator<Node> iterator = violation.getPropertyPath().iterator();
	while (iterator.hasNext()) {
		Node node = iterator.next();

		// ignore methods/parameters
		if (node.getKind() == ElementKind.METHOD) {
			continue;
		}
		if (node.getKind() == ElementKind.PARAMETER) {
			resource = getParameterValue(node);
			nodeObject = resource;
			ref = new ResourceRef(resource);
			assertResource(resource);
			continue;
		}

		// visit list, set, map references
		nodeObject = ref.getNodeReference(nodeObject, node);
		ref.visitNode(nodeObject);

		// visit property
		nodeObject = ref.visitProperty(nodeObject, node);
	}

	return ref;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:42,代码来源:ConstraintViolationExceptionMapper.java


示例18: visitProperty

import javax.validation.ElementKind; //导入依赖的package包/类
public Object visitProperty(Object nodeObject, Node node) {
	Object next;
	if (node.getKind() == ElementKind.PROPERTY) {
		next = PropertyUtils.getProperty(nodeObject, node.getName());
	}
	else if (node.getKind() == ElementKind.BEAN) {
		next = nodeObject;
	}
	else {
		throw new UnsupportedOperationException("unknown node: " + node);
	}

	if (node.getName() != null) {
		appendSeparator();
		if (!isResource(nodeObject.getClass()) || isPrimaryKey(nodeObject.getClass(), node.getName())) {
			// continue along attributes path or primary key on root
			appendSourcePointer(node.getName());
		}
		else if (isAssociation(nodeObject.getClass(), node.getName())) {
			appendSourcePointer("/data/relationships/");
			appendSourcePointer(node.getName());
		}
		else {

			appendSourcePointer("/data/attributes/");
			appendSourcePointer(node.getName());
		}
	}
	return next;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:31,代码来源:ConstraintViolationExceptionMapper.java


示例19: getKind

import javax.validation.ElementKind; //导入依赖的package包/类
@Override
public ElementKind getKind() {
	if (path == null) {
		return ElementKind.BEAN;
	} else {
		return ElementKind.PROPERTY;
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:9,代码来源:ConstraintViolationImpl.java


示例20: printPropertyPath

import javax.validation.ElementKind; //导入依赖的package包/类
private String printPropertyPath(Path path) {
    if (path == null) {
        return "UNKNOWN";
    }

    String propertyPath = "";
    Path.Node parameterNode = null;
    // Construct string representation of property path.
    // This will strip away any other nodes added by RESTEasy (method, parameter, ...).
    for (Path.Node node : path) {
        if (node.getKind() == ElementKind.PARAMETER) {
            parameterNode = node;
        }

        if (node.getKind() == ElementKind.PROPERTY) {
            if (!propertyPath.isEmpty()) {
                propertyPath += ".";
            }
            propertyPath += node;
        }
    }

    if (propertyPath.isEmpty() && parameterNode != null) {
        // No property path constructed, assume this is a validation failure on a request parameter.
        propertyPath = parameterNode.toString();
    }
    return propertyPath;
}
 
开发者ID:jhonystein,项目名称:Pedidex,代码行数:29,代码来源:ConstraintViolationMapper.java



注:本文中的javax.validation.ElementKind类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClassNotFoundException类代码示例发布时间:2022-05-21
下一篇:
Java EncryptionOperationNotPossibleException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap