public PullToolsVisitor(RequestHandlerContext context, ExplorerVisitor v, PullService tools) {
super(context, v);
this.tools = tools;
this.rootEntry = new Entry(null);
PullContext pullContext = tools.getContext();
boolean parentEntry = false;
String[] names = pullContext.getQualifiedToolNames().toArray(EMPTY_STRING_ARRAY);
Arrays.sort(names, new Comparator<String>() {
public int compare(String o1, String o2) {
int p1 = o1.startsWith("/_parent/") ? 1 : 0;
int p2 = o2.startsWith("/_parent/") ? 1 : 0;
if (p1 == p2) {
return o1.compareTo(o2);
} else {
return p1 - p2;
}
}
});
for (String path : names) {
Entry entry = rootEntry;
String[] pathsegs = split(path, "/");
String name = null;
for (String pathseg : pathsegs) {
name = pathseg;
Entry subEntry = entry.subEntries.get(name);
if (subEntry == null) {
subEntry = new Entry(name);
entry.subEntries.put(name, subEntry);
}
entry = subEntry;
if (!parentEntry) {
if ("_parent".equals(entry.name)) {
parentEntry = true;
}
}
entry.parentEntry = parentEntry;
}
try {
entry.value = pullContext.pull(name);
} catch (Exception e) {
entry.value = e;
}
}
}