1 56 package org.objectstyle.cayenne.project.validator; 57 58 import org.apache.log4j.Logger; 59 import org.objectstyle.cayenne.access.DataDomain; 60 import org.objectstyle.cayenne.access.DataNode; 61 import org.objectstyle.cayenne.map.DataMap; 62 import org.objectstyle.cayenne.map.DbAttribute; 63 import org.objectstyle.cayenne.map.DbEntity; 64 import org.objectstyle.cayenne.map.DbRelationship; 65 import org.objectstyle.cayenne.map.ObjAttribute; 66 import org.objectstyle.cayenne.map.ObjEntity; 67 import org.objectstyle.cayenne.map.ObjRelationship; 68 import org.objectstyle.cayenne.map.Procedure; 69 import org.objectstyle.cayenne.map.ProcedureParameter; 70 import org.objectstyle.cayenne.project.ProjectPath; 71 import org.objectstyle.cayenne.query.ProcedureQuery; 72 import org.objectstyle.cayenne.query.SQLTemplate; 73 import org.objectstyle.cayenne.query.SelectQuery; 74 75 81 public abstract class TreeNodeValidator { 82 83 private static Logger logObj = Logger.getLogger(TreeNodeValidator.class); 84 85 protected static final DomainValidator domainValidator = new DomainValidator(); 87 protected static final DataNodeValidator nodeValidator = new DataNodeValidator(); 88 protected static final DataMapValidator mapValidator = new DataMapValidator(); 89 protected static final ObjEntityValidator objEntityValidator = new ObjEntityValidator(); 90 protected static final ObjAttributeValidator objAttrValidator = new ObjAttributeValidator(); 91 protected static final ObjRelationshipValidator objRelValidator = new ObjRelationshipValidator(); 92 protected static final DbEntityValidator dbEntityValidator = new DbEntityValidator(); 93 protected static final DbAttributeValidator dbAttrValidator = new DbAttributeValidator(); 94 protected static final DbRelationshipValidator dbRelValidator = new DbRelationshipValidator(); 95 96 protected static final ProcedureValidator procedureValidator = new ProcedureValidator(); 97 98 protected static final ProcedureParameterValidator procedureParameterValidator = new ProcedureParameterValidator(); 99 protected static final SelectQueryValidator selectQueryValidator = new SelectQueryValidator(); 100 101 protected static final ProcedureQueryValidator procedureQueryValidator = new ProcedureQueryValidator(); 102 103 protected static final SQLTemplateValidator sqlTemplateValidator = new SQLTemplateValidator(); 104 105 108 public static void validate(ProjectPath path, Validator validator) { 109 Object validatedObj = path.getObject(); 110 TreeNodeValidator validatorObj = null; 111 if (validatedObj instanceof ObjAttribute) { 112 validatorObj = objAttrValidator; 113 } 114 else if (validatedObj instanceof ObjRelationship) { 115 validatorObj = objRelValidator; 116 } 117 else if (validatedObj instanceof ObjEntity) { 118 validatorObj = objEntityValidator; 119 } 120 else if (validatedObj instanceof DbAttribute) { 121 validatorObj = dbAttrValidator; 122 } 123 else if (validatedObj instanceof DbRelationship) { 124 validatorObj = dbRelValidator; 125 } 126 else if (validatedObj instanceof DbEntity) { 127 validatorObj = dbEntityValidator; 128 } 129 else if (validatedObj instanceof DataNode) { 130 validatorObj = nodeValidator; 131 } 132 else if (validatedObj instanceof DataMap) { 133 validatorObj = mapValidator; 134 } 135 else if (validatedObj instanceof DataDomain) { 136 validatorObj = domainValidator; 137 } 138 else if (validatedObj instanceof Procedure) { 139 validatorObj = procedureValidator; 140 } 141 else if (validatedObj instanceof ProcedureParameter) { 142 validatorObj = procedureParameterValidator; 143 } 144 else if (validatedObj instanceof SelectQuery) { 145 validatorObj = selectQueryValidator; 146 } 147 else if (validatedObj instanceof SQLTemplate) { 148 validatorObj = sqlTemplateValidator; 149 } 150 else if (validatedObj instanceof ProcedureQuery) { 151 validatorObj = procedureQueryValidator; 152 } 153 else { 154 String className = (validatedObj != null) 156 ? validatedObj.getClass().getName() 157 : "(null object)"; 158 logObj.info("Validation not supported for object of class: " + className); 159 return; 160 } 161 162 validatorObj.validateObject(path, validator); 163 } 164 165 168 public TreeNodeValidator() { 169 super(); 170 } 171 172 178 public abstract void validateObject(ProjectPath treeNodePath, Validator validator); 179 } | Popular Tags |