当前位置: 首页>>代码示例>>Java>>正文


Java Path.Node方法代码示例

本文整理汇总了Java中javax.validation.Path.Node方法的典型用法代码示例。如果您正苦于以下问题:Java Path.Node方法的具体用法?Java Path.Node怎么用?Java Path.Node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.validation.Path的用法示例。


在下文中一共展示了Path.Node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStringBasedPath

import javax.validation.Path; //导入方法依赖的package包/类
private String getStringBasedPath(Path.Node traversableProperty, Path pathToTraversableObject) {
	StringBuilder path = new StringBuilder( );
	for ( Path.Node node : pathToTraversableObject ) {
		if (node.getName() != null) {
			path.append( node.getName() ).append( "." );
		}
	}
	if ( traversableProperty.getName() == null ) {
		throw new AssertionFailure(
				"TraversableResolver being passed a traversableProperty with null name. pathToTraversableObject: "
						+ path.toString() );
	}
	path.append( traversableProperty.getName() );

	return path.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HibernateTraversableResolver.java

示例2: getValidationErrorResponse

import javax.validation.Path; //导入方法依赖的package包/类
private List<ValidationMessage> getValidationErrorResponse(ConstraintViolationException constraintViolationException) {
    final List<ValidationMessage> validationErrors = new ArrayList<>();
    LOG.error("Got validation errors", constraintViolationException);
    for (ConstraintViolation<?> violationSet : constraintViolationException.getConstraintViolations()) {
        List<String> propertyList = new ArrayList<>();
        Iterator<Path.Node> propertyIterator = violationSet
                .getPropertyPath().iterator();
        while (propertyIterator.hasNext()) {
            propertyList.add(propertyIterator.next().getName());
        }
        // add violations errors in response
        validationErrors.add(ValidationMessage.builder()
                .entity(violationSet.getRootBeanClass().getName())
                        // remove { and }
                .messageTemplate(violationSet.getMessageTemplate().replaceAll("^[{]|[}]$", ""))
                .propertyList(propertyList).build());
    }
    return validationErrors;
}
 
开发者ID:holisticon,项目名称:continuous-delivery-demo,代码行数:20,代码来源:GlobalControllerExceptionHandler.java

示例3: convert

import javax.validation.Path; //导入方法依赖的package包/类
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
开发者ID:jurgendl,项目名称:hql-builder,代码行数:28,代码来源:JavaxValidationConverter.java

示例4: convert

import javax.validation.Path; //导入方法依赖的package包/类
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
开发者ID:jurgendl,项目名称:hql-builder,代码行数:28,代码来源:JavaxValidationConverter.java

示例5: testExtractViolationInfoFromNode

import javax.validation.Path; //导入方法依赖的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

示例6: as

import javax.validation.Path; //导入方法依赖的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

示例7: getResponseStatus

import javax.validation.Path; //导入方法依赖的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

示例8: printPropertyPath

import javax.validation.Path; //导入方法依赖的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

示例9: isReachable

import javax.validation.Path; //导入方法依赖的package包/类
public boolean isReachable(Object traversableObject,
						   Path.Node traversableProperty,
						   Class<?> rootBeanType,
						   Path pathToTraversableObject,
						   ElementType elementType) {
	//lazy, don't load
	return Hibernate.isInitialized( traversableObject )
			&& Hibernate.isPropertyInitialized( traversableObject, traversableProperty.getName() );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:HibernateTraversableResolver.java

示例10: isCascadable

import javax.validation.Path; //导入方法依赖的package包/类
public boolean isCascadable(Object traversableObject,
					  Path.Node traversableProperty,
					  Class<?> rootBeanType,
					  Path pathToTraversableObject,
					  ElementType elementType) {
	String path = getStringBasedPath( traversableProperty, pathToTraversableObject );
	return ! associations.contains(path);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:HibernateTraversableResolver.java

示例11: printPropertyPath

import javax.validation.Path; //导入方法依赖的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

示例12: ValuePath

import javax.validation.Path; //导入方法依赖的package包/类
public ValuePath(Path validationPath) {
	for (Path.Node node: validationPath) {
		if (node.getIndex() != null) 
			elements.add(new PathSegment.Element(node.getIndex()));
		if (node.getName() != null)
			elements.add(new PathSegment.Property(node.getName()));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:9,代码来源:ValuePath.java

示例13: getConstraintViolationField

import javax.validation.Path; //导入方法依赖的package包/类
/**
 * 通过根类和hibernate validator错误信息获取当前验证失败的field对象
 *
 * @param rootClass pojo根类, 如:User.class类包含属性info:Info.class,User即rootClass
 * @param cv        hibernate validator验证结果对象{@link ConstraintViolation}
 * @return 当前失败的field对象
 */
static Field getConstraintViolationField(Class<?> rootClass, ConstraintViolation<Object> cv) {

    try {
        Field field = null;
        for (Path.Node node : cv.getPropertyPath()) {
            String fieldName = node.getName();
            field = rootClass.getDeclaredField(fieldName);
            rootClass = field.getType();
        }
        return field;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Strangeen,项目名称:excel-util4j,代码行数:22,代码来源:ValidateKit.java

示例14: toResponse

import javax.validation.Path; //导入方法依赖的package包/类
@Override
public Response toResponse(ConstraintViolationException exception) {
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.BAD_REQUEST));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    // start with the overall message which will be something like "Cannot create xyz"
    final StringBuilder errorMessage = new StringBuilder(exception.getMessage()).append(" - ");

    boolean first = true;
    for (final ConstraintViolation violation : exception.getConstraintViolations()) {
        if (!first) {
            errorMessage.append(", ");
        }
        first = false;

        // lastNode should end up as the field that failed validation
        Path.Node lastNode = null;
        for (final Path.Node node : violation.getPropertyPath()) {
            lastNode = node;
        }

        // append something like "xyz must not be..."
        errorMessage.append(lastNode.getName()).append(" ").append(violation.getMessage());
    }

    return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage.toString()).type("text/plain").build();
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:31,代码来源:ConstraintViolationExceptionMapper.java

示例15: readPropertyName

import javax.validation.Path; //导入方法依赖的package包/类
private static String readPropertyName(ConstraintViolation violation) {
    Iterator<Path.Node> i = violation.getPropertyPath().iterator();
    Path.Node current = i.next();
    while (i.hasNext()) {
        current = i.next();
    }
    // Use '.' as the key if the entire object is erroneous
    if ("arg0".equals(current.getName())) {
        return ".";
    }
    else {
        return violation.getPropertyPath().toString();
    }
}
 
开发者ID:codebulb,项目名称:crudlet,代码行数:15,代码来源:RestValidationConstraintErrorBuilder.java


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