IEngineServiceView engine,
IRequestCycle cycle,
ResponseOutputStream output)
throws ServletException, IOException
{
IAction action = null;
String componentPageName;
int count = 0;
String[] serviceContext = getServiceContext(cycle.getRequestContext());
if (serviceContext != null)
count = serviceContext.length;
if (count != 4 && count != 5)
throw new ApplicationRuntimeException(
Tapestry.getMessage("ActionService.context-parameters"));
boolean complex = count == 5;
int i = 0;
String stateful = serviceContext[i++];
String pageName = serviceContext[i++];
String targetActionId = serviceContext[i++];
if (complex)
componentPageName = serviceContext[i++];
else
componentPageName = pageName;
String targetIdPath = serviceContext[i++];
IPage page = cycle.getPage(pageName);
// Setup the page for the rewind, then do the rewind.
cycle.activate(page);
IPage componentPage = cycle.getPage(componentPageName);
IComponent component = componentPage.getNestedComponent(targetIdPath);
try
{
action = (IAction) component;
}
catch (ClassCastException ex)
{
throw new ApplicationRuntimeException(
Tapestry.format("ActionService.component-wrong-type", component.getExtendedId()),
component,
null,
ex);
}
// Only perform the stateful check if the application was stateful
// when the URL was rendered.
if (stateful.equals(STATEFUL_ON) && action.getRequiresSession())
{
HttpSession session = cycle.getRequestContext().getSession();
if (session == null || session.isNew())
throw new StaleSessionException();