List<Path> topLevelPaths = projection.getTopLevelPathsInRepository(pathFactory);
switch (topLevelPaths.size()) {
case 0:
break;
case 1: {
Path topLevelPath = topLevelPaths.iterator().next();
if (path.isAncestorOf(topLevelPath)) {
assert topLevelPath.size() > path.size();
Path.Segment child = topLevelPath.getSegment(path.size());
contribution = Contribution.createPlaceholder(source, path, expirationTime, child);
}
break;
}
default: {
// We assume that the top-level paths do not overlap ...
List<Path.Segment> children = new ArrayList<Path.Segment>(topLevelPaths.size());
for (Path topLevelPath : topLevelPaths) {
if (path.isAncestorOf(topLevelPath)) {
assert topLevelPath.size() > path.size();
Path.Segment child = topLevelPath.getSegment(path.size());
children.add(child);
}
}
if (children.size() > 0) {
contribution = Contribution.createPlaceholder(source, path, expirationTime, children);
}
}
}
if (contribution == null) contribution = Contribution.create(source, expirationTime);
contributions.add(contribution);
} else {
// There is at least one (real) contribution ...
// Get the contributions ...
final int numPaths = pathsInSource.size();
if (numPaths == 1) {
Path pathInSource = pathsInSource.iterator().next();
BasicGetNodeCommand fromSource = new BasicGetNodeCommand(pathInSource);
sourceConnection.execute(getExecutionContext(), fromSource);
if (!fromSource.hasError()) {
Collection<Property> properties = fromSource.getProperties();
List<Segment> children = fromSource.getChildren();