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.conf.DriverDataSourceFactory; 27 import org.apache.cayenne.project.ProjectPath; 28 import org.apache.cayenne.util.Util; 29 30 33 public class DataNodeValidator extends TreeNodeValidator { 34 35 38 public DataNodeValidator() { 39 super(); 40 } 41 42 public void validateObject(ProjectPath path, Validator validator) { 43 DataNode node = (DataNode) path.getObject(); 44 validateName(node, path, validator); 45 validateConnection(node, path, validator); 46 } 47 48 protected void validateConnection(DataNode node, ProjectPath path, Validator validator) { 49 String factory = node.getDataSourceFactory(); 50 51 if (Util.isEmptyString(factory)) { 53 validator.registerError("No DataSource factory.", path); 54 } 55 else if (!DriverDataSourceFactory.class.getName().equals(factory)) { 56 String location = node.getDataSourceLocation(); 57 if (Util.isEmptyString(location)) { 58 validator.registerError("DataNode has no location parameter.", path); 59 } 60 } 61 } 62 63 protected void validateName(DataNode node, ProjectPath path, Validator validator) { 64 String name = node.getName(); 65 66 if (Util.isEmptyString(name)) { 67 validator.registerError("Unnamed DataNode.", path); 68 return; 69 } 70 71 DataDomain domain = (DataDomain) path.getObjectParent(); 72 if (domain == null) { 73 return; 74 } 75 76 Iterator it = domain.getDataNodes().iterator(); 78 while (it.hasNext()) { 79 DataNode otherNode = (DataNode) it.next(); 80 if (otherNode == node) { 81 continue; 82 } 83 84 if (name.equals(otherNode.getName())) { 85 validator.registerError("Duplicate DataNode name: " + name + ".", path); 86 break; 87 } 88 } 89 } 90 } 91 | Popular Tags |