ActionBean actionBean = (ActionBean) getPageContext().findAttribute(binding);
boolean beanNotPresent = actionBean == null;
try {
final Configuration config = StripesFilter.getConfiguration();
final ActionResolver resolver = StripesFilter.getConfiguration().getActionResolver();
final HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();
final HttpServletResponse response = (HttpServletResponse) getPageContext().getResponse();
Resolution resolution = null;
ExecutionContext ctx = new ExecutionContext();
// Lookup the ActionBean if we don't already have it
if (beanNotPresent) {
ActionBeanContext tempContext =
config.getActionBeanContextFactory().getContextInstance(request, response);
tempContext.setServletContext(getPageContext().getServletContext());
ctx.setLifecycleStage(LifecycleStage.ActionBeanResolution);
ctx.setActionBeanContext(tempContext);
// Run action bean resolution
ctx.setInterceptors(config.getInterceptors(LifecycleStage.ActionBeanResolution));
resolution = ctx.wrap( new Interceptor() {
public Resolution intercept(ExecutionContext ec) throws Exception {
ActionBean bean = resolver.getActionBean(ec.getActionBeanContext(), binding);
ec.setActionBean(bean);
return null;
}
});
}
else {
ctx.setActionBean(actionBean);
ctx.setActionBeanContext(actionBean.getContext());
}
// Then, if and only if an event was specified, run handler resolution
if (resolution == null && event != null && (beanNotPresent || this.alwaysExecuteEvent)) {
ctx.setLifecycleStage(LifecycleStage.HandlerResolution);
ctx.setInterceptors(config.getInterceptors(LifecycleStage.HandlerResolution));
resolution = ctx.wrap( new Interceptor() {
public Resolution intercept(ExecutionContext ec) throws Exception {
ec.setHandler(resolver.getHandler(ec.getActionBean().getClass(), event));
ec.getActionBeanContext().setEventName(event);
return null;
}
});
}