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.conf.DriverDataSourceFactory; 63 import org.objectstyle.cayenne.project.ProjectPath; 64 import org.objectstyle.cayenne.util.Util; 65 66 69 public class DataNodeValidator extends TreeNodeValidator { 70 71 74 public DataNodeValidator() { 75 super(); 76 } 77 78 public void validateObject(ProjectPath path, Validator validator) { 79 DataNode node = (DataNode) path.getObject(); 80 validateName(node, path, validator); 81 validateConnection(node, path, validator); 82 } 83 84 protected void validateConnection( 85 DataNode node, 86 ProjectPath path, 87 Validator validator) { 88 String factory = node.getDataSourceFactory(); 89 90 if (Util.isEmptyString(factory)) { 92 validator.registerError("No DataSource factory.", path); 93 } else if(!DriverDataSourceFactory.class.getName().equals(factory)) { 94 String location = node.getDataSourceLocation(); 95 if (Util.isEmptyString(location)) { 96 validator.registerError("DataNode has no location parameter.", path); 97 } 98 } 99 100 if (node.getAdapter() == null) { 101 validator.registerWarning("DataNode has no DBAdapter.", path); 102 } 103 } 104 105 protected void validateName(DataNode node, ProjectPath path, Validator validator) { 106 String name = node.getName(); 107 108 if (Util.isEmptyString(name)) { 109 validator.registerError("Unnamed DataNode.", path); 110 return; 111 } 112 113 DataDomain domain = (DataDomain) path.getObjectParent(); 114 if (domain == null) { 115 return; 116 } 117 118 Iterator it = domain.getDataNodes().iterator(); 120 while (it.hasNext()) { 121 DataNode otherNode = (DataNode) it.next(); 122 if (otherNode == node) { 123 continue; 124 } 125 126 if (name.equals(otherNode.getName())) { 127 validator.registerError("Duplicate DataNode name: " + name + ".", path); 128 break; 129 } 130 } 131 } 132 } 133 | Popular Tags |