use of org.apache.cayenne.validation.BeanValidationFailure in project cayenne by apache.
the class ClassGenerationValidator method validateRelationship.
private ValidationFailure validateRelationship(ObjRelationship relationship, boolean clientValidation) {
String name = relationship.getSourceEntity().getName();
ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "relationship.name", relationship.getName());
if (emptyName != null) {
return emptyName;
}
ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "relationship.name", relationship.getName());
if (badName != null) {
return badName;
}
if (!relationship.isToMany()) {
ObjEntity targetEntity = relationship.getTargetEntity();
if (clientValidation && targetEntity != null) {
targetEntity = targetEntity.getClientEntity();
}
if (targetEntity == null) {
return new BeanValidationFailure(name, "relationship.targetEntity", "No target entity");
} else if (!targetEntity.isGeneric()) {
ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "relationship.targetEntity.className", targetEntity.getClassName());
if (emptyClass != null) {
return emptyClass;
}
return BeanValidationFailure.validateJavaClassName(name, "relationship.targetEntity.className", targetEntity.getClassName());
}
}
return null;
}
use of org.apache.cayenne.validation.BeanValidationFailure in project cayenne by apache.
the class CodeValidationUtil method validateJavaIdentifier.
public static ValidationFailure validateJavaIdentifier(Object bean, String attribute, String identifier) {
ValidationFailure emptyFailure = BeanValidationFailure.validateNotEmpty(bean, attribute, identifier);
if (emptyFailure != null) {
return emptyFailure;
}
char c = identifier.charAt(0);
if (!Character.isJavaIdentifierStart(c)) {
return new BeanValidationFailure(bean, attribute, validationMessage(attribute, " starts with invalid character: " + c));
}
for (int i = 1; i < identifier.length(); i++) {
c = identifier.charAt(i);
if (!Character.isJavaIdentifierPart(c)) {
return new BeanValidationFailure(bean, attribute, validationMessage(attribute, " contains invalid character: " + c));
}
}
return null;
}
Aggregations