當前位置: 首頁>>代碼示例>>Java>>正文


Java Path類代碼示例

本文整理匯總了Java中javax.validation.Path的典型用法代碼示例。如果您正苦於以下問題:Java Path類的具體用法?Java Path怎麽用?Java Path使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Path類屬於javax.validation包,在下文中一共展示了Path類的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: setupConstraintViolation

import javax.validation.Path; //導入依賴的package包/類
private ConstraintViolation<Object> setupConstraintViolation(Class offendingObjectClass, String path, Class<? extends Annotation> annotationClass, String message) {
    ConstraintViolation<Object> mockConstraintViolation = mock(ConstraintViolation.class);

    Path mockPath = mock(Path.class);
    doReturn(path).when(mockPath).toString();

    Annotation mockAnnotation = mock(Annotation.class);
    doReturn(annotationClass).when(mockAnnotation).annotationType();

    ConstraintDescriptor<?> mockConstraintDescriptor = mock(ConstraintDescriptor.class);
    doReturn(mockAnnotation).when(mockConstraintDescriptor).getAnnotation();

    when(mockConstraintViolation.getPropertyPath()).thenReturn(mockPath);
    doReturn(mockConstraintDescriptor).when(mockConstraintViolation).getConstraintDescriptor();
    when(mockConstraintViolation.getMessage()).thenReturn(message);

    doReturn(offendingObjectClass).when(mockConstraintViolation).getRootBeanClass();

    return mockConstraintViolation;
}
 
開發者ID:Nike-Inc,項目名稱:backstopper,代碼行數:21,代碼來源:ClientDataValidationErrorHandlerListenerTest.java

示例3: setupConstraintViolation

import javax.validation.Path; //導入依賴的package包/類
private ConstraintViolation<Object> setupConstraintViolation(String path, Class<? extends Annotation> annotationClass, String message) {
    ConstraintViolation<Object> mockConstraintViolation = mock(ConstraintViolation.class);

    Path mockPath = mock(Path.class);
    doReturn(path).when(mockPath).toString();

    Annotation mockAnnotation = mock(Annotation.class);
    doReturn(annotationClass).when(mockAnnotation).annotationType();

    ConstraintDescriptor<?> mockConstraintDescriptor = mock(ConstraintDescriptor.class);
    doReturn(mockAnnotation).when(mockConstraintDescriptor).getAnnotation();

    when(mockConstraintViolation.getPropertyPath()).thenReturn(mockPath);
    doReturn(mockConstraintDescriptor).when(mockConstraintViolation).getConstraintDescriptor();
    when(mockConstraintViolation.getMessage()).thenReturn(message);

    return mockConstraintViolation;
}
 
開發者ID:Nike-Inc,項目名稱:backstopper,代碼行數:19,代碼來源:ServersideValidationErrorHandlerListenerTest.java

示例4: 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

示例5: validateAdditionalRules

import javax.validation.Path; //導入依賴的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

示例6: makePath

import javax.validation.Path; //導入依賴的package包/類
private String makePath ( final ConstraintViolation<Object> entry )
{
    final StringBuilder sb = new StringBuilder ();

    final Path p = entry.getPropertyPath ();
    for ( final Node n : p )
    {
        if ( sb.length () > 0 )
        {
            sb.append ( '.' );
        }
        sb.append ( n.getName () );
    }

    return sb.toString ();
}
 
開發者ID:eclipse,項目名稱:packagedrone,代碼行數:17,代碼來源:JavaValidator.java

示例7: 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

示例8: 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

示例9: 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

示例10: instantiate

import javax.validation.Path; //導入依賴的package包/類
/**
 * instantiate a ConstraintViolationImpl.
 *
 * @param streamReader serialized stream reader to take data from
 * @return ConstraintViolationImpl
 * @throws SerializationException if deserialization fails
 */
public static ConstraintViolationImpl<Object> instantiate(
    final SerializationStreamReader streamReader) throws SerializationException {

  final String messageTemplate = null;
  final String interpolatedMessage = streamReader.readString();
  final Class<Object> rootBeanClass = null;
  final Object rootBean = null;
  final Object leafBeanInstance = null;
  final Object value = null;
  final Path propertyPath = (Path) streamReader.readObject();
  final ConstraintDescriptor<?> constraintDescriptor = null;
  final ElementType elementType = null;
  final Map<String, Object> messageParameters = new HashMap<>();
  final Map<String, Object> expressionVariables = new HashMap<>();
  return (ConstraintViolationImpl<Object>) ConstraintViolationImpl.forBeanValidation(
      messageTemplate, messageParameters, expressionVariables, interpolatedMessage, rootBeanClass,
      rootBean, leafBeanInstance, value, propertyPath, constraintDescriptor, elementType, null);
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-bean-validators,代碼行數:26,代碼來源:ConstraintViolationImpl_CustomFieldSerializer.java

示例11: ConstraintViolationImpl

import javax.validation.Path; //導入依賴的package包/類
private ConstraintViolationImpl(final String messageTemplate,
    final Map<String, Object> messageParameters, final Map<String, Object> expressionVariables,
    final String interpolatedMessage, final Class<T> rootBeanClass, final T rootBean,
    final Object leafBeanInstance, final Object value, final Path propertyPath,
    final ConstraintDescriptor<?> constraintDescriptor, final ElementType elementType,
    final Object[] executableParameters, final Object executableReturnValue,
    final Object dynamicPayload) {
  this.messageTemplate = messageTemplate;
  this.messageParameters = messageParameters;
  this.expressionVariables = expressionVariables;
  this.interpolatedMessage = interpolatedMessage;
  this.rootBean = rootBean;
  this.value = value;
  this.propertyPath = propertyPath;
  this.leafBeanInstance = leafBeanInstance;
  this.constraintDescriptor = constraintDescriptor;
  this.rootBeanClass = rootBeanClass;
  this.elementType = elementType;
  this.executableParameters = executableParameters;
  this.executableReturnValue = executableReturnValue;
  this.dynamicPayload = dynamicPayload;
  // pre-calculate hash code, the class is immutable and hashCode is needed often
  this.hashCodeValue = this.createHashCode();
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-bean-validators,代碼行數:25,代碼來源:ConstraintViolationImpl.java

示例12: 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

示例13: createConstraintViolations

import javax.validation.Path; //導入依賴的package包/類
private static ConstraintViolation<Object> createConstraintViolations(
		LanguageProvider languageProvider, ClassInfo classInfo,
		Object domainObject, ValidationViolation validationViolation) {
	String messageTemplateKey = validationViolation.getMessageTemplateKey();
	String messageTemplateDefault = validationViolation
			.getMessageTemplateInEnglish();
	String messageTemplate = languageProvider.getText(messageTemplateKey,
			messageTemplateDefault);
	Object invalidValue = validationViolation.getInvalidValue();
	String message = String.format(messageTemplate, invalidValue);
	Path path = PathImpl.create(classInfo.getSimpleName());
	@SuppressWarnings("unchecked")
	Class<Object> rootBeanClass = (Class<Object>) domainObject.getClass();
	ConstraintDescriptor<?> constraintDescriptor = null;
	ElementType elementType = null;
	ConstraintViolationImpl<Object> constraintViolation = new ConstraintViolationImpl<Object>(
			messageTemplate, message, domainObject, domainObject, path,
			domainObject, constraintDescriptor, rootBeanClass, elementType);
	return constraintViolation;
}
 
開發者ID:ntenhoeve,項目名稱:Introspect-Framework,代碼行數:21,代碼來源:ConstrainViolationFactory.java

示例14: toResponse

import javax.validation.Path; //導入依賴的package包/類
@Override
public Response toResponse(ConstraintViolationException exception) {

    LOGGER.debug("Validation constraint violation {}", exception.getConstraintViolations());

    ValidationMessage validationMessage = new ValidationMessage();
    Set<ConstraintViolation<?>> violations = exception.getConstraintViolations();
    Multimap<String, String> errors = ArrayListMultimap.create();
    for (ConstraintViolation<?> cv : violations) {
        String name = StreamSupport.stream(cv.getPropertyPath().spliterator(), false)
                .map(Path.Node::getName)
                .reduce((first, second) -> second)
                .orElseGet(() -> cv.getPropertyPath().toString());
        errors.put(name, cv.getMessage());
    }

    validationMessage.setErrors(errors.asMap());

    return Response.status(Response.Status.BAD_REQUEST)
            .entity(validationMessage)
            .build();
}
 
開發者ID:paukiatwee,項目名稱:budgetapp,代碼行數:23,代碼來源:ConstraintViolationExceptionMapper.java

示例15: 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


注:本文中的javax.validation.Path類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。