本文整理匯總了Java中org.kuali.rice.krad.datadictionary.validation.ValidationUtils.convertToDataType方法的典型用法代碼示例。如果您正苦於以下問題:Java ValidationUtils.convertToDataType方法的具體用法?Java ValidationUtils.convertToDataType怎麽用?Java ValidationUtils.convertToDataType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.kuali.rice.krad.datadictionary.validation.ValidationUtils
的用法示例。
在下文中一共展示了ValidationUtils.convertToDataType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processSingleLengthConstraint
import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的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: processDataTypeConstraint
import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
* validates the value provided using {@code DataTypeConstraint}
*
* @param result - a holder for any already run validation results
* @param dataType - the expected data type
* @param value - the value to validate
* @param attributeValueReader - provides access to the attribute being validated
* @return the passed in result, updated with the results of the processing
*/
protected ConstraintValidationResult processDataTypeConstraint(DictionaryValidationResult result, DataType dataType,
Object value, AttributeValueReader attributeValueReader) {
if (dataType == null) {
return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
}
if (ValidationUtils.isNullOrEmpty(value)) {
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
try {
ValidationUtils.convertToDataType(value, dataType, dateTimeService);
} catch (Exception e) {
switch (dataType) {
case BOOLEAN:
return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BOOLEAN);
case INTEGER:
return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_INTEGER);
case LONG:
return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_LONG);
case DOUBLE:
return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
case FLOAT:
return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
case TRUNCATED_DATE:
case DATE:
return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
case STRING:
}
}
// If we get here then it was a success!
return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
}
示例3: processSingleRangeConstraint
import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
* validates the value provided using {@code RangeConstraint}
*
* @param result - a holder for any already run validation results
* @param value - the value to validate
* @param constraint - the range constraint to use
* @param attributeValueReader - provides access to the attribute being validated
* @return the passed in result, updated with the results of the processing
* @throws AttributeValidationException if validation fails
*/
protected ConstraintValidationResult processSingleRangeConstraint(DictionaryValidationResult result, Object value,
RangeConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
// Can't process any range constraints on null values
if (ValidationUtils.isNullOrEmpty(value) || (constraint.getExclusiveMin() == null
&& constraint.getInclusiveMax() == null)) {
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
// This is necessary because sometimes we'll be getting a string, for example, that represents a date.
DataType dataType = constraint.getDataType();
Object typedValue = value;
if (dataType != null) {
typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
} else if (value instanceof String) {
//assume string is a number of type double
try {
Double d = Double.parseDouble((String) value);
typedValue = d;
} catch (NumberFormatException n) {
//do nothing, typedValue is never reset
}
}
// TODO: decide if there is any reason why the following would be insufficient - i.e. if something numeric could still be cast to String at this point
if (typedValue instanceof Date) {
return validateRange(result, (Date) typedValue, constraint, attributeValueReader);
} else if (typedValue instanceof Number) {
return validateRange(result, (Number) typedValue, constraint, attributeValueReader);
}
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
示例4: processSingleRangeConstraint
import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
* validates the value provided using {@code RangeConstraint}
*
* @param result - a holder for any already run validation results
* @param value - the value to validate
* @param constraint - the range constraint to use
* @param attributeValueReader - provides access to the attribute being validated
* @return the passed in result, updated with the results of the processing
*/
protected ConstraintValidationResult processSingleRangeConstraint(DictionaryValidationResult result, Object value,
RangeConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
// Can't process any range constraints on null values
if (ValidationUtils.isNullOrEmpty(value) || (constraint.getExclusiveMin() == null
&& constraint.getInclusiveMax() == null)) {
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
// This is necessary because sometimes we'll be getting a string, for example, that represents a date.
DataType dataType = constraint.getDataType();
Object typedValue = value;
if (dataType != null) {
typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
} else if (value instanceof String) {
//assume string is a number of type double
try {
Double d = Double.parseDouble((String) value);
typedValue = d;
} catch (NumberFormatException n) {
//do nothing, typedValue is never reset
}
}
// TODO: decide if there is any reason why the following would be insufficient - i.e. if something numeric could still be cast to String at this point
if (typedValue instanceof Date) {
return validateRange(result, (Date) typedValue, constraint, attributeValueReader);
} else if (typedValue instanceof Number) {
return validateRange(result, (Number) typedValue, constraint, attributeValueReader);
}
return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}