Package org.strecks.controller.chain.command

Source Code of org.strecks.controller.chain.command.ExecuteAction

package org.strecks.controller.chain.command;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.chain.commands.AbstractExecuteAction;
import org.apache.struts.chain.contexts.ServletActionContext;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ForwardConfig;
import org.strecks.builder.InterceptorBuilder;
import org.strecks.builder.InterceptorBuilderImpl;
import org.strecks.context.ActionContext;
import org.strecks.context.ActionContextFactory;
import org.strecks.context.ActionContextFactoryImpl;
import org.strecks.controller.ControllerAction;
import org.strecks.controller.ControllerProcessorDelegate;
import org.strecks.controller.ControllerProcessorDelegateImpl;

/**
* Replaces <code>ExecuteAction</code> in chain
* @author Phil Zoio
*/
public class ExecuteAction extends AbstractExecuteAction
{

  private ActionContextFactory actionContextFactory;
  private ControllerProcessorDelegate delegate;
  private String prefix;

  public ExecuteAction()
  {
    super();
    actionContextFactory = newActionContextFactory();
  }

  protected ControllerProcessorDelegate newControllerProcessorDelegate()
  {
    InterceptorBuilder interceptorBuilder = newInterceptorBuilder();
    interceptorBuilder.build(getPrefix());
   
    ControllerProcessorDelegateImpl delegate = new ControllerProcessorDelegateImpl();
    delegate.setBeforeInterceptors(interceptorBuilder.getBeforeInterceptors());
    delegate.setAfterInterceptors(interceptorBuilder.getAfterInterceptors());
    return delegate;
  }

  protected InterceptorBuilder newInterceptorBuilder()
  {
    InterceptorBuilder interceptorBuilder = new InterceptorBuilderImpl();
    return interceptorBuilder;
  }
 
  protected String getPrefix()
  {
    return prefix;
  }

  protected ActionContextFactory newActionContextFactory()
  {
    return new ActionContextFactoryImpl();
  }

  @Override
  protected ForwardConfig execute(org.apache.struts.chain.contexts.ActionContext context, Action action,
      ActionConfig actionConfig, ActionForm actionForm) throws Exception
  {

    synchronized (this)
    {
      if (delegate == null)
      {
      delegate = newControllerProcessorDelegate();
      }
    }
   
    ServletActionContext sc = (ServletActionContext) context;
    HttpServletRequest request = sc.getRequest();
    HttpServletResponse response = sc.getResponse();
    ServletContext servletContext = sc.getContext();
   
    ActionContext actionContext = actionContextFactory.createActionContext(request, response, servletContext,
        actionForm, (ActionMapping) actionConfig);

    ActionForward forward = null;

    if (action instanceof ControllerAction)
    {
      // execute strecks specific processActionPerform
      forward = delegate.handleActionPerform((ControllerAction) action, actionContext);
    }
    else
    {
      // execute regular Struts actions
      forward = action.execute((ActionMapping) actionConfig, actionForm, request, response);
    }

    return forward;

  }

  public void setPrefix(String prefix)
  {
    this.prefix = prefix;
  }
 
 

}
TOP

Related Classes of org.strecks.controller.chain.command.ExecuteAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.