org.apache.struts2.config
Class MethodConfigurationProvider

java.lang.Object
  extended by org.apache.struts2.config.MethodConfigurationProvider
All Implemented Interfaces:
ConfigurationProvider

public class MethodConfigurationProvider
extends Object
implements ConfigurationProvider

MethodConfigurationProvider creates ActionConfigs for potential action methods that lack a corresponding action mapping, so that these methods can be invoked without extra or redundant configuration.

As a dynamic method, the behavior of this class could be represented as:

int bang = name.indexOf('!'); if (bang != -1) { String method = name.substring(bang + 1); mapping.setMethod(method); name = name.substring(0, bang); }

If the action URL is "foo!bar", the the "foo" action is invoked, calling "bar" instead of "execute".

Instead of scanning each request at runtime, the provider creates action mappings for each method that could be matched using a dynamic approach. Advantages over a dynamic approach are that:


Field Summary
private  Configuration configuration
          Stores configuration property.
(package private)  ObjectFactory factory
          Stores ObjectFactory property.
(package private)  boolean reload
          Store needsReload property.
 
Constructor Summary
MethodConfigurationProvider()
           
 
Method Summary
protected  boolean addDynamicMethods(Map actions, String actionName, ActionConfig actionConfig)
          Scans class for potential Action mehods, automatically generating and registering ActionConfigs as needed.
 void destroy()
           
private  ObjectFactory getObjectFactory()
          Provides ObjectFactory property.
 void init(Configuration configuration)
           
 void loadPackages()
           
 boolean needsReload()
          Tells whether the ConfigurationProvider should reload its configuration
 void register(ContainerBuilder containerBuilder, LocatableProperties locatableProperties)
           
 void setConfiguration(Configuration configuration)
          Updates configuration property.
 void setObjectFactory(ObjectFactory factory)
          Updates ObjectFactory property.
private  boolean upperAt(int pos, String string)
          Verifies that character at a String position is upper case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

private Configuration configuration
Stores configuration property.


reload

boolean reload
Store needsReload property.


factory

ObjectFactory factory
Stores ObjectFactory property.

Constructor Detail

MethodConfigurationProvider

public MethodConfigurationProvider()
Method Detail

setConfiguration

public void setConfiguration(Configuration configuration)
Updates configuration property.

Parameters:
configuration - New configuration

destroy

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

init

public void init(Configuration configuration)
          throws ConfigurationException
Specified by:
init in interface ConfigurationProvider
Throws:
ConfigurationException

register

public void register(ContainerBuilder containerBuilder,
                     LocatableProperties locatableProperties)
              throws ConfigurationException
Specified by:
register in interface ConfigurationProvider
Throws:
ConfigurationException

loadPackages

public void loadPackages()
                  throws ConfigurationException
Specified by:
loadPackages in interface ConfigurationProvider
Throws:
ConfigurationException

needsReload

public boolean needsReload()
Description copied from interface: ConfigurationProvider
Tells whether the ConfigurationProvider should reload its configuration

Specified by:
needsReload in interface ConfigurationProvider
Returns:
true, whether the ConfigurationProvider should reload its configuration, falseotherwise.

setObjectFactory

public void setObjectFactory(ObjectFactory factory)
Updates ObjectFactory property.

Parameters:
factory -

getObjectFactory

private ObjectFactory getObjectFactory()
                                throws ConfigurationException
Provides ObjectFactory property.

Returns:
Throws:
ConfigurationException - if ObjectFactory has not been set.

upperAt

private boolean upperAt(int pos,
                        String string)
Verifies that character at a String position is upper case.

Parameters:
pos - Position to test
string - Text containing position
Returns:
True if character at a String position is upper case

addDynamicMethods

protected boolean addDynamicMethods(Map actions,
                                    String actionName,
                                    ActionConfig actionConfig)
                             throws ConfigurationException
Scans class for potential Action mehods, automatically generating and registering ActionConfigs as needed.

The system iterates over the set of namespaces and the set of actionNames in a Configuration and retrieves each ActionConfig. For each ActionConfig that invokes the default "execute" method, the provider inspects the className class for other non-void, no-argument methods that do not begin with "getX" or "isX". For each qualifying method, the provider looks for another actionName in the same namespace that equals action.name + "!" + method.name. If that actionName is not found, System copies the ActionConfig, changes the method property, and adds it to the package configuration under the new actionName (action!method).

The system ignores ActionConfigs with a method property set so as to avoid creating alias methods for alias methods. The system ignores "getX" and "isX" methods since these would appear to be JavaBeans property and would not be intended as action methods. (The X represents any upper character or non-letter.)

Parameters:
actions - All ActionConfigs in namespace
actionName - Name of ActionConfig to analyze
actionConfig - ActionConfig corresponding to actionName
Throws:
ConfigurationException


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