1 19 20 package org.apache.cayenne.project.validator; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.cayenne.map.DataMap; 26 import org.apache.cayenne.map.Procedure; 27 import org.apache.cayenne.project.ProjectPath; 28 import org.apache.cayenne.util.Util; 29 30 35 public class ProcedureValidator extends TreeNodeValidator { 36 37 public void validateObject(ProjectPath treeNodePath, Validator validator) { 38 Procedure procedure = (Procedure) treeNodePath.getObject(); 39 validateName(procedure, treeNodePath, validator); 40 41 if (procedure.isReturningValue()) { 43 List parameters = procedure.getCallParameters(); 44 if (parameters.size() == 0) { 45 validator.registerWarning( 46 "Procedure returns a value, but has no parameters.", 47 treeNodePath); 48 } 49 } 50 } 51 52 protected void validateName( 53 Procedure procedure, 54 ProjectPath path, 55 Validator validator) { 56 String name = procedure.getName(); 57 58 if (Util.isEmptyString(name)) { 60 validator.registerError("Unnamed Procedure.", path); 61 return; 62 } 63 64 DataMap map = (DataMap) path.getObjectParent(); 65 if (map == null) { 66 return; 67 } 68 69 Iterator it = map.getProcedures().iterator(); 71 while (it.hasNext()) { 72 Procedure otherProcedure = (Procedure) it.next(); 73 if (otherProcedure == procedure) { 74 continue; 75 } 76 77 if (name.equals(otherProcedure.getName())) { 78 validator.registerError("Duplicate Procedure name: " + name + ".", path); 79 break; 80 } 81 } 82 } 83 84 } 85 | Popular Tags |