Author: pbenedict
Date: Thu Dec 25 21:29:21 2008
New Revision: 729453

URL: http://svn.apache.org/viewvc?rev=729453&view=rev
Log:
STR-3168: Refactor out getDispatcherType() and fix indentation

Modified:
    
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java

Modified: 
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
URL: 
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java?rev=729453&r1=729452&r2=729453&view=diff
==============================================================================
--- 
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
 (original)
+++ 
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
 Thu Dec 25 21:29:21 2008
@@ -48,50 +48,53 @@
      * @throws Exception if creation fails
      * @see ClassUtils#getApplicationInstance(String)
      */
-    protected Dispatcher createDispatcher(String type, ActionContext context)
-           throws Exception {
-       log.info("Initializing dispatcher of type: " + type);
-       return (Dispatcher) ClassUtils.getApplicationInstance(type);
+    protected Dispatcher createDispatcher(String type, ActionContext context) 
throws Exception {
+        log.info("Initializing dispatcher of type: " + type);
+        return (Dispatcher) ClassUtils.getApplicationInstance(type);
     }
 
     public boolean execute(ActionContext context) throws Exception {
-       // Skip processing if the current request is not valid
-       Boolean valid = context.getFormValid();
-       if ((valid == null) || !valid.booleanValue()) {
-           return CONTINUE_PROCESSING;
-       }
-
-       // If no dispatcher, skip
-       ActionConfig actionConfig = context.getActionConfig();
-       if (actionConfig.getDispatcher() == null) {
-           return CONTINUE_PROCESSING;
-       }
-
-       // Obtain (or create) the dispatcher cache
-       String cacheKey = Constants.DISPATCHERS_KEY
-               + context.getModuleConfig().getPrefix();
-       Map dispatchers = (Map) context.getApplicationScope().get(cacheKey);
-       if (dispatchers == null) {
-           dispatchers = new HashMap();
-           context.getApplicationScope().put(cacheKey, dispatchers);
-       }
-
-       // Lookup (or create) the dispatch instance
-       Dispatcher dispatcher = null;
-       synchronized (dispatchers) {
-           String actionType = actionConfig.getType();
-           dispatcher = (Dispatcher) dispatchers.get(actionType);
-           if (dispatcher == null) {
-               String dispatcherType = actionConfig.getDispatcher();
-               dispatcher = createDispatcher(dispatcherType, context);
-               dispatchers.put(actionType, dispatcher);
-           }
-       }
-
-       // Dispatch
-       Object result = dispatcher.dispatch(context);
-       processDispatchResult(result, context);
-       return CONTINUE_PROCESSING;
+        // Skip processing if the current request is not valid
+        Boolean valid = context.getFormValid();
+        if ((valid == null) || !valid.booleanValue()) {
+            return CONTINUE_PROCESSING;
+        }
+
+        // Skip processing if no dispatcher type specified
+        String dispatcherType = getDispatcherType(context);
+        if (dispatcherType == null) {
+            return CONTINUE_PROCESSING;
+        }
+
+        // Obtain (or create) the dispatcher cache
+        String cacheKey = Constants.DISPATCHERS_KEY + 
context.getModuleConfig().getPrefix();
+        Map dispatchers = (Map) context.getApplicationScope().get(cacheKey);
+        if (dispatchers == null) {
+            dispatchers = new HashMap();
+            context.getApplicationScope().put(cacheKey, dispatchers);
+        }
+
+        // Lookup (or create) the dispatch instance
+        Dispatcher dispatcher = null;
+        synchronized (dispatchers) {
+            ActionConfig actionConfig = context.getActionConfig();
+            String actionType = actionConfig.getType();
+            dispatcher = (Dispatcher) dispatchers.get(actionType);
+            if (dispatcher == null) {
+                dispatcher = createDispatcher(dispatcherType, context);
+                dispatchers.put(actionType, dispatcher);
+            }
+        }
+
+        // Dispatch
+        Object result = dispatcher.dispatch(context);
+        processDispatchResult(result, context);
+
+        return CONTINUE_PROCESSING;
+    }
+
+    protected String getDispatcherType(ActionContext context) {
+        return (context != null) ? context.getActionConfig().getDispatcher() : 
null;
     }
 
     /**
@@ -116,36 +119,33 @@
      * @see ActionMapping#findRequiredForward(String)
      */
     protected void processDispatchResult(Object result, ActionContext context) 
{
-       // Null means the response was handled directly
-       if (result == null) {
-           return;
-       }
-
-       // A forward is the classical response
-       if (result instanceof ForwardConfig) {
-           context.setForwardConfig((ForwardConfig) result);
-           return;
-       }
-
-       // String represents the name of a forward
-       ActionConfig actionConfig = context.getActionConfig();
-       ActionMapping mapping = ((ActionMapping) actionConfig);
-       if (result instanceof String) {
-           context.setForwardConfig(mapping
-                   .findRequiredForward((String) result));
-           return;
-       }
-
-       // Select success if no return signature
-       if (result instanceof Void) {
-           context.setForwardConfig(mapping
-                   .findRequiredForward(Action.SUCCESS));
-           return;
-       }
-
-       // Unknown result type
-       throw new IllegalStateException("Unknown dispatch return type: "
-               + result.getClass().getName());
+        // Null means the response was handled directly
+        if (result == null) {
+            return;
+        }
+
+        // A forward is the classical response
+        if (result instanceof ForwardConfig) {
+            context.setForwardConfig((ForwardConfig) result);
+            return;
+        }
+
+        // String represents the name of a forward
+        ActionConfig actionConfig = context.getActionConfig();
+        ActionMapping mapping = ((ActionMapping) actionConfig);
+        if (result instanceof String) {
+            context.setForwardConfig(mapping.findRequiredForward((String) 
result));
+            return;
+        }
+
+        // Select success if no return signature
+        if (result instanceof Void) {
+            
context.setForwardConfig(mapping.findRequiredForward(Action.SUCCESS));
+            return;
+        }
+
+        // Unknown result type
+        throw new IllegalStateException("Unknown dispatch return type: " + 
result.getClass().getName());
     }
 
 }


Reply via email to