本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}