本文整理汇总了Java中org.kuali.rice.krad.datadictionary.validation.constraint.LengthConstraint类的典型用法代码示例。如果您正苦于以下问题:Java LengthConstraint类的具体用法?Java LengthConstraint怎么用?Java LengthConstraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LengthConstraint类属于org.kuali.rice.krad.datadictionary.validation.constraint包,在下文中一共展示了LengthConstraint类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processSingleLengthConstraint
import org.kuali.rice.krad.datadictionary.validation.constraint.LengthConstraint; //导入依赖的package包/类
protected ConstraintValidationResult processSingleLengthConstraint(DictionaryValidationResult result, Object value,
LengthConstraint constraint,
AttributeValueReader attributeValueReader) throws AttributeValidationException {
// Can't process any range constraints on null values
if (ValidationUtils.isNullOrEmpty(value)) {
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
DataType dataType = constraint.getDataType();
Object typedValue = value;
if (dataType != null) {
typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
}
// The only thing that can have a length constraint currently is a string.
if (typedValue instanceof String) {
return validateLength(result, (String) typedValue, constraint, attributeValueReader);
}
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
示例2: init
import org.kuali.rice.krad.datadictionary.validation.constraint.LengthConstraint; //导入依赖的package包/类
@Override
public void init() {
resolverMap = new HashMap<String, ConstraintResolver<AttributeDefinition>>();
resolverMap.put(SimpleConstraint.class.getName(), new SimpleConstraintResolver<AttributeDefinition>());
resolverMap.put(CaseConstraint.class.getName(), new CaseConstraintResolver<AttributeDefinition>());
resolverMap.put(DataTypeConstraint.class.getName(), new DefinitionConstraintResolver<AttributeDefinition>());
resolverMap.put(LengthConstraint.class.getName(), new DefinitionConstraintResolver<AttributeDefinition>());
resolverMap.put(ValidCharactersConstraint.class.getName(),
new ValidCharactersConstraintResolver<AttributeDefinition>());
resolverMap.put(PrerequisiteConstraint.class.getName(),
new PrerequisiteConstraintsResolver<AttributeDefinition>());
resolverMap.put(MustOccurConstraint.class.getName(), new MustOccurConstraintsResolver<AttributeDefinition>());
}
示例3: process
import org.kuali.rice.krad.datadictionary.validation.constraint.LengthConstraint; //导入依赖的package包/类
/**
* @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult,
* Object, org.kuali.rice.krad.datadictionary.validation.constraint.Constraint,
* org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
*/
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, LengthConstraint constraint,
AttributeValueReader attributeValueReader) throws AttributeValidationException {
// To accommodate the needs of other processors, the ConstraintProcessor.process() method returns a list of ConstraintValidationResult objects
// but since a definition that is length constrained only constrains a single field, there is effectively always a single constraint
// being imposed
return new ProcessorResult(processSingleLengthConstraint(result, value, constraint, attributeValueReader));
}
示例4: getConstraintType
import org.kuali.rice.krad.datadictionary.validation.constraint.LengthConstraint; //导入依赖的package包/类
/**
* @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#getConstraintType()
*/
@Override
public Class<? extends Constraint> getConstraintType() {
return LengthConstraint.class;
}
示例5: validateLength
import org.kuali.rice.krad.datadictionary.validation.constraint.LengthConstraint; //导入依赖的package包/类
protected ConstraintValidationResult validateLength(DictionaryValidationResult result, String value,
LengthConstraint constraint, AttributeValueReader attributeValueReader) throws IllegalArgumentException {
Integer valueLength = Integer.valueOf(value.length());
Integer maxLength = constraint.getMaxLength();
Integer minLength = constraint.getMinLength();
Result lessThanMax = ValidationUtils.isLessThanOrEqual(valueLength, maxLength);
Result greaterThanMin = ValidationUtils.isGreaterThanOrEqual(valueLength, minLength);
// It's okay for one end of the range to be undefined - that's not an error. It's only an error if one of them is invalid
if (lessThanMax != Result.INVALID && greaterThanMin != Result.INVALID) {
// Of course, if they're both undefined then we didn't actually have a real constraint
if (lessThanMax == Result.UNDEFINED && greaterThanMin == Result.UNDEFINED) {
return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
}
// In this case, we've succeeded
return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
}
String maxErrorParameter = maxLength != null ? maxLength.toString() : null;
String minErrorParameter = minLength != null ? minLength.toString() : null;
// If both comparisons happened then if either comparison failed we can show the end user the expected range on both sides.
if (lessThanMax != Result.UNDEFINED && greaterThanMin != Result.UNDEFINED) {
return result.addError(RANGE_KEY, attributeValueReader, CONSTRAINT_NAME,
RiceKeyConstants.ERROR_OUT_OF_RANGE, minErrorParameter, maxErrorParameter);
}
// If it's the max comparison that fails, then just tell the end user what the max can be
else if (lessThanMax == Result.INVALID) {
return result.addError(MAX_LENGTH_KEY, attributeValueReader, CONSTRAINT_NAME,
RiceKeyConstants.ERROR_INCLUSIVE_MAX, maxErrorParameter);
}
// Otherwise, just tell them what the min can be
else {
return result.addError(MIN_LENGTH_KEY, attributeValueReader, CONSTRAINT_NAME,
RiceKeyConstants.ERROR_EXCLUSIVE_MIN, minErrorParameter);
}
}