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


Java ConstraintValidatorContext類代碼示例

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


ConstraintValidatorContext類屬於javax.validation包,在下文中一共展示了ConstraintValidatorContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateInterestDate

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
private boolean validateInterestDate(Object validateThis,
                                     ConstraintValidatorContext ctx,
                                     Field fieldObj,
                                     Field dependentFieldObj) throws IllegalAccessException {
    InterestDate interestDate = (InterestDate) fieldObj.get(validateThis);
    Interest interest = (Interest) dependentFieldObj.get(validateThis);
    if (interest != null && !interestTypeIsNoInterest(interest.getType())) {
        Set<ConstraintViolation<Object>> violations = validator.validate(interestDate);
        if (!violations.isEmpty()) {
            ctx.disableDefaultConstraintViolation();
            ctx.buildConstraintViolationWithTemplate(getViolationMessages(violations, ctx))
                .addPropertyNode(field)
                .addConstraintViolation();

            return false;
        }
    }
    return true;
}
 
開發者ID:hmcts,項目名稱:cmc-claim-store,代碼行數:20,代碼來源:InterDependentFieldsConstraintValidator.java

示例2: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
public boolean isValid(Object value, ConstraintValidatorContext context) {
	boolean returnValue = false;
	try {
		Comparable first = (Comparable) getNestedProperty(value, property);
		Object second = getNestedProperty(value, otherProperty);
		if (first == null) {
			returnValue = true;
		} else if (second != null) {
			returnValue = doComparison(first, second, comparison);
		}
		// Wenn first != null und second == null: Prüfung würde NPE bewirken, einfach false zurückgeben.
	} catch (Exception e) {
		throw new ValidationException("Cannot read property " + property + " and comparison property " + otherProperty);
	}
	if (!returnValue) {
		createViolationMessageForNestedProperty(property, messageTemplate, context);
	}
	return returnValue;
}
 
開發者ID:dvbern,項目名稱:beanvalidation,代碼行數:20,代碼來源:CompareToValidator.java

示例3: validateRate

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
private boolean validateRate(Object validateThis,
                             ConstraintValidatorContext ctx,
                             Field fieldObj,
                             Field dependentFieldObj) throws IllegalAccessException {
    BigDecimal rate = (BigDecimal) fieldObj.get(validateThis);
    Interest.InterestType type = (Interest.InterestType) dependentFieldObj.get(validateThis);
    if ((type == null || !interestTypeIsNoInterest(type)) && rate == null) {
        ctx.disableDefaultConstraintViolation();
        ctx.buildConstraintViolationWithTemplate("may not be null")
            .addPropertyNode(field)
            .addConstraintViolation();

        return false;

    }
    return true;
}
 
開發者ID:hmcts,項目名稱:cmc-claim-store,代碼行數:18,代碼來源:InterDependentFieldsConstraintValidator.java

示例4: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(final String password, final ConstraintValidatorContext context) {
    final PasswordValidator validator = new PasswordValidator(singletonList(
        new LengthRule(8, 30)
        // More rules can be added to increase security
    ));

    final RuleResult result = validator.validate(new PasswordData(password));
    if (result.isValid()) {
        return true;
    }

    context.disableDefaultConstraintViolation();
    context.buildConstraintViolationWithTemplate(
        validator.getMessages(result).stream().collect(joining("\n"))
    ).addConstraintViolation();

    return false;
}
 
開發者ID:membaza,項目名稱:users-service,代碼行數:20,代碼來源:PasswordConstraintValidator.java

示例5: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(List<String> values, ConstraintValidatorContext context) {
	
	if(values == null || values.isEmpty()) {
		return true;
	}
	
	for (String val : values) {
		boolean valid = false;
		for(String cat: categories) {
			if(cat.equals(val)) {
				valid = true;
			}
		}
		
		if(!valid) {
			context.disableDefaultConstraintViolation();
			context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
			return false;
		}
	}
	return true;
}
 
開發者ID:Code4SocialGood,項目名稱:c4sg-services,代碼行數:24,代碼來源:ListEntryValidator.java

示例6: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(CountyCourtJudgment ccj, ConstraintValidatorContext context) {
    if (ccj == null) {
        return true;
    }

    PaymentOption type = ccj.getPaymentOption();
    boolean payByDateIsPopulated = ccj.getPayBySetDate().isPresent();
    boolean repaymentPlanIsPopulated = ccj.getRepaymentPlan().isPresent();

    boolean isValidImmediately = type.equals(IMMEDIATELY) && !payByDateIsPopulated && !repaymentPlanIsPopulated;
    boolean isValidFull = type.equals(FULL_BY_SPECIFIED_DATE) && payByDateIsPopulated && !repaymentPlanIsPopulated;
    boolean isValidByInstalments = type.equals(INSTALMENTS) && !payByDateIsPopulated && repaymentPlanIsPopulated;

    return isValidImmediately || isValidFull || isValidByInstalments;
}
 
開發者ID:hmcts,項目名稱:cmc-claim-store,代碼行數:17,代碼來源:ValidCountyCourtJudgmentValidator.java

