org.apache.struts2.convention
Class PackageBasedActionConfigBuilder

java.lang.Object
  extended by org.apache.struts2.convention.PackageBasedActionConfigBuilder
All Implemented Interfaces:
ActionConfigBuilder

public class PackageBasedActionConfigBuilder
extends java.lang.Object
implements ActionConfigBuilder

This class implements the ActionConfigBuilder interface.


Constructor Summary
PackageBasedActionConfigBuilder(Configuration configuration, Container container, ObjectFactory objectFactory, java.lang.String redirectToSlash, java.lang.String defaultParentPackage)
          Constructs actions based on a list of packages.
 
Method Summary
 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  void buildConfiguration(java.util.Set<java.lang.Class> classes)
           
protected  java.util.List<ExceptionMappingConfig> buildExceptionMappings(ExceptionMapping[] exceptions, java.lang.String actionName)
           
protected  void buildIndexActions(java.util.Map<java.lang.String,PackageConfig.Builder> packageConfigs)
          Determine all the index handling actions and results based on this logic: 1.
protected  boolean cannotInstantiate(java.lang.Class<?> actionClass)
          Interfaces, enums, annotations, and abstract classes cannot be instantiated.
protected  java.util.List<Action> checkActionsAnnotation(Actions actionsAnnotation)
          Builds a list of actions from an @Actions annotation, and check that they are not all empty
protected  void createActionConfig(PackageConfig.Builder pkgCfg, java.lang.Class<?> actionClass, java.lang.String actionName, java.lang.String actionMethod, Action annotation)
          Creates a single ActionConfig object.
 void destroy()
           
protected  java.lang.String determineActionName(java.lang.Class<?> actionClass)
          Converts the class name into an action name using the ActionNameBuilder.
protected  java.util.List<java.lang.String> determineActionNamespace(java.lang.Class<?> actionClass)
          Determines the namespace(s) for the action based on the action class.
protected  java.util.Set<java.lang.Class> findActions()
           
protected  java.util.Map<java.lang.String,java.util.List<Action>> getActionAnnotations(java.lang.Class<?> actionClass)
          Locates all of the Actions and Action annotations on methods within the Action class and its parent classes.
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  java.lang.ClassLoader getClassLoader()
           
protected  ClassLoaderInterface getClassLoaderInterface()
           
protected  Test<java.lang.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(java.util.Map<java.lang.String,PackageConfig.Builder> packageConfigs, java.lang.String actionNamespace, java.lang.String actionPackage, java.lang.Class<?> actionClass, Action action)
           
