當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。