Search in sources :

Example 1 with GroupPropertyConstraintValidator

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;
}
Also used : ValidationException(eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException) InstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReporter) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) QName(javax.xml.namespace.QName) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) InstanceValidationContext(eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext) GroupPropertyConstraintValidator(eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator)

Aggregations

GroupPropertyConstraintValidator (eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator)1 InstanceValidationContext (eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext)1 ValidationException (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException)1 InstanceValidationReporter (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReporter)1 DefaultInstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage)1 DefaultInstanceValidationReporter (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter)1 QName (javax.xml.namespace.QName)1