Set<ConsistencyValidator> requriedConsistencyValidators = synchronizer.getRequiredValidators();
//check that all the required consistency validators were run
for(ConsistencyValidator v : requriedConsistencyValidators) {
if (!consistencyValidators.contains(v)) {
ret.add(new ConsistencyValidatorFailureReport(v.getClass().getName(), "The validator '"
+ v.getClass().getName() + "' is required by the synchronizer '" + synchronizerClass
+ "' but was not found in the export file."));
}
}
//don't bother checking if there are inconsistencies in the export file
if (!ret.isEmpty()) {
return ret;
}
boolean configured = false;
Configuration importConfiguration = importConfigurations.get(synchronizerClass);
Set<EntityValidator<X>> validators = null;
//the passed in configuration has precedence over the default one inlined in
//the config file.
if (importConfiguration != null) {
importer.configure(importConfiguration);
validators = importer.getEntityValidators();
for(EntityValidator<X> v : validators) {
v.initialize(subject, entityManager);
}
configured = true;
}
while (rdr.hasNext()) {
boolean bailout = false;
switch (rdr.next()) {
case XMLStreamConstants.START_ELEMENT:
if (SynchronizationConstants.DEFAULT_CONFIGURATION_ELEMENT.equals(rdr.getName().getLocalPart())) {
if (!configured) {
importConfiguration = getDefaultConfiguration(rdr);
}
} else if (SynchronizationConstants.DATA_ELEMENT.equals(rdr.getName().getLocalPart())) {
//first check if the configure method has been called
if (!configured) {
importer.configure(importConfiguration);
validators = importer.getEntityValidators();
for(EntityValidator<X> v : validators) {
v.initialize(subject, entityManager);
}
configured = true;
}
//now do the validation
rdr.nextTag();
X exportedEntity = importer.unmarshallExportedEntity(new ExportReader(rdr));
for (EntityValidator<X> validator : validators) {
try {
validator.validateExportedEntity(exportedEntity);
} catch (Exception e) {
ValidationException v = new ValidationException("Failed to validate entity ["
+ exportedEntity + "]", e);
ret.add(new ConsistencyValidatorFailureReport(validator.getClass().getName(),
printExceptionToString(v)));
}
}
}
break;