public class PackageBasedActionConfigBuilder extends Object implements ActionConfigBuilder
This class implements the ActionConfigBuilder interface.
Constructor and Description |
---|
PackageBasedActionConfigBuilder(Configuration configuration,
Container container,
ObjectFactory objectFactory,
String redirectToSlash,
String defaultParentPackage,
String enableSmiInheritance)
Constructs actions based on a list of packages.
|
Modifier and Type | Method and Description |
---|---|
void |
buildActionConfigs()
Builds the action configurations by loading all classes in the packages specified by the
property struts.convention.action.packages and then figuring out which classes implement Action
or have Action in their name.
|
protected ClassFinder |
buildClassFinder(Test<String> classPackageTest,
List<URL> urls) |
protected void |
buildConfiguration(Set<Class> classes) |
protected List<ExceptionMappingConfig> |
buildExceptionMappings(ExceptionMapping[] exceptions,
String actionName) |
protected void |
buildIndexActions(Map<String,PackageConfig.Builder> packageConfigs)
Determine all the index handling actions and results based on this logic:
1.
|
protected boolean |
cannotInstantiate(Class<?> actionClass)
Interfaces, enums, annotations, and abstract classes cannot be instantiated.
|
protected boolean |
checkActionPackages(String classPackageName)
Checks if class package match provided list of action packages
|
protected List<Action> |
checkActionsAnnotation(Actions actionsAnnotation)
Builds a list of actions from an @Actions annotation, and check that they are not all empty
|
protected boolean |
checkExcludePackages(String classPackageName)
Checks if provided class package is on the exclude list
|
protected boolean |
checkPackageLocators(String classPackageName)
Checks if class package match provided list of package locators
|
protected void |
createActionConfig(PackageConfig.Builder pkgCfg,
Class<?> actionClass,
String actionName,
String actionMethod,
Action annotation,
Set<String> allowedMethods)
Creates a single ActionConfig object.
|
void |
destroy() |
protected String |
determineActionName(Class<?> actionClass)
Converts the class name into an action name using the ActionNameBuilder.
|
protected List<String> |
determineActionNamespace(Class<?> actionClass)
Determines the namespace(s) for the action based on the action class.
|
protected Set<Class> |
findActions() |
protected Map<String,List<Action>> |
getActionAnnotations(Class<?> actionClass)
|
protected Test<ClassFinder.ClassInfo> |
getActionClassTest()
Construct a
Test Object that determines if a specified class
should be included in the package scan based on the full ClassFinder.ClassInfo
of the class. |
protected ClassLoader |
getClassLoader() |
protected ClassLoaderInterface |
getClassLoaderInterface() |
protected Test<String> |
getClassPackageTest()
Construct a
Test object that determines if a specified class name
should be included in the package scan based on the clazz's package name. |
protected PackageConfig.Builder |
getPackageConfig(Map<String,PackageConfig.Builder> packageConfigs,
String actionNamespace,
String actionPackage,
Class<?> actionClass,
Action action) |
protected boolean |
includeClassNameInActionScan(String className)
Note that we can't include the test for
actionSuffix here
because a class is included if its name ends in actionSuffix OR
it implements Action . |
protected void |
initReloadClassLoader() |
protected boolean |
isReloadEnabled() |
boolean |
needsReload() |
void |
setActionPackages(String actionPackages) |
void |
setActionSuffix(String actionSuffix) |
void |
setAlwaysMapExecute(String alwaysMapExecute) |
void |
setCheckImplementsAction(String checkImplementsAction) |
void |
setClassFinderFactory(ClassFinderFactory classFinderFactory) |
void |
setDevMode(String mode) |
void |
setDisableActionScanning(String disableActionScanning) |
void |
setDisablePackageLocatorsScanning(String disablePackageLocatorsScanning) |
void |
setEagerLoading(String eagerLoading) |
void |
setExcludePackages(String excludePackages) |
void |
setExcludeParentClassLoader(String exclude) |
void |
setFileManagerFactory(FileManagerFactory fileManagerFactory) |
void |
setFileProtocols(String fileProtocols)
File URLs whose protocol are in these list will be processed as jars containing classes
|
void |
setIncludeJars(String includeJars) |
void |
setMapAllMatches(String mapAllMatches) |
void |
setPackageLocators(String packageLocators) |
void |
setPackageLocatorsBase(String packageLocatorsBasePackage) |
void |
setReload(String reload) |
void |
setSlashesInActionNames(String slashesInActionNames) |
public PackageBasedActionConfigBuilder(Configuration configuration, Container container, ObjectFactory objectFactory, String redirectToSlash, String defaultParentPackage, String enableSmiInheritance)
configuration
- The XWork configuration that the new package configs and action configs
are added to.container
- Xwork ContainerobjectFactory
- The ObjectFactory used to create the actions and such.redirectToSlash
- A boolean parameter that controls whether or not this will create an
action for indexes. If this is set to true, index actions are not created because
the unknown handler will redirect from /foo to /foo/. The only action that is created
is to the empty action in the namespace (e.g. the namespace /foo and the action "").enableSmiInheritance
- A boolean parameter which determines if a newly created package config inherits the SMI value of its parent package configdefaultParentPackage
- The default parent package for all the configuration.public void setDevMode(String mode)
public void setReload(String reload)
reload
- Reload configuration when classes change. Defaults to "false" and should not be used
in production.public void setSlashesInActionNames(String slashesInActionNames)
public void setExcludeParentClassLoader(String exclude)
exclude
- Exclude URLs found by the parent class loader. Defaults to "true", set to true for JBosspublic void setAlwaysMapExecute(String alwaysMapExecute)
alwaysMapExecute
- If this constant is true, and there is an "execute" method(not annotated), a mapping will be added
pointing to it, even if there are other mapping in the classpublic void setFileProtocols(String fileProtocols)
fileProtocols
- Comma separated list of file protocols that will be considered as jar files and scannedpublic void setDisableActionScanning(String disableActionScanning)
disableActionScanning
- Disable scanning for actionspublic void setIncludeJars(String includeJars)
includeJars
- Comma separated list of regular expressions of jars to be included.public void setDisablePackageLocatorsScanning(String disablePackageLocatorsScanning)
disablePackageLocatorsScanning
- If set to true, only the named packages will be scannedpublic void setActionPackages(String actionPackages)
actionPackages
- (Optional) An optional list of action packages that this should create
configuration for.public void setCheckImplementsAction(String checkImplementsAction)
checkImplementsAction
- (Optional) Map classes that implement com.opensymphony.xwork2.Action
as actionspublic void setActionSuffix(String actionSuffix)
actionSuffix
- (Optional) Classes that end with these value will be mapped as actions
(defaults to "Action")public void setExcludePackages(String excludePackages)
excludePackages
- (Optional) A list of packages that should be skipped when building
configuration.public void setPackageLocators(String packageLocators)
packageLocators
- (Optional) A list of names used to find action packages.public void setPackageLocatorsBase(String packageLocatorsBasePackage)
packageLocatorsBasePackage
- (Optional) If set, only packages that start with this
name will be scanned for actions.public void setMapAllMatches(String mapAllMatches)
mapAllMatches
- (Optional) Map actions that match the "*${Suffix}" pattern
even if they don't have a default method. The mapping from
the url to the action will be delegated the action mapper.public void setEagerLoading(String eagerLoading)
eagerLoading
- (Optional) If set, found action classes will be instantiated by the ObjectFactory to accelerate future use
setting it up can clash with Spring managed beanspublic void setFileManagerFactory(FileManagerFactory fileManagerFactory)
public void setClassFinderFactory(ClassFinderFactory classFinderFactory)
protected void initReloadClassLoader()
protected ClassLoader getClassLoader()
public void buildActionConfigs()
ParentPackage
annotation which is used to control the parent package for a specific action. Lastly, the
ResultMapBuilder
is used to create ResultConfig instances of the action.buildActionConfigs
in interface ActionConfigBuilder
protected ClassLoaderInterface getClassLoaderInterface()
protected boolean isReloadEnabled()
protected ClassFinder buildClassFinder(Test<String> classPackageTest, List<URL> urls)
protected boolean includeClassNameInActionScan(String className)
actionSuffix
here
because a class is included if its name ends in actionSuffix
OR
it implements Action
. Since the whole
goal is to avoid loading the class if we don't have to, the (actionSuffix
|| implements Action) test will have to remain until later. See
getActionClassTest()
for the test performed on the loaded
ClassFinder.ClassInfo
structure.className
- the name of the class to testprotected boolean checkExcludePackages(String classPackageName)
classPackageName
- name of class packageexcludePackages
listprotected boolean checkActionPackages(String classPackageName)
classPackageName
- name of class packageactionPackages
listprotected boolean checkPackageLocators(String classPackageName)
classPackageName
- name of class packagepackageLocators
listprotected Test<String> getClassPackageTest()
Test
object that determines if a specified class name
should be included in the package scan based on the clazz's package name.
Note that the goal is to avoid loading the class, so the test should only
rely on information in the class name itself. The default implementation
is to return the result of includeClassNameInActionScan(String)
.Test
object that returns true if the specified class
name should be included in the package scanprotected Test<ClassFinder.ClassInfo> getActionClassTest()
Test
Object that determines if a specified class
should be included in the package scan based on the full ClassFinder.ClassInfo
of the class. At this point, the class has been loaded, so it's ok to
perform tests such as checking annotations or looking at interfaces or
super-classes of the specified class.Test
object that returns true if the specified class
should be included in the package scanprotected boolean cannotInstantiate(Class<?> actionClass)
actionClass
- class to checkprotected List<String> determineActionNamespace(Class<?> actionClass)
Namespace
annotation on the class (including parent classes) or on the package that the class is in, than
it is used. Otherwise, the Java package name that the class is in is used in conjunction with
either the struts.convention.action.packages or struts.convention.package.locators
configuration values. These are used to determine which part of the Java package name should
be converted into the namespace for the XWork PackageConfig.actionClass
- The action class.protected String determineActionName(Class<?> actionClass)
actionClass
- The action class.protected Map<String,List<Action>> getActionAnnotations(Class<?> actionClass)
Actions
and Action
annotations on methods within the Action
class and its parent classes.actionClass
- The action class.protected List<Action> checkActionsAnnotation(Actions actionsAnnotation)
actionsAnnotation
- Actions annotationprotected void createActionConfig(PackageConfig.Builder pkgCfg, Class<?> actionClass, String actionName, String actionMethod, Action annotation, Set<String> allowedMethods)
pkgCfg
- The package the action configuration instance will belong to.actionClass
- The action class.actionName
- The name of the action.actionMethod
- The method that the annotation was on (if the annotation is not null) or
the default method (execute).annotation
- The ActionName annotation that might override the action name and possiblyprotected List<ExceptionMappingConfig> buildExceptionMappings(ExceptionMapping[] exceptions, String actionName)
protected PackageConfig.Builder getPackageConfig(Map<String,PackageConfig.Builder> packageConfigs, String actionNamespace, String actionPackage, Class<?> actionClass, Action action)
protected void buildIndexActions(Map<String,PackageConfig.Builder> packageConfigs)
packageConfigs
- Used to store the actions.public void destroy()
destroy
in interface ActionConfigBuilder
public boolean needsReload()
needsReload
in interface ActionConfigBuilder
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.