1 19 20 package org.apache.cayenne.project.validator; 21 22 import java.util.Iterator ; 23 24 import org.apache.cayenne.access.DataDomain; 25 import org.apache.cayenne.access.DataNode; 26 import org.apache.cayenne.map.DataMap; 27 import org.apache.cayenne.project.ProjectPath; 28 import org.apache.cayenne.util.Util; 29 30 35 public class DataMapValidator extends TreeNodeValidator { 36 37 40 public DataMapValidator() { 41 super(); 42 } 43 44 public void validateObject(ProjectPath path, Validator validator) { 45 DataMap map = (DataMap) path.getObject(); 46 validateName(map, path, validator); 47 48 validateNodeLinks(map, path, validator); 50 } 51 52 protected void validateNodeLinks(DataMap map, ProjectPath path, Validator validator) { 53 DataDomain domain = (DataDomain) path.getObjectParent(); 54 if (domain == null) { 55 return; 56 } 57 58 boolean unlinked = true; 59 int nodeCount = 0; 60 Iterator it = domain.getDataNodes().iterator(); 61 while(it.hasNext()) { 62 DataNode node = (DataNode)it.next(); 63 nodeCount++; 64 if(node.getDataMaps().contains(map)) { 65 unlinked = false; 66 break; 67 } 68 } 69 70 if(unlinked && nodeCount > 0) { 71 validator.registerWarning("DataMap is not linked to any DataNodes.", path); 72 } 73 } 74 75 protected void validateName(DataMap map, ProjectPath path, Validator validator) { 76 String name = map.getName(); 77 78 if (Util.isEmptyString(name)) { 79 validator.registerError("Unnamed DataMap.", path); 80 return; 81 } 82 83 DataDomain domain = (DataDomain) path.getObjectParent(); 84 if (domain == null) { 85 return; 86 } 87 88 Iterator it = domain.getDataMaps().iterator(); 90 while (it.hasNext()) { 91 DataMap otherMap = (DataMap) it.next(); 92 if (otherMap == map) { 93 continue; 94 } 95 96 if (name.equals(otherMap.getName())) { 97 validator.registerError("Duplicate DataMap name: " + name + ".", path); 98 return; 99 } 100 } 101 } 102 } 103 | Popular Tags |