}
private void follow(CrawlPath path, StateVertex targetState)
throws StateUnreachableException,
CrawljaxException {
StateVertex curState = context.getSession().getInitialState();
for (Eventable clickable : path) {
checkCrawlConditions(targetState);
LOG.debug("Backtracking by executing {} on element: {}", clickable.getEventType(),
clickable);
boolean switched = stateMachine.changeState(clickable.getTargetStateVertex());
if (!switched) {
throw new StateUnreachableException(targetState, "Could not switch states");
}
curState = clickable.getTargetStateVertex();
crawlpath.add(clickable);
handleInputElements(clickable);
if (fireEvent(clickable)) {
if (crawlerLeftDomain()) {
throw new StateUnreachableException(targetState,
"Domain left while following path");
}
int depth = crawlDepth.incrementAndGet();
LOG.info("Crawl depth is now {}", depth);
plugins.runOnRevisitStatePlugins(context, curState);
} else {
throw new StateUnreachableException(targetState, "couldn't fire eventable "
+ clickable);
}
checkCrawlConditions(targetState);
}
if (!curState.equals(targetState)) {
throw new StateUnreachableException(targetState,
"The path didn't result in the desired state but in state "
+ curState.getName());
}
}