1 56 package org.objectstyle.cayenne.project.validator; 57 58 import java.util.Iterator ; 59 60 import org.objectstyle.cayenne.access.DataDomain; 61 import org.objectstyle.cayenne.access.DataNode; 62 import org.objectstyle.cayenne.map.DataMap; 63 import org.objectstyle.cayenne.project.ProjectPath; 64 import org.objectstyle.cayenne.util.Util; 65 66 71 public class DataMapValidator extends TreeNodeValidator { 72 73 76 public DataMapValidator() { 77 super(); 78 } 79 80 public void validateObject(ProjectPath path, Validator validator) { 81 DataMap map = (DataMap) path.getObject(); 82 validateName(map, path, validator); 83 84 validateNodeLinks(map, path, validator); 86 } 87 88 protected void validateNodeLinks(DataMap map, ProjectPath path, Validator validator) { 89 DataDomain domain = (DataDomain) path.getObjectParent(); 90 if (domain == null) { 91 return; 92 } 93 94 boolean unlinked = true; 95 int nodeCount = 0; 96 Iterator it = domain.getDataNodes().iterator(); 97 while(it.hasNext()) { 98 DataNode node = (DataNode)it.next(); 99 nodeCount++; 100 if(node.getDataMaps().contains(map)) { 101 unlinked = false; 102 break; 103 } 104 } 105 106 if(unlinked && nodeCount > 0) { 107 validator.registerWarning("DataMap is not linked to any DataNodes.", path); 108 } 109 } 110 111 protected void validateName(DataMap map, ProjectPath path, Validator validator) { 112 String name = map.getName(); 113 114 if (Util.isEmptyString(name)) { 115 validator.registerError("Unnamed DataMap.", path); 116 return; 117 } 118 119 DataDomain domain = (DataDomain) path.getObjectParent(); 120 if (domain == null) { 121 return; 122 } 123 124 Iterator it = domain.getDataMaps().iterator(); 126 while (it.hasNext()) { 127 DataMap otherMap = (DataMap) it.next(); 128 if (otherMap == map) { 129 continue; 130 } 131 132 if (name.equals(otherMap.getName())) { 133 validator.registerError("Duplicate DataMap name: " + name + ".", path); 134 return; 135 } 136 } 137 } 138 } 139 | Popular Tags |