Making it easier to extend the classpath package provider

WW-1715


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@586740 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2007-10-20 15:08:15 +00:00
parent 2ba492bceb
commit 6a5c4c2c53
@@ -241,16 +241,7 @@ public class ClasspathPackageProvider implements PackageProvider {
protected void loadPackages(String[] pkgs) {
ResolverUtil<Class> resolver = new ResolverUtil<Class>();
resolver.find(new ClassTest() {
// Match Action implementations and classes ending with "Action"
public boolean matches(Class type) {
// TODO: should also find annotated classes
return (Action.class.isAssignableFrom(type) ||
type.getSimpleName().endsWith("Action") ||
type.getAnnotation(org.apache.struts2.config.Action.class) != null);
}
}, pkgs);
resolver.find(createActionClassTest(), pkgs);
Set<? extends Class<? extends Class>> actionClasses = resolver.getClasses();
for (Object obj : actionClasses) {
@@ -265,6 +256,23 @@ public class ClasspathPackageProvider implements PackageProvider {
}
}
protected ClassTest createActionClassTest() {
return new ClassTest() {
// Match Action implementations and classes ending with "Action"
public boolean matches(Class type) {
// TODO: should also find annotated classes
return (Action.class.isAssignableFrom(type) ||
type.getSimpleName().endsWith(getClassSuffix()) ||
type.getAnnotation(org.apache.struts2.config.Action.class) != null);
}
};
}
protected String getClassSuffix() {
return ACTION;
}
/**
* Create a default action mapping for a class instance.
*
@@ -310,8 +318,8 @@ public class ClasspathPackageProvider implements PackageProvider {
}
}
// Truncate Action suffix if found
if (actionName.endsWith(ACTION)) {
actionName = actionName.substring(0, actionName.length() - ACTION.length());
if (actionName.endsWith(getClassSuffix())) {
actionName = actionName.substring(0, actionName.length() - getClassSuffix().length());
}
// Force initial letter of action to lowercase, if desired