1 19 20 package org.apache.cayenne.project.validator; 21 22 import org.apache.cayenne.map.ObjAttribute; 23 import org.apache.cayenne.project.ProjectPath; 24 import org.apache.cayenne.util.Util; 25 26 29 public class ObjAttributeValidator extends TreeNodeValidator { 30 31 34 public ObjAttributeValidator() { 35 super(); 36 } 37 38 public void validateObject(ProjectPath path, Validator validator) { 39 ObjAttribute attribute = (ObjAttribute) path.getObject(); 40 41 if (path.getObjectParent() != null 43 && path.getObjectParent() != attribute.getEntity()) { 44 return; 45 } 46 47 if (Util.isEmptyString(attribute.getName())) { 49 validator.registerError("Unnamed ObjAttribute.", path); 50 } 51 else { 52 MappingNamesHelper helper = MappingNamesHelper.getInstance(); 53 String invalidChars = helper.invalidCharsInObjPathComponent(attribute 54 .getName()); 55 56 if (invalidChars != null) { 57 validator.registerWarning( 58 "ObjAttribute name contains invalid characters: " + invalidChars, 59 path); 60 } 61 else if (helper.invalidDataObjectProperty(attribute.getName())) { 62 validator.registerWarning("ObjAttribute name is invalid: " 63 + attribute.getName(), path); 64 } 65 } 66 67 if (Util.isEmptyString(attribute.getType())) { 69 validator.registerWarning("ObjAttribute has no type.", path); 70 } 71 72 if (attribute.getDbAttribute() == null) { 73 validator.registerWarning("ObjAttribute has no DbAttribute mapping.", path); 74 } 75 else if (attribute.getDbAttribute().isPrimaryKey() 78 && attribute.getDbAttribute().isGenerated()) { 79 validator.registerWarning("ObjAttribute is mapped to a generated PK: " 80 + attribute.getDbAttributeName(), path); 81 } 82 } 83 } 84 | Popular Tags |