protected  boolean includeClassNameInActionScan(java.lang.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(java.lang.String actionPackages)
           
 void setActionSuffix(java.lang.String actionSuffix)
           
 void setAlwaysMapExecute(java.lang.String 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 class
 void setCheckImplementsAction(java.lang.String checkImplementsAction)
           
 void setDevMode(java.lang.String mode)
           
 void setDisableActionScanning(java.lang.String disableActionScanning)
           
 void setDisablePackageLocatorsScanning(java.lang.String disablePackageLocatorsScanning)
           
 void setEagerLoading(java.lang.String eagerLoading)
           
 void setExcludePackages(java.lang.String excludePackages)
           
 void setExcludeParentClassLoader(java.lang.String exclude)
          Exclude URLs found by the parent class loader.
 void setFileProtocols(java.lang.String fileProtocols)
          File URLs whose protocol are in these list will be processed as jars containing classes
 void setIncludeJars(java.lang.String includeJars)
           
 void setMapAllMatches(java.lang.String mapAllMatches)
           
 void setPackageLocators(java.lang.String packageLocators)
           
 void setPackageLocatorsBase(java.lang.String packageLocatorsBasePackage)
           
 void setReload(java.lang.String reload)
          Reload configuration when classes change.
 void setSlashesInActionNames(java.lang.String slashesInActionNames)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageBasedActionConfigBuilder

public PackageBasedActionConfigBuilder(Configuration configuration,
                                       Container container,
                                       ObjectFactory objectFactory,
                                       java.lang.String redirectToSlash,
                                       java.lang.String defaultParentPackage)
Constructs actions based on a list of packages.

Parameters:
configuration - The XWork configuration that the new package configs and action configs are added to.
container - Xwork Container
objectFactory - 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 "").
defaultParentPackage - The default parent package for all the configuration.
Method Detail

setDevMode

public void setDevMode(java.lang.String mode)

setReload

public void setReload(java.lang.String reload)
Reload configuration when classes change. Defaults to "false" and should not be used in production.


setSlashesInActionNames

public void setSlashesInActionNames(java.lang.String slashesInActionNames)

setExcludeParentClassLoader

public void setExcludeParentClassLoader(java.lang.String exclude)
Exclude URLs found by the parent class loader. Defaults to "true", set to true for JBoss


setAlwaysMapExecute

public void setAlwaysMapExecute(java.lang.String 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 class


setFileProtocols

public void setFileProtocols(java.lang.String fileProtocols)
File URLs whose protocol are in these list will be processed as jars containing classes

Parameters:
fileProtocols - Comma separated list of file protocols that will be considered as jar files and scanned

setDisableActionScanning

public void setDisableActionScanning(java.lang.String disableActionScanning)
Parameters:
disableActionScanning - Disable scanning for actions

setIncludeJars

public void setIncludeJars(java.lang.String includeJars)
Parameters:
includeJars - Comma separated list of regular expressions of jars to be included.

setDisablePackageLocatorsScanning

public void setDisablePackageLocatorsScanning(java.lang.String disablePackageLocatorsScanning)
Parameters:
disablePackageLocatorsScanning - If set to true, only the named packages will be scanned

setActionPackages

public void setActionPackages(java.lang.String actionPackages)
Parameters:
actionPackages - (Optional) An optional list of action packages that this should create configuration for.

setCheckImplementsAction

public void setCheckImplementsAction(java.lang.String checkImplementsAction)
Parameters:
checkImplementsAction - (Optional) Map classes that implement com.opensymphony.xwork2.Action as actions

setActionSuffix

public void setActionSuffix(java.lang.String actionSuffix)
Parameters:
actionSuffix - (Optional) Classes that end with these value will be mapped as actions (defaults to "Action")

setExcludePackages

public void setExcludePackages(java.lang.String excludePackages)
Parameters:
excludePackages - (Optional) A list of packages that should be skipped when building configuration.

setPackageLocators

public void setPackageLocators(java.lang.String packageLocators)
Parameters:
packageLocators - (Optional) A list of names used to find action packages.

setPackageLocatorsBase

public void setPackageLocatorsBase(java.lang.String packageLocatorsBasePackage)
Parameters:
packageLocatorsBasePackage - (Optional) If set, only packages that start with this name will be scanned for actions.

setMapAllMatches

public void setMapAllMatches(java.lang.String mapAllMatches)
Parameters:
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.

setEagerLoading

public void setEagerLoading(java.lang.String eagerLoading)
Parameters:
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 beans

initReloadClassLoader

protected void initReloadClassLoader()

getClassLoader

protected java.lang.ClassLoader getClassLoader()

buildActionConfigs

public 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. Next, if this class is in a Java package that hasn't been inspected a new PackageConfig (XWork) is created for that Java package using the Java package name. This will contain all the ActionConfigs for all the Action classes that are discovered within that Java package. Next, each class is inspected for the 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.

Specified by:
buildActionConfigs in interface ActionConfigBuilder

getClassLoaderInterface

protected ClassLoaderInterface getClassLoaderInterface()

isReloadEnabled

protected boolean isReloadEnabled()

findActions

protected java.util.Set<java.lang.Class> findActions()

includeClassNameInActionScan

protected boolean includeClassNameInActionScan(java.lang.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. 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.

Parameters:
className - the name of the class to test
Returns:
true if the specified class should be included in the package-based action scan

getClassPackageTest

protected Test<java.lang.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. 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).

Returns:
a Test object that returns true if the specified class name should be included in the package scan

getActionClassTest

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. 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.

Returns:
a Test object that returns true if the specified class should be included in the package scan

buildConfiguration

protected void buildConfiguration(java.util.Set<java.lang.Class> classes)

cannotInstantiate

protected boolean cannotInstantiate(java.lang.Class<?> actionClass)
Interfaces, enums, annotations, and abstract classes cannot be instantiated.

Parameters:
actionClass - class to check
Returns:
returns true if the class cannot be instantiated or should be ignored

determineActionNamespace

protected java.util.List<java.lang.String> determineActionNamespace(java.lang.Class<?> actionClass)
Determines the namespace(s) for the action based on the action class. If there is a 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.

Parameters:
actionClass - The action class.
Returns:
The namespace or an empty string.

determineActionName

protected java.lang.String determineActionName(java.lang.Class<?> actionClass)
Converts the class name into an action name using the ActionNameBuilder.

Parameters:
actionClass - The action class.
Returns:
The action name.

getActionAnnotations

protected java.util.Map<java.lang.String,java.util.List<Action>> getActionAnnotations(java.lang.Class<?> actionClass)
Locates all of the Actions and Action annotations on methods within the Action class and its parent classes.

Parameters:
actionClass - The action class.
Returns:
The list of annotations or an empty list if there are none.

checkActionsAnnotation

protected java.util.List<Action> checkActionsAnnotation(Actions actionsAnnotation)
Builds a list of actions from an @Actions annotation, and check that they are not all empty

Parameters:
actionsAnnotation - Actions annotation
Returns:
a list of Actions

createActionConfig

protected void createActionConfig(PackageConfig.Builder pkgCfg,
                                  java.lang.Class<?> actionClass,
                                  java.lang.String actionName,
                                  java.lang.String actionMethod,
                                  Action annotation)
Creates a single ActionConfig object.

Parameters:
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 possibly

buildExceptionMappings

protected java.util.List<ExceptionMappingConfig> buildExceptionMappings(ExceptionMapping[] exceptions,
                                                                        java.lang.String actionName)

getPackageConfig

protected PackageConfig.Builder getPackageConfig(java.util.Map<java.lang.String,PackageConfig.Builder> packageConfigs,
                                                 java.lang.String actionNamespace,
                                                 java.lang.String actionPackage,
                                                 java.lang.Class<?> actionClass,
                                                 Action action)

buildIndexActions

protected void buildIndexActions(java.util.Map<java.lang.String,PackageConfig.Builder> packageConfigs)
Determine all the index handling actions and results based on this logic: 1. Loop over all the namespaces such as /foo and see if it has an action named index 2. If an action doesn't exists in the parent namespace of the same name, create an action in the parent namespace of the same name as the namespace that points to the index action in the namespace. e.g. /foo -> /foo/index 3. Create the action in the namespace for empty string if it doesn't exist. e.g. /foo/ the action is "" and the namespace is /foo

Parameters:
packageConfigs - Used to store the actions.

destroy

public void destroy()
Specified by:
destroy in interface ActionConfigBuilder

needsReload

public boolean needsReload()
Specified by:
needsReload in interface ActionConfigBuilder


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.