use of eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator in project hale by halestudio.
the class InstanceValidator method validate.
/**
* Validates the given object. The created reports messages do not have an
* {@link InstanceReference} set.
*
* @param object the object to validate (i. e. an instance, group or basic
* value)
* @param childDef the child definition of the given object
* @return a report of the validation
*/
public InstanceValidationReporter validate(Object object, ChildDefinition<?> childDef) {
InstanceValidationReporter reporter = new DefaultInstanceValidationReporter(false);
reporter.setSuccess(false);
InstanceValidationContext context = new InstanceValidationContext();
// first a special case for Choice-Flag
// XXX a better way to do this than coding this special case?
boolean onlyCheckExistingChildren = false;
if (childDef.asGroup() != null) {
GroupPropertyConstraintValidator validator = ConstraintValidatorExtension.getInstance().getGroupPropertyConstraintValidators().get(ChoiceFlag.class);
if (validator != null)
try {
validator.validateGroupPropertyConstraint(new Object[] { object }, childDef.asGroup().getConstraint(ChoiceFlag.class), childDef.asGroup(), context);
} catch (ValidationException vE) {
reporter.warn(new DefaultInstanceValidationMessage(null, null, Collections.<QName>emptyList(), ChoiceFlag.class.getSimpleName(), vE.getMessage()));
}
onlyCheckExistingChildren = childDef.asGroup().getConstraint(ChoiceFlag.class).isEnabled();
}
// then validate the object as if it were a lone property value
validateChildren(new Object[] { object }, childDef, reporter, null, new ArrayList<QName>(), onlyCheckExistingChildren, null, context, null);
reporter.setSuccess(true);
return reporter;
}
Aggregations