001: package org.strecks.controller.chain.command;
002:
003: import javax.servlet.ServletContext;
004: import javax.servlet.http.HttpServletRequest;
005: import javax.servlet.http.HttpServletResponse;
006:
007: import org.apache.struts.action.Action;
008: import org.apache.struts.action.ActionForm;
009: import org.apache.struts.action.ActionForward;
010: import org.apache.struts.action.ActionMapping;
011: import org.apache.struts.chain.commands.AbstractExecuteAction;
012: import org.apache.struts.chain.contexts.ServletActionContext;
013: import org.apache.struts.config.ActionConfig;
014: import org.apache.struts.config.ForwardConfig;
015: import org.strecks.builder.InterceptorBuilder;
016: import org.strecks.builder.InterceptorBuilderImpl;
017: import org.strecks.context.ActionContext;
018: import org.strecks.context.ActionContextFactory;
019: import org.strecks.context.ActionContextFactoryImpl;
020: import org.strecks.controller.ControllerAction;
021: import org.strecks.controller.ControllerProcessorDelegate;
022: import org.strecks.controller.ControllerProcessorDelegateImpl;
023:
024: /**
025: * Replaces <code>ExecuteAction</code> in chain
026: * @author Phil Zoio
027: */
028: public class ExecuteAction extends AbstractExecuteAction {
029:
030: private ActionContextFactory actionContextFactory;
031: private ControllerProcessorDelegate delegate;
032: private String prefix;
033:
034: public ExecuteAction() {
035: super ();
036: actionContextFactory = newActionContextFactory();
037: }
038:
039: protected ControllerProcessorDelegate newControllerProcessorDelegate() {
040: InterceptorBuilder interceptorBuilder = newInterceptorBuilder();
041: interceptorBuilder.build(getPrefix());
042:
043: ControllerProcessorDelegateImpl delegate = new ControllerProcessorDelegateImpl();
044: delegate.setBeforeInterceptors(interceptorBuilder
045: .getBeforeInterceptors());
046: delegate.setAfterInterceptors(interceptorBuilder
047: .getAfterInterceptors());
048: return delegate;
049: }
050:
051: protected InterceptorBuilder newInterceptorBuilder() {
052: InterceptorBuilder interceptorBuilder = new InterceptorBuilderImpl();
053: return interceptorBuilder;
054: }
055:
056: protected String getPrefix() {
057: return prefix;
058: }
059:
060: protected ActionContextFactory newActionContextFactory() {
061: return new ActionContextFactoryImpl();
062: }
063:
064: @Override
065: protected ForwardConfig execute(
066: org.apache.struts.chain.contexts.ActionContext context,
067: Action action, ActionConfig actionConfig,
068: ActionForm actionForm) throws Exception {
069:
070: synchronized (this ) {
071: if (delegate == null) {
072: delegate = newControllerProcessorDelegate();
073: }
074: }
075:
076: ServletActionContext sc = (ServletActionContext) context;
077: HttpServletRequest request = sc.getRequest();
078: HttpServletResponse response = sc.getResponse();
079: ServletContext servletContext = sc.getContext();
080:
081: ActionContext actionContext = actionContextFactory
082: .createActionContext(request, response, servletContext,
083: actionForm, (ActionMapping) actionConfig);
084:
085: ActionForward forward = null;
086:
087: if (action instanceof ControllerAction) {
088: // execute strecks specific processActionPerform
089: forward = delegate.handleActionPerform(
090: (ControllerAction) action, actionContext);
091: } else {
092: // execute regular Struts actions
093: forward = action.execute((ActionMapping) actionConfig,
094: actionForm, request, response);
095: }
096:
097: return forward;
098:
099: }
100:
101: public void setPrefix(String prefix) {
102: this.prefix = prefix;
103: }
104:
105: }
|