use of eu.esdihumboldt.hale.common.instance.extension.validation.ValidationLocation in project hale by halestudio.
the class InstanceValidator method validateProperty.
/**
* Validates the given property values against their
* {@link PropertyDefinition}.<br>
* Then calls
* {@link #validateChildren(Object[], ChildDefinition, InstanceValidationReporter, QName, List, boolean, InstanceReference, InstanceValidationContext, EntityDefinition)}
* .
*
* @param properties the array of existing properties, may be null
* @param propertyDef their definition
* @param reporter the reporter to report to
* @param type the top level type
* @param path the current property path
* @param reference the instance reference
* @param context the instance validation context
* @param entity the property's entity definition or <code>null</code>
*/
@SuppressWarnings("unchecked")
private void validateProperty(Object[] properties, PropertyDefinition propertyDef, InstanceValidationReporter reporter, QName type, List<QName> path, InstanceReference reference, InstanceValidationContext context, @Nullable EntityDefinition entity) {
ValidationLocation loc = new ValidationLocation(reference, type, new ArrayList<QName>(path));
// property constraint validators
for (Entry<Class<PropertyConstraint>, PropertyConstraintValidator> entry : ConstraintValidatorExtension.getInstance().getPropertyConstraintValidators().entrySet()) {
try {
entry.getValue().validatePropertyConstraint(properties, propertyDef.getConstraint((Class<? extends PropertyConstraint>) ConstraintUtil.getConstraintType(entry.getKey())), propertyDef, context, loc);
} catch (ValidationException vE) {
reporter.warn(new DefaultInstanceValidationMessage(loc, entry.getKey().getSimpleName(), vE.getMessage()));
}
}
if (properties != null) {
// generic validators
for (InstanceModelValidator validator : additionalValidators) {
for (Object value : properties) {
// visit each value
if (value instanceof Instance) {
try {
validator.validateInstance((Instance) value, entity, context);
} catch (ValidationException vE) {
reporter.warn(new DefaultInstanceValidationMessage(reference, type, new ArrayList<QName>(path), validator.getCategory(), vE.getMessage()));
}
} else {
try {
validator.validateProperty(value, propertyDef, entity, context);
} catch (ValidationException vE) {
reporter.warn(new DefaultInstanceValidationMessage(reference, type, new ArrayList<QName>(path), validator.getCategory(), vE.getMessage()));
}
}
}
}
}
validateChildren(properties, propertyDef, reporter, type, path, false, reference, context, entity);
}
Aggregations