Location actualLocation = request.at();
int numMerged = 0;
// The first pass will only capture the actual ReadBranchRequests to the underlying sources ...
Map<Path, Location> actualLocationsOfProxyNodes = new HashMap<Path, Location>();
while (projectedRequest != null) {
CacheableRequest fromSource = (CacheableRequest)projectedRequest.getRequest();
if (fromSource.hasError()) {
projectedRequest = projectedRequest.next();
continue;
}
if (fromSource.isCancelled()) {
request.cancel();
return;
}
Projection projection = projectedRequest.getProjection();
if (fromSource instanceof ReadBranchRequest) {
ReadBranchRequest readFromSource = (ReadBranchRequest)fromSource;
for (Location parent : readFromSource) {
List<Location> children = readFromSource.getChildren(parent);
Map<Name, Property> properties = readFromSource.getPropertiesFor(parent);
projectToFederated(actualLocation, projection, request, parent, children, properties);
}
Location locationOfProxy = readFromSource.getActualLocationOfNode();
// The location is in terms of the source, so get the projected location ...
locationOfProxy = determineActualLocation(locationOfProxy, projection);
actualLocationsOfProxyNodes.put(locationOfProxy.getPath(), locationOfProxy);
}
setCacheableInfo(request, fromSource.getCachePolicy());
projectedRequest = projectedRequest.next();
++numMerged;
}
// Go through the requests and process the ReadNodeRequests (which were reading children of placeholders)...
projectedRequest = federatedRequest.getFirstProjectedRequest();
while (projectedRequest != null) {
CacheableRequest fromSource = (CacheableRequest)projectedRequest.getRequest();
Projection projection = projectedRequest.getProjection();
if (fromSource instanceof ReadNodeRequest) {
ReadNodeRequest readFromSource = (ReadNodeRequest)fromSource;
Location parent = readFromSource.getActualLocationOfNode();
List<Location> children = readFromSource.getChildren();
for (int i = 0; i != children.size(); ++i) {
Location child = children.get(i);
if (!child.hasIdProperties()) {
// The the child must have been a proxy node ...
Location actual = actualLocationsOfProxyNodes.get(child.getPath());
assert actual != null;
children.set(i, actual);
}
}
Map<Name, Property> properties = readFromSource.getPropertiesByName();
projectToFederated(actualLocation, projection, request, parent, children, properties);
}
setCacheableInfo(request, fromSource.getCachePolicy());
projectedRequest = projectedRequest.next();
}
if (numMerged == 0) {
// No source requests had results ...