Revision: 835
          http://stripes.svn.sourceforge.net/stripes/?rev=835&view=rev
Author:   bengunter
Date:     2008-02-05 08:48:36 -0800 (Tue, 05 Feb 2008)

Log Message:
-----------
STS-497. To facilitate the move from 1.4 to 1.5 for people who have been using 
DelegatingExceptionHandler, support for DelegatingExceptionHandler.Packages has 
been added back in. It will now search for AutoExceptionHandlers there first, 
then it will try autodiscovery, then it will fall back to 
ActionResolver.Packages.

Modified Paths:
--------------
    
trunk/stripes/src/net/sourceforge/stripes/exception/DelegatingExceptionHandler.java

Modified: 
trunk/stripes/src/net/sourceforge/stripes/exception/DelegatingExceptionHandler.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/exception/DelegatingExceptionHandler.java
 2008-02-05 16:45:17 UTC (rev 834)
+++ 
trunk/stripes/src/net/sourceforge/stripes/exception/DelegatingExceptionHandler.java
 2008-02-05 16:48:36 UTC (rev 835)
@@ -17,8 +17,10 @@
 import net.sourceforge.stripes.action.Resolution;
 import net.sourceforge.stripes.config.BootstrapPropertyResolver;
 import net.sourceforge.stripes.config.Configuration;
+import net.sourceforge.stripes.controller.AnnotatedClassActionResolver;
 import net.sourceforge.stripes.util.Log;
 import net.sourceforge.stripes.util.ResolverUtil;
+import net.sourceforge.stripes.util.StringUtil;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -26,8 +28,10 @@
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -77,6 +81,12 @@
     /** Configuration key used to lookup the package filters used when 
scanning for handlers. */
     @Deprecated public static final String PACKAGE_FILTERS = 
"DelegatingExceptionHandler.PackageFilters";
 
+    /**
+     * Configuration key used to lookup the list of packages to scan for auto 
handlers.
+     * @since Stripes 1.5
+     */
+    public static final String PACKAGES = 
"DelegatingExceptionHandler.Packages";
+
     private Configuration configuration;
 
     /** Provides subclasses with access to the configuration object. */
@@ -237,13 +247,40 @@
             log.error("The configuration properties '", URL_FILTERS, "' and 
'", PACKAGE_FILTERS,
                       "' are deprecated, and NO LONGER SUPPORTED. Please read 
the upgrade ",
                       "documentation for Stripes 1.5 for how to resolve this 
situation. In short ",
-                      "you should specify neither ", URL_FILTERS, " or ", 
PACKAGE_FILTERS,
+                      "you should specify neither ", URL_FILTERS, " nor ", 
PACKAGE_FILTERS,
                       ". Instead you should specify a comma separated list of 
package roots ",
                       "(e.g. com.myco.web) that should be scanned for 
implementations of ",
-                      "AutoExceptionHandler, using the configuration parameter 
'",
-                      BootstrapPropertyResolver.EXTENSION_LIST,  "'.");
+                      "AutoExceptionHandler, using the configuration parameter 
'", PACKAGES,
+                      "', or include the packages along with other extension 
packages using the ",
+                      "configuration parameter '", 
BootstrapPropertyResolver.PACKAGES, "'.");
         }
-        return new HashSet<Class<? extends AutoExceptionHandler>>(
-                bootstrap.getClassPropertyList(AutoExceptionHandler.class));
+
+        // Try the config param that is specific to this class
+        String[] packages = 
StringUtil.standardSplit(bootstrap.getProperty(PACKAGES));
+        if (packages == null || packages.length == 0) {
+            // Config param not found so try autodiscovery
+            log.info("No config parameter '", PACKAGES, "' found. Trying 
autodiscovery instead.");
+            List<Class<? extends AutoExceptionHandler>> classes = bootstrap
+                    .getClassPropertyList(AutoExceptionHandler.class);
+            if (!classes.isEmpty()) {
+                return new HashSet<Class<? extends 
AutoExceptionHandler>>(classes);
+            }
+            else {
+                // Autodiscovery found nothing so resort to looking at the 
ActionBean packages
+                log.info("Autodiscovery found no implementations of 
AutoExceptionHandler. Using ",
+                        "the value of '", 
AnnotatedClassActionResolver.PACKAGES, "' instead.");
+                packages = StringUtil.standardSplit(bootstrap
+                        .getProperty(AnnotatedClassActionResolver.PACKAGES));
+            }
+        }
+
+        if (packages != null && packages.length > 0) {
+            ResolverUtil<AutoExceptionHandler> resolver = new 
ResolverUtil<AutoExceptionHandler>();
+            resolver.findImplementations(AutoExceptionHandler.class, packages);
+            return resolver.getClasses();
+        }
+        else {
+            return Collections.emptySet();
+        }
     }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to