mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
Reverts changes introduced with WW-4827 and adds default constructors
This commit is contained in:
@@ -49,8 +49,8 @@ public class ObjectFactory implements Serializable {
|
||||
private static final Logger LOG = LogManager.getLogger(ObjectFactory.class);
|
||||
|
||||
private transient ClassLoader ccl;
|
||||
private final Container container;
|
||||
|
||||
private Container container;
|
||||
private ActionFactory actionFactory;
|
||||
private ResultFactory resultFactory;
|
||||
private InterceptorFactory interceptorFactory;
|
||||
@@ -58,8 +58,11 @@ public class ObjectFactory implements Serializable {
|
||||
private ConverterFactory converterFactory;
|
||||
private UnknownHandlerFactory unknownHandlerFactory;
|
||||
|
||||
public ObjectFactory() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ObjectFactory(Container container) {
|
||||
public void setContainer(Container container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
|
||||
@Deprecated
|
||||
private boolean enableAopSupport = false;
|
||||
|
||||
public SpringObjectFactory() {
|
||||
}
|
||||
|
||||
@Inject(value="applicationContextPath",required=false)
|
||||
public void setApplicationContextPath(String ctx) {
|
||||
if (ctx != null) {
|
||||
@@ -73,11 +76,6 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
|
||||
this.enableAopSupport = BooleanUtils.toBoolean(enableAopSupport);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public SpringObjectFactory(Container container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Spring ApplicationContext that should be used to look beans up with.
|
||||
*
|
||||
|
||||
@@ -23,9 +23,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -41,9 +38,7 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory {
|
||||
|
||||
private List<String> skipBeanNames = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
public SpringProxyableObjectFactory(Container container) {
|
||||
super(container);
|
||||
public SpringProxyableObjectFactory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -106,7 +106,8 @@ public class ActionAutowiringInterceptor extends AbstractInterceptor implements
|
||||
LOG.warn("ApplicationContext could not be found. Action classes will not be autowired.");
|
||||
} else {
|
||||
setApplicationContext(applicationContext);
|
||||
factory = new SpringObjectFactory(ActionContext.getContext().getContainer());
|
||||
factory = new SpringObjectFactory();
|
||||
factory.setContainer(ActionContext.getContext().getContainer());
|
||||
factory.setApplicationContext(getApplicationContext());
|
||||
if (autowireStrategy != null) {
|
||||
factory.setAutowireStrategy(autowireStrategy);
|
||||
|
||||
@@ -5,17 +5,12 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
|
||||
/**
|
||||
* ObjectFactory that returns a FooProxy in the buildBean if the clazz is FooAction
|
||||
*/
|
||||
public class ProxyObjectFactory extends ObjectFactory {
|
||||
|
||||
@Inject
|
||||
public ProxyObjectFactory(Container container) {
|
||||
super(container);
|
||||
public ProxyObjectFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-1
@@ -36,7 +36,9 @@ public class ScopedModelDrivenInterceptorTest extends XWorkTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
inter = new ScopedModelDrivenInterceptor();
|
||||
inter.setObjectFactory(new ProxyObjectFactory(container));
|
||||
ProxyObjectFactory factory = new ProxyObjectFactory();
|
||||
factory.setContainer(container);
|
||||
inter.setObjectFactory(factory);
|
||||
}
|
||||
|
||||
public void testResolveModel() throws Exception {
|
||||
|
||||
@@ -230,7 +230,8 @@ public class DispatcherTest extends StrutsInternalTestCase {
|
||||
String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
|
||||
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
|
||||
reloadConfigs);
|
||||
final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory((Container) mockContainer.proxy());
|
||||
final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
|
||||
destroyedObjectFactory.setContainer((Container) mockContainer.proxy());
|
||||
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
|
||||
|
||||
mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
|
||||
@@ -261,7 +262,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
|
||||
packageConfigs.put("test", packageConfig);
|
||||
|
||||
Mock mockContainer = new Mock(Container.class);
|
||||
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory((Container) mockContainer.proxy()));
|
||||
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
|
||||
String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
|
||||
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
|
||||
reloadConfigs);
|
||||
@@ -316,8 +317,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
|
||||
public static class InnerDestroyableObjectFactory extends ObjectFactory implements ObjectFactoryDestroyable {
|
||||
public boolean destroyed = false;
|
||||
|
||||
public InnerDestroyableObjectFactory(Container container) {
|
||||
super(container);
|
||||
public InnerDestroyableObjectFactory() {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package org.apache.struts2.cdi;
|
||||
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -74,9 +73,7 @@ public class CdiObjectFactory extends ObjectFactory {
|
||||
|
||||
Map<Class<?>, InjectionTarget<?>> injectionTargetCache = new ConcurrentHashMap<Class<?>, InjectionTarget<?>>();
|
||||
|
||||
@Inject
|
||||
public CdiObjectFactory(Container container) {
|
||||
super(container);
|
||||
public CdiObjectFactory() {
|
||||
LOG.info("Initializing Struts2 CDI integration...");
|
||||
this.beanManager = findBeanManager();
|
||||
if (beanManager != null) {
|
||||
|
||||
@@ -27,19 +27,19 @@ public class CdiObjectFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testFindBeanManager() throws Exception {
|
||||
assertNotNull(new CdiObjectFactory(null).findBeanManager());
|
||||
assertNotNull(new CdiObjectFactory().findBeanManager());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBean() throws Exception {
|
||||
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory(null);
|
||||
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory();
|
||||
FooConsumer fooConsumer = (FooConsumer) cdiObjectFactory.buildBean(FooConsumer.class.getCanonicalName(), null, false);
|
||||
assertNotNull(fooConsumer);
|
||||
assertNotNull(fooConsumer.fooService);
|
||||
}
|
||||
|
||||
@Test public void testGetInjectionTarget() throws Exception {
|
||||
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory(null);
|
||||
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory();
|
||||
final InjectionTarget<?> injectionTarget = cdiObjectFactory.getInjectionTarget(FooConsumer.class);
|
||||
assertNotNull(injectionTarget);
|
||||
assertTrue(cdiObjectFactory.injectionTargetCache.containsKey(FooConsumer.class));
|
||||
|
||||
+5
-2
@@ -338,7 +338,8 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
configuration.addPackageConfig("class-level", classLevelParentPkg);
|
||||
|
||||
ActionNameBuilder actionNameBuilder = new SEOActionNameBuilder("true", "-");
|
||||
ObjectFactory of = new ObjectFactory(mockContainer);
|
||||
ObjectFactory of = new ObjectFactory();
|
||||
of.setContainer(mockContainer);
|
||||
DefaultInterceptorMapBuilder interceptorBuilder = new DefaultInterceptorMapBuilder();
|
||||
interceptorBuilder.setConfiguration(configuration);
|
||||
|
||||
@@ -780,7 +781,9 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
}
|
||||
T obj;
|
||||
if (type == ObjectFactory.class) {
|
||||
obj = type.getConstructor(Container.class).newInstance(this);
|
||||
obj = type.getConstructor().newInstance();
|
||||
((ObjectFactory)obj).setContainer(this);
|
||||
|
||||
OgnlReflectionProvider rp = new OgnlReflectionProvider() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,9 +35,7 @@ public class DelegatingObjectFactory extends ObjectFactory implements ObjectFact
|
||||
private BundleAccessor bundleResourceLoader;
|
||||
private OsgiConfigurationProvider osgiConfigurationProvider;
|
||||
|
||||
@Inject
|
||||
public DelegatingObjectFactory(Container container) {
|
||||
super(container);
|
||||
public DelegatingObjectFactory() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -23,7 +23,6 @@ package org.apache.struts2.osgi;
|
||||
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
@@ -39,9 +38,7 @@ public class SpringOsgiObjectFactory extends ObjectFactory {
|
||||
|
||||
private BundleAccessor bundleAccessor;
|
||||
|
||||
@Inject
|
||||
public SpringOsgiObjectFactory(Container container) {
|
||||
super(container);
|
||||
public SpringOsgiObjectFactory() {
|
||||
}
|
||||
|
||||
public Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception {
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -81,9 +80,7 @@ public class PlexusObjectFactory extends ObjectFactory {
|
||||
private PlexusContainer base;
|
||||
private ReflectionProvider reflectionProvider;
|
||||
|
||||
@Inject
|
||||
public PlexusObjectFactory(Container container) {
|
||||
super(container);
|
||||
public PlexusObjectFactory() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
||||
+4
-2
@@ -48,8 +48,12 @@ import javax.servlet.ServletContext;
|
||||
* </p>
|
||||
*/
|
||||
public class StrutsSpringObjectFactory extends SpringObjectFactory {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(StrutsSpringObjectFactory.class);
|
||||
|
||||
public StrutsSpringObjectFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the spring object factory
|
||||
* @param autoWire The type of autowiring to use
|
||||
@@ -58,7 +62,6 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
|
||||
* @param enableAopSupport enable AOP support
|
||||
* @param servletContext The servlet context
|
||||
* @param devMode development mode
|
||||
* @param container container
|
||||
* @since 2.1.3
|
||||
*/
|
||||
@Inject
|
||||
@@ -71,7 +74,6 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
|
||||
@Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
|
||||
@Inject Container container) {
|
||||
|
||||
super(container);
|
||||
boolean useClassCache = BooleanUtils.toBoolean(useClassCacheStr);
|
||||
LOG.info("Initializing Struts-Spring integration...");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user