use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DataMapValidator method validateNodeLinks.
private void validateNodeLinks(DataMap map, ValidationResult validationResult) {
DataChannelDescriptor domain = map.getDataChannelDescriptor();
if (domain == null) {
return;
}
boolean unlinked = true;
int nodeCount = 0;
for (DataNodeDescriptor node : domain.getNodeDescriptors()) {
nodeCount++;
if (node.getDataMapNames().contains(map.getName())) {
unlinked = false;
break;
}
}
if (unlinked && nodeCount > 0) {
addFailure(validationResult, map, "DataMap is not linked to any DataNodes");
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DataNodeValidator method validateName.
void validateName(DataNodeDescriptor node, ValidationResult validationResult) {
String name = node.getName();
if (Util.isEmptyString(name)) {
addFailure(validationResult, node, "Unnamed DataNode");
return;
}
DataChannelDescriptor dataChannelDescriptor = node.getDataChannelDescriptor();
// check for duplicate names in the parent context
for (DataNodeDescriptor otherNode : dataChannelDescriptor.getNodeDescriptors()) {
if (otherNode == node) {
continue;
}
if (name.equals(otherNode.getName())) {
addFailure(validationResult, node, "Duplicate DataNode name: %s", name);
break;
}
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class EmbeddableValidator method validate.
void validate(Embeddable embeddable, ValidationResult validationResult) {
String name = embeddable.getClassName();
// Must have name
if (Util.isEmptyString(name)) {
addFailure(validationResult, embeddable, "Unnamed Embeddable");
return;
}
DataMap map = embeddable.getDataMap();
if (map == null) {
return;
}
// check for duplicate names in the parent context
for (Embeddable otherEmb : map.getEmbeddables()) {
if (otherEmb == embeddable) {
continue;
}
if (name.equals(otherEmb.getClassName())) {
addFailure(validationResult, embeddable, "Duplicate Embeddable class name: %s", name);
break;
}
}
// check for duplicates in other DataMaps
DataChannelDescriptor domain = map.getDataChannelDescriptor();
if (domain != null) {
for (DataMap nextMap : domain.getDataMaps()) {
if (nextMap == map) {
continue;
}
// note that lookuo below will return the same embeddable due to the
// shared namespace if not conflicts exist
Embeddable conflictingEmbeddable = nextMap.getEmbeddable(name);
if (conflictingEmbeddable != null && conflictingEmbeddable != embeddable) {
addFailure(validationResult, embeddable, "Duplicate Embeddable name in another DataMap: %s", name);
break;
}
}
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ObjEntityValidator method validateName.
void validateName(ObjEntity entity, ValidationResult validationResult) {
String name = entity.getName();
// Must have name
if (Util.isEmptyString(name)) {
addFailure(validationResult, entity, "Unnamed ObjEntity");
return;
}
DataMap map = entity.getDataMap();
if (map == null) {
return;
}
// check for duplicate names in the parent context
for (ObjEntity otherEnt : map.getObjEntities()) {
if (otherEnt == entity) {
continue;
}
if (name.equals(otherEnt.getName())) {
addFailure(validationResult, entity, "Duplicate ObjEntity name: '%s'", name);
break;
}
}
// check for duplicates in other DataMaps
DataChannelDescriptor domain = entity.getDataMap().getDataChannelDescriptor();
if (domain != null) {
for (DataMap nextMap : domain.getDataMaps()) {
if (nextMap == map) {
continue;
}
ObjEntity conflictingEntity = nextMap.getObjEntity(name);
if (conflictingEntity != null) {
if (!Util.nullSafeEquals(conflictingEntity.getClassName(), entity.getClassName())) {
addFailure(validationResult, entity, "Duplicate ObjEntity name in another DataMap: '%s'", name);
break;
}
}
}
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class FileProjectSaverTest method testSaveAs_Sorted.
@Test
public void testSaveAs_Sorted() throws Exception {
File testFolder = setupTestDirectory("testSaveAs_Sorted");
DataChannelDescriptor rootNode = new DataChannelDescriptor();
rootNode.setName("test");
// add maps and nodes in reverse alpha order. Check that they are saved in alpha
// order
rootNode.getDataMaps().add(new DataMap("C"));
rootNode.getDataMaps().add(new DataMap("B"));
rootNode.getDataMaps().add(new DataMap("A"));
DataNodeDescriptor[] nodes = new DataNodeDescriptor[3];
nodes[0] = new DataNodeDescriptor("Z");
nodes[1] = new DataNodeDescriptor("Y");
nodes[2] = new DataNodeDescriptor("X");
nodes[0].getDataMapNames().add("C");
nodes[0].getDataMapNames().add("B");
nodes[0].getDataMapNames().add("A");
rootNode.getNodeDescriptors().addAll(Arrays.asList(nodes));
Project project = new Project(new ConfigurationTree<DataChannelDescriptor>(rootNode));
saver.saveAs(project, new URLResource(testFolder.toURI().toURL()));
File target = new File(testFolder, "cayenne-test.xml");
assertTrue(target.isFile());
assertSaveAs_Sorted(target);
}
Aggregations