Skip to content

Commit

Permalink
Puts back the default bean name to allow alias beans
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Mar 9, 2017
1 parent 1ab616b commit 6c19875
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 109 deletions.
79 changes: 0 additions & 79 deletions core/src/main/java/com/opensymphony/xwork2/XWork.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public class ConfigurationManager {
private boolean providersChanged = false;
private boolean reloadConfigs = true; // for the first time

public ConfigurationManager() {
this("xwork");
}

public ConfigurationManager(String name) {
this.defaultFrameworkBeanName = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@
*/
public class DefaultConfiguration implements Configuration {

public static final String DEFAULT_BEAN_NAME = "struts";

protected static final Logger LOG = LogManager.getLogger(DefaultConfiguration.class);


// Programmatic Action Configurations
protected Map<String, PackageConfig> packageContexts = new LinkedHashMap<>();
protected RuntimeConfiguration runtimeConfiguration;
Expand All @@ -68,7 +65,7 @@ public class DefaultConfiguration implements Configuration {
ObjectFactory objectFactory;

public DefaultConfiguration() {
this(DEFAULT_BEAN_NAME);
this(Container.DEFAULT_NAME);
}

public DefaultConfiguration(String defaultBeanName) {
Expand Down Expand Up @@ -266,6 +263,8 @@ protected Container createBootstrapContainer(List<ContainerProvider> providers)

builder.factory(TextParser.class, OgnlTextParser.class, Scope.SINGLETON);
builder.factory(TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON);
builder.factory(TextProvider.class, TextProviderSupport.class, Scope.SINGLETON);
builder.factory(LocaleProvider.class, DefaultLocaleProvider.class, Scope.SINGLETON);

builder.factory(ObjectTypeDeterminer.class, DefaultObjectTypeDeterminer.class, Scope.SINGLETON);
builder.factory(PropertyAccessor.class, CompoundRoot.class.getName(), CompoundRootAccessor.class, Scope.SINGLETON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class XWorkTestCaseHelper {

public static ConfigurationManager setUp() throws Exception {
ConfigurationManager configurationManager = new ConfigurationManager();
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.addContainerProvider(new XWorkConfigurationProvider());
Configuration config = configurationManager.getConfiguration();
Container container = config.getContainer();
Expand All @@ -54,7 +54,7 @@ public static ConfigurationManager loadConfigurationProviders(ConfigurationManag
} catch (Exception e) {
throw new RuntimeException("Cannot clean old configuration", e);
}
configurationManager = new ConfigurationManager();
configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.addContainerProvider(new ContainerProvider() {
public void destroy() {}
public void init(Configuration configuration) throws ConfigurationException {}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/struts2/StrutsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,6 @@ public final class StrutsConstants {
public static final String STRUTS_CONTENT_TYPE_MATCHER = "struts.contentTypeMatcher";

public static final String STRUTS_SMI_METHOD_REGEX = "struts.strictMethodInvocation.methodRegex";

public static final String STRUTS_LOCALIZED_TEXT_PROVIDER = "struts.localizedTextProvider";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.opensymphony.xwork2.config.BeanSelectionProvider;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.*;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.location.LocatableProperties;
Expand All @@ -20,6 +19,8 @@ public abstract class AbstractBeanSelectionProvider implements BeanSelectionProv

private static final Logger LOG = LogManager.getLogger(AbstractBeanSelectionProvider.class);

public static final String DEFAULT_BEAN_NAME = "struts";

public void destroy() {
// NO-OP
}
Expand All @@ -41,8 +42,8 @@ protected void alias(Class type, String key, ContainerBuilder builder, Propertie
}

protected void alias(Class type, String key, ContainerBuilder builder, Properties props, Scope scope) {
if (!builder.contains(type)) {
String foundName = props.getProperty(key, DefaultConfiguration.DEFAULT_BEAN_NAME);
if (!builder.contains(type, Container.DEFAULT_NAME)) {
String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
if (builder.contains(type, foundName)) {
LOG.trace("Choosing bean ({}) for ({})", foundName, type.getName());
builder.alias(type, foundName, Container.DEFAULT_NAME);
Expand All @@ -54,7 +55,7 @@ protected void alias(Class type, String key, ContainerBuilder builder, Propertie
} catch (ClassNotFoundException ex) {
// Perhaps a spring bean id, so we'll delegate to the object factory at runtime
LOG.trace("Choosing bean ({}) for ({}) to be loaded from the ObjectFactory", foundName, type.getName());
if (DefaultConfiguration.DEFAULT_BEAN_NAME.equals(foundName)) {
if (DEFAULT_BEAN_NAME.equals(foundName)) {
// Probably an optional bean, will ignore
} else {
if (ObjectFactory.class != type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ public void register(ContainerBuilder builder, LocatableProperties props) {
alias(TypeConverterHolder.class, StrutsConstants.STRUTS_CONVERTER_HOLDER, builder, props);

alias(TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER, builder, props, Scope.PROTOTYPE);

alias(LocaleProvider.class, StrutsConstants.STRUTS_LOCALE_PROVIDER, builder, props);
alias(LocalizedTextUtil.class, StrutsConstants.STRUTS_LOCALIZED_TEXT_PROVIDER, 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ private void init_CheckWebLogicWorkaround(Container container) {
public void init() {

if (configurationManager == null) {
configurationManager = createConfigurationManager(DefaultConfiguration.DEFAULT_BEAN_NAME);
configurationManager = createConfigurationManager(Container.DEFAULT_NAME);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.XWorkTestCase;
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.util.location.LocatableProperties;

Expand Down Expand Up @@ -73,7 +74,7 @@ class State {
}

final State state = new State();
ConfigurationManager configurationManager = new ConfigurationManager();
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.addContainerProvider(new ConfigurationProvider() {
public void destroy() {
throw new RuntimeException("testing testing 123");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.opensymphony.xwork2.config.ConfigurationProvider;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Container;

/**
* <code>XmlConfigurationProviderGlobalResultInheritenceTest</code>
Expand All @@ -19,7 +20,7 @@ public class XmlConfigurationProviderGlobalResultInheritenceTest extends Configu
public void testGlobalResultInheritenceTest() throws Exception {
ConfigurationProvider provider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-global-result-inheritence.xml");

ConfigurationManager configurationManager = new ConfigurationManager();
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.addContainerProvider(new XWorkConfigurationProvider());
configurationManager.addContainerProvider(provider);
Configuration configuration = configurationManager.getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void dispatcherInitialized(Dispatcher du) {

public void testConfigurationManager() {
Dispatcher du;
final InternalConfigurationManager configurationManager = new InternalConfigurationManager();
final InternalConfigurationManager configurationManager = new InternalConfigurationManager(Container.DEFAULT_NAME);
try {
du = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), configurationManager);
du.init();
Expand All @@ -196,7 +196,7 @@ public void testConfigurationManager() {
public void testObjectFactoryDestroy() throws Exception {

final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
ConfigurationManager cm = new ConfigurationManager();
ConfigurationManager cm = new ConfigurationManager(Container.DEFAULT_NAME);
Dispatcher du = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), cm);
Mock mockConfiguration = new Mock(Configuration.class);
cm.setConfiguration((Configuration)mockConfiguration.proxy());
Expand Down Expand Up @@ -245,7 +245,7 @@ public void testInterceptorDestroy() throws Exception {
mockConfiguration.matchAndReturn("getContainer", mockContainer.proxy());
mockConfiguration.expect("destroy");

ConfigurationManager configurationManager = new ConfigurationManager();
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.setConfiguration((Configuration) mockConfiguration.proxy());

Dispatcher dispatcher = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), configurationManager);
Expand All @@ -259,8 +259,12 @@ public void testInterceptorDestroy() throws Exception {

class InternalConfigurationManager extends ConfigurationManager {
public boolean destroyConfiguration = false;

@Override

public InternalConfigurationManager(String name) {
super(name);
}

@Override
public synchronized void destroyConfiguration() {
super.destroyConfiguration();
destroyConfiguration = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testGetActionMappingAndUri1() throws Exception {
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper3")), mapper2);
CompositeActionMapper compositeActionMapper = new CompositeActionMapper((Container) mockContainer.proxy(), "mapper1,mapper2,mapper3");

ActionMapping actionMapping = compositeActionMapper.getMapping(new MockHttpServletRequest(), new ConfigurationManager());
ActionMapping actionMapping = compositeActionMapper.getMapping(new MockHttpServletRequest(), new ConfigurationManager(Container.DEFAULT_NAME));
String uri = compositeActionMapper.getUriFromActionMapping(new ActionMapping());
mockContainer.verify();

Expand All @@ -69,7 +69,7 @@ public void testGetActionMappingAndUri2() throws Exception {
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper2")), mapper2);
CompositeActionMapper compositeActionMapper = new CompositeActionMapper((Container) mockContainer.proxy(), "mapper1,mapper2");

ActionMapping actionMapping = compositeActionMapper.getMapping(new MockHttpServletRequest(), new ConfigurationManager());
ActionMapping actionMapping = compositeActionMapper.getMapping(new MockHttpServletRequest(), new ConfigurationManager(Container.DEFAULT_NAME));
String uri = compositeActionMapper.getUriFromActionMapping(new ActionMapping());
mockContainer.verify();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.Container;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsException;
import org.apache.struts2.StrutsInternalTestCase;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected void setUp() throws Exception {
PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
configManager = new ConfigurationManager() {
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
Expand Down Expand Up @@ -139,7 +140,7 @@ public void testGetMappingWithSlashedNameAtRoot() throws Exception {
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
config.addPackageConfig("root", pkg3);
configManager = new ConfigurationManager() {
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.apache.struts2.dispatcher.mapper;

import com.opensymphony.xwork2.inject.Container;
import org.apache.struts2.StrutsInternalTestCase;
import com.mockobjects.servlet.MockHttpServletRequest;
import com.opensymphony.xwork2.config.ConfigurationManager;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected void setUp() throws Exception {
.namespace("/my").build();
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
configManager = new ConfigurationManager() {
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.Container;
import junit.framework.TestCase;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.springframework.mock.web.MockHttpServletRequest;
Expand All @@ -50,7 +51,7 @@ protected void setUp() throws Exception {
PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
configManager = new ConfigurationManager() {
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.opensymphony.xwork2.config.ConfigurationProvider;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Container;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.struts2.config.DefaultBeanSelectionProvider;
Expand Down Expand Up @@ -71,7 +72,7 @@ private static void initXWork() {
File configFile = new File(configFilePath);
try {
ConfigurationProvider configProvider = new StrutsXmlConfigurationProvider(configFile.getCanonicalPath(), true, null);
cm = new ConfigurationManager();
cm = new ConfigurationManager(Container.DEFAULT_NAME);
cm.addContainerProvider(new DefaultPropertiesProvider());
cm.addContainerProvider(new StrutsXmlConfigurationProvider("struts-default.xml", false, null));
cm.addContainerProvider(configProvider);
Expand Down

0 comments on commit 6c19875

Please sign in to comment.