示例7: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if(value == null) {
		return false;
	}
	
	check = new SafeguardCheck();
	parametros.forEach((parametro) -> check.elementOf(value, parametro).validate());
	
	if(check.hasError()) {
		context.disableDefaultConstraintViolation();
		context.buildConstraintViolationWithTemplate("(" + value + ") contém caracteres inválidos ")
		.addConstraintViolation(); 
	}
	
	return !check.hasError();
}
 
開發者ID:gilmardeveloper,項目名稱:java-validator-safeguard,代碼行數:18,代碼來源:VerifyValidator.java

示例8: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    }
    final boolean valid = Arrays.asList(strings).contains(value);

    if (!valid) {
        HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
        hibernateContext.disableDefaultConstraintViolation();

        hibernateContext.addExpressionVariable("validValues", Joiner.on(" ").join(strings))
                .buildConstraintViolationWithTemplate(hibernateContext.getDefaultConstraintMessageTemplate())
                .addConstraintViolation();
    }

    return valid;
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:19,代碼來源:IsOneOfValidator.java

示例9: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	// 不能9位以下純數字
	if (value.matches("^\\d{1,9}")) {
		return false;
	}
	// 不能相同字符組成
	if (value.matches("^(.)\\1+$")) {
		return false;
	}
	// 不能由連續字符組成
	if (consectiveStr(value)) {
		return false;
	}
	return true;
}
 
開發者ID:onsoul,項目名稱:os,代碼行數:17,代碼來源:PasswordValidator.java

示例10: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {

    if (null == value) {
        return false;
    }

    Class<?>[] classes = annotation.value();

    for(Class<?> cls : classes) {
        if (cls.isInstance(value)) {
            return true;
        }
    }

    return false;
}
 
開發者ID:nomemory,項目名稱:java-bean-validation-extension,代碼行數:18,代碼來源:InstanceOfValidator.java

示例11: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {

    if (null == value) {
        return false;
    }

    CreditCardType[] types = annotation.value();

    for(CreditCardType creditCardType : types) {
        CreditCardValidator ccv =
                new CreditCardValidator(creditCardType.getInternalValue());
        if (ccv.isValid(value)) {
            return true;
        }
    }

    return false;
}
 
開發者ID:nomemory,項目名稱:java-bean-validation-extension,代碼行數:20,代碼來源:CCValidator.java

示例12: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {

    if (null == value) {
        return false;
    }

    ParseableType type = annotation.value();

    switch (type) {
        case TO_INT:
            return catcher(value, Integer::parseInt);
        case TO_DOUBLE:
            return catcher(value, Double::parseDouble);
        case TO_LONG:
            return catcher(value, Long::parseLong);
        case TO_SHORT:
            return catcher(value, Short::parseShort);
        case TO_FLOAT:
            return catcher(value, Float::parseFloat);
    }

    return false;
}
 
開發者ID:nomemory,項目名稱:java-bean-validation-extension,代碼行數:25,代碼來源:ParseableValidator.java

示例13: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
    try {
        if (StringUtils.isEmpty(value)) {
            return true; // do not validate empty value there are other constraints for that e.g. @NotNull, @Size etc...
        }

        final Path path = Paths.get(value);

        if (checkIfExists && !path.toFile().exists()) {
            return false;
        }

        final String fileExt = FilenameUtils.getExtension(value);
        return allowableFileExtensions.isEmpty() ||
               !allowableFileExtensions.stream().filter(fileExt::equalsIgnoreCase).findFirst().orElse(StringUtils.EMPTY).isEmpty();

    } catch (final InvalidPathException e) {
        LOGGER.error(e.getMessage(), e);
        return false;
    }
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:23,代碼來源:PathValidator.java

示例14: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
	Object fieldValue = new BeanWrapperImpl(value).getPropertyValue(field);
	Object fieldMatchValue = new BeanWrapperImpl(value).getPropertyValue(fieldMatch);
	boolean result = false;
	
	if(fieldValue != null)
	{
		//Passwords are kept as char arrays, other values mostly as Strings
		if(fieldValue instanceof char[])
			result =  Arrays.equals((char[])fieldValue, (char[])fieldMatchValue);
		else result = fieldValue.equals(fieldMatchValue);
	} else
		result = fieldMatchValue == null;
	return result;
}
 
開發者ID:Azanx,項目名稱:Smart-Shopping,代碼行數:17,代碼來源:FieldsVerificationValidator.java

示例15: isValid

import javax.validation.ConstraintValidatorContext; //導入依賴的package包/類
@Override
public boolean isValid(MultipartFile[] multipartFiles, ConstraintValidatorContext constraintValidatorContext) {
    long _totalSize = 0L;
    if (multipartFiles == null || multipartFiles.length <= 0) {
        return allowEmpty;
    }
    boolean result = false;
    for (MultipartFile multipartFile : multipartFiles) {
        result = (allowSize(multipartFile) && allowContentType(multipartFile));
        if (!result) {
            return false;
        }
        _totalSize += multipartFile.getSize();
    }
    /*
      totalSize = 0 ,則不限製
      如果超出大小,則限製
     */
    return totalSize == 0 || _totalSize < totalSize;
}
 
開發者ID:egzosn,項目名稱:spring-jdbc-orm,代碼行數:21,代碼來源:MultipartFilesUploadValidate.java


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