BeanSelectionProviderpublic class BeanSelectionProvider extends Object implements com.opensymphony.xwork2.config.ConfigurationProviderSelects the implementations of key framework extension points, using the loaded
property constants. The implementations are selected from the container builder
using the name defined in its associated property. The default implementation name will
always be "struts".
The following is a list of the allowed extension points:
Type |
Property |
Scope |
Description |
com.opensymphony.xwork2.ObjectFactory |
struts.objectFactory |
singleton |
Creates actions, results, and interceptors |
com.opensymphony.xwork2.ActionProxyFactory |
struts.actionProxyFactory |
singleton |
Creates the ActionProxy |
com.opensymphony.xwork2.util.ObjectTypeDeterminer |
struts.objectTypeDeterminer |
singleton |
Determines what the key and and element class of a Map or Collection should be |
org.apache.struts2.dispatcher.mapper.ActionMapper |
struts.mapper.class |
singleton |
Determines the ActionMapping from a request and a URI from an ActionMapping |
org.apache.struts2.dispatcher.multipart.MultiPartRequest |
struts.multipart.parser |
per request |
Parses a multipart request (file upload) |
org.apache.struts2.views.freemarker.FreemarkerManager |
struts.freemarker.manager.classname |
singleton |
Loads and processes Freemarker templates |
org.apache.struts2.views.velocity.VelocityManager |
struts.velocity.manager.classname |
singleton |
Loads and processes Velocity templates |
Implementations are selected using the value of its associated property. That property is
used to determine the implementation by:
- Trying to find an existing bean by that name in the container
- Trying to find a class by that name, then creating a new bean factory for it
- Creating a new delegation bean factory that delegates to the configured ObjectFactory at runtime
Finally, this class overrides certain properties if dev mode is enabled:
struts.i18n.reload = true
struts.configuration.xml.reload = true
|
Fields Summary |
---|
public static final String | DEFAULT_BEAN_NAME | private static final Log | LOG |
Methods Summary |
---|
void | alias(java.lang.Class type, java.lang.String key, com.opensymphony.xwork2.inject.ContainerBuilder builder, java.util.Properties props)
alias(type, key, builder, props, Scope.SINGLETON);
| void | alias(java.lang.Class type, java.lang.String key, com.opensymphony.xwork2.inject.ContainerBuilder builder, java.util.Properties props, com.opensymphony.xwork2.inject.Scope scope)
if (!builder.contains(type)) {
String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
if (builder.contains(type, foundName)) {
if (LOG.isDebugEnabled()) {
LOG.info("Choosing bean ("+foundName+") for "+type);
}
builder.alias(type, foundName, Container.DEFAULT_NAME);
} else {
try {
Class cls = ClassLoaderUtil.loadClass(foundName, this.getClass());
if (LOG.isDebugEnabled()) {
LOG.debug("Choosing bean ("+cls+") for "+type);
}
builder.factory(type, cls, scope);
} catch (ClassNotFoundException ex) {
// Perhaps a spring bean id, so we'll delegate to the object factory at runtime
if (LOG.isDebugEnabled()) {
LOG.debug("Choosing bean ("+foundName+") for "+type+" to be loaded from the ObjectFactory");
}
if (DEFAULT_BEAN_NAME.equals(foundName)) {
// Probably an optional bean, will ignore
} else {
if (ObjectFactory.class != type) {
builder.factory(type, new ObjectFactoryDelegateFactory(foundName, type), scope);
} else {
throw new ConfigurationException("Cannot locate the chosen ObjectFactory implementation: "+foundName);
}
}
}
}
} else {
LOG.warn("Unable to alias bean type "+type+", default mapping already assigned.");
}
| public void | destroy()
// NO-OP
| public void | init(com.opensymphony.xwork2.config.Configuration configuration)
// NO-OP
| public void | loadPackages()
// NO-OP
| public boolean | needsReload()
return false;
| public void | register(com.opensymphony.xwork2.inject.ContainerBuilder builder, com.opensymphony.xwork2.util.location.LocatableProperties props)
alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props);
alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, builder, props);
alias(TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER, builder, props);
alias(ActionProxyFactory.class, StrutsConstants.STRUTS_ACTIONPROXYFACTORY, builder, props);
alias(ObjectTypeDeterminer.class, StrutsConstants.STRUTS_OBJECTTYPEDETERMINER, builder, props);
alias(ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS, builder, props);
alias(MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER, builder, props, Scope.DEFAULT);
alias(FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, builder, props);
alias(VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props);
if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) {
props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true");
props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true");
// Convert struts properties into ones that xwork expects
props.setProperty("devMode", "true");
} else {
props.setProperty("devMode", "false");
}
// TODO: This should be moved to XWork after 2.0.4
// struts.custom.i18n.resources
LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
String bundles = props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES);
if (bundles != null && bundles.length() > 0) {
StringTokenizer customBundles = new StringTokenizer(props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES), ", ");
while (customBundles.hasMoreTokens()) {
String name = customBundles.nextToken();
try {
LOG.info("Loading global messages from " + name);
LocalizedTextUtil.addDefaultResourceBundle(name);
} catch (Exception e) {
LOG.error("Could not find messages file " + name + ".properties. Skipping");
}
}
}
|
|