1 56 package org.objectstyle.cayenne.project.validator; 57 58 import java.util.Iterator ; 59 import java.util.List ; 60 61 import org.objectstyle.cayenne.map.DataMap; 62 import org.objectstyle.cayenne.map.Procedure; 63 import org.objectstyle.cayenne.project.ProjectPath; 64 import org.objectstyle.cayenne.util.Util; 65 66 71 public class ProcedureValidator extends TreeNodeValidator { 72 73 public void validateObject(ProjectPath treeNodePath, Validator validator) { 74 Procedure procedure = (Procedure) treeNodePath.getObject(); 75 validateName(procedure, treeNodePath, validator); 76 77 if (procedure.isReturningValue()) { 79 List parameters = procedure.getCallParameters(); 80 if (parameters.size() == 0) { 81 validator.registerWarning( 82 "Procedure returns a value, but has no parameters.", 83 treeNodePath); 84 } 85 } 86 } 87 88 protected void validateName( 89 Procedure procedure, 90 ProjectPath path, 91 Validator validator) { 92 String name = procedure.getName(); 93 94 if (Util.isEmptyString(name)) { 96 validator.registerError("Unnamed Procedure.", path); 97 return; 98 } 99 100 DataMap map = (DataMap) path.getObjectParent(); 101 if (map == null) { 102 return; 103 } 104 105 Iterator it = map.getProcedures().iterator(); 107 while (it.hasNext()) { 108 Procedure otherProcedure = (Procedure) it.next(); 109 if (otherProcedure == procedure) { 110 continue; 111 } 112 113 if (name.equals(otherProcedure.getName())) { 114 validator.registerError("Duplicate Procedure name: " + name + ".", path); 115 break; 116 } 117 } 118 } 119 120 } 121 | Popular Tags |