Set<ConstraintViolation<Object>> errors = service.validate(domainObject);
if (errors != null && !errors.isEmpty()) {
SimpleProxyId<?> id = entry.getKey();
for (ConstraintViolation<Object> error : errors) {
// Construct an ID that represents domainObject
IdMessage rootId = FACTORY.id().as();
rootId.setClientId(id.getClientId());
rootId.setTypeToken(service.resolveTypeToken(id.getProxyClass()));
if (id.isEphemeral()) {
rootId.setStrength(Strength.EPHEMERAL);
} else {
rootId.setServerId(toBase64(id.getServerId()));
}
// If possible, also include the id of the leaf bean
IdMessage leafId = null;
if (error.getLeafBean() != null) {
SimpleProxyId<?> stableId = source.getStableId(error.getLeafBean());
if (stableId != null) {
leafId = FACTORY.id().as();
leafId.setClientId(stableId.getClientId());
leafId.setTypeToken(service.resolveTypeToken(stableId.getProxyClass()));
if (stableId.isEphemeral()) {
leafId.setStrength(Strength.EPHEMERAL);
} else {
leafId.setServerId(toBase64(stableId.getServerId()));
}
}
}
ViolationMessage message = FACTORY.violation().as();