mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
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:
+20
-12
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user