for (int i = 0; i < paths.length; i++) {
// First fetch the cell. If it does not exist, then return a bad
// response. This is an error since the path should never contain
// a Cell that does not exist.
WFSCell cell = dir.getCellByName(paths[i]);
if (cell == null) {
LOGGER.warning("Unable to find WFS Cell with path: " + path);
return Response.status(Response.Status.BAD_REQUEST).build();
}
// Next, get the directory associated with the cell. All elements
// the path should have a Cell directory, except perhaps for the
// last element.
dir = cell.getCellDirectory();
if (dir == null && i < paths.length - 1) {
// Some interior path does not have a Cell directory. This is
// an error.
LOGGER.warning("Unable to find WFS Cell directory with path: " +
path);
return Response.status(Response.Status.BAD_REQUEST).build();
}
else if (dir == null) {
// Otherwise, if the final path does not have a Cell directory,
// this is ok. It just means that Cell has no children, so we
// return an empty list.
LOGGER.fine("Did not find a WFS Cell directory for path " +
path + ". This is ok, returning empty list.");
CellList children = new CellList(path, new Cell[] {});
return Response.ok(children).build();
}
}
// If we have reached here, we have 'dir' with the directory in which
// the cells should be. Create a WFSCellChildren object which is used
// to serialize the result.
String names[] = dir.getCellNames();
if (names == null) {
// If the directory exists, yet there are no children, this is ok.
// Just return an empty list.
LOGGER.fine("Did not find WFS Cell children for path " + path +
". This is ok, returning empty list.");
CellList children = new CellList(path, new Cell[]{});
return Response.ok(children).build();
}
LOGGER.fine("For WFS Cell " + path + " # Children " + names.length);
// Loop through and create the WFSCellChildren object, we need to
// include the last modified time so that the client can check whether
// the cell has been modified or not.
LinkedList<Cell> list = new LinkedList<Cell>();
for (String name : names) {
WFSCell cell = dir.getCellByName(name);
if (cell == null) {
LOGGER.warning("No WFS cell exists with name " + name);
continue;
}
LOGGER.fine("Found WFS child " + name + " in path " + path);
list.add(new Cell(name, cell.getLastModified()));
}
// Convert the list of CellChilds to an array, form into a CellList and
// send the CellList directly to the client.
Cell[] childs = list.toArray(new Cell[] {});