Set<Name> nodeTypesToRefresh = new HashSet<Name>();
Set<Name> nodeTypesToDelete = new HashSet<Name>();
for (Change change : changeSet) {
if (change instanceof NodeAdded) {
NodeAdded added = (NodeAdded)change;
Path addedPath = added.getPath();
if (nodeTypesPath.isAncestorOf(addedPath)) {
// Get the name of the node type ...
Name nodeTypeName = addedPath.getSegment(2).getName();
nodeTypesToRefresh.add(nodeTypeName);
}
} else if (change instanceof NodeRemoved) {
NodeRemoved removed = (NodeRemoved)change;
Path removedPath = removed.getPath();
if (nodeTypesPath.isAncestorOf(removedPath)) {
// Get the name of the node type ...
Name nodeTypeName = removedPath.getSegment(2).getName();
if (removedPath.size() == 3) {
nodeTypesToDelete.add(nodeTypeName);
} else {
// It's a child defn or property defn ...
if (!nodeTypesToDelete.contains(nodeTypeName)) {
// The child defn or property defn is being removed but the node type is not ...
nodeTypesToRefresh.add(nodeTypeName);
}
}
}
} else if (change instanceof PropertyChanged) {
PropertyChanged propChanged = (PropertyChanged)change;
Path changedPath = propChanged.getPathToNode();
if (nodeTypesPath.isAncestorOf(changedPath)) {
// Get the name of the node type ...
Name nodeTypeName = changedPath.getSegment(2).getName();
nodeTypesToRefresh.add(nodeTypeName);
}
} // we don't care about node moves (don't happen) or property added/removed (handled by node add/remove)